You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/05/13 07:43:01 UTC

[camel-quarkus] 16/26: fix atlasmap integration tests error

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 138d852e672c592344f005b1de70fb7d99bc00e7
Author: Zineb Bendhiba <be...@gmail.com>
AuthorDate: Mon May 3 17:49:52 2021 +0200

    fix atlasmap integration tests error
---
 .../atlasmap/deployment/AtlasmapProcessor.java     | 21 -----
 extensions/atlasmap/runtime/pom.xml                |  6 ++
 .../component/atlasmap/AtlasmapRecorder.java       | 90 ----------------------
 .../component/atlasmap/graalvm/Substitutions.java  | 21 +++++
 4 files changed, 27 insertions(+), 111 deletions(-)

diff --git a/extensions/atlasmap/deployment/src/main/java/org/apache/camel/quarkus/component/atlasmap/deployment/AtlasmapProcessor.java b/extensions/atlasmap/deployment/src/main/java/org/apache/camel/quarkus/component/atlasmap/deployment/AtlasmapProcessor.java
index 8c74b06..60b2963 100644
--- a/extensions/atlasmap/deployment/src/main/java/org/apache/camel/quarkus/component/atlasmap/deployment/AtlasmapProcessor.java
+++ b/extensions/atlasmap/deployment/src/main/java/org/apache/camel/quarkus/component/atlasmap/deployment/AtlasmapProcessor.java
@@ -37,22 +37,13 @@ import io.atlasmap.v2.DataSourceMetadata;
 import io.atlasmap.xml.module.XmlModule;
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
 import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
-import io.quarkus.deployment.recording.RecorderContext;
 import io.quarkus.deployment.util.ServiceUtil;
-import io.quarkus.runtime.RuntimeValue;
-import org.apache.camel.component.atlasmap.AtlasMapComponent;
-import org.apache.camel.quarkus.component.atlasmap.AtlasmapRecorder;
-import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem;
-import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
-import org.apache.camel.quarkus.core.deployment.spi.CompiledCSimpleExpressionBuildItem;
 import org.jboss.jandex.IndexView;
 
 class AtlasmapProcessor {
@@ -138,16 +129,4 @@ class AtlasmapProcessor {
                     }
                 });
     }
-
-    @Record(ExecutionTime.STATIC_INIT)
-    @BuildStep
-    CamelBeanBuildItem configureComponent(
-            RecorderContext recorderContext,
-            AtlasmapRecorder recorder,
-            CamelContextBuildItem camelContext,
-            List<CompiledCSimpleExpressionBuildItem> compiledCSimpleExpressions) {
-
-        final RuntimeValue<?> atlasmapComponent = recorder.createAtlasmapComponent();
-        return new CamelBeanBuildItem("atlasmap", AtlasMapComponent.class.getName(), atlasmapComponent);
-    }
 }
diff --git a/extensions/atlasmap/runtime/pom.xml b/extensions/atlasmap/runtime/pom.xml
index 2c0fea5..2d80f1a 100644
--- a/extensions/atlasmap/runtime/pom.xml
+++ b/extensions/atlasmap/runtime/pom.xml
@@ -60,8 +60,14 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-jackson</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.graalvm.nativeimage</groupId>
+            <artifactId>svm</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
+
     <build>
         <plugins>
             <plugin>
diff --git a/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/AtlasmapRecorder.java b/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/AtlasmapRecorder.java
deleted file mode 100644
index 146484c..0000000
--- a/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/AtlasmapRecorder.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.apache.camel.quarkus.component.atlasmap;
-
-import java.net.URL;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import io.atlasmap.core.DefaultAtlasContextFactory;
-import io.quarkus.runtime.RuntimeValue;
-import io.quarkus.runtime.annotations.Recorder;
-import org.apache.camel.component.atlasmap.AtlasMapComponent;
-import org.jboss.logging.Logger;
-
-@Recorder
-public class AtlasmapRecorder {
-
-    public RuntimeValue<AtlasMapComponent> createAtlasmapComponent() {
-        /*
-         * TODO simplify once https://github.com/atlasmap/atlasmap/issues/2704 is solved
-         * Currently there is no way to directly create a DefaultAtlasContextFactory with a custom compound class loader
-         */
-        final DefaultAtlasContextFactory cf = DefaultAtlasContextFactory.getInstance();
-        cf.destroy();
-        final CamelQuarkusCompoundClassLoader compoundClassLoader = new CamelQuarkusCompoundClassLoader();
-        final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-        compoundClassLoader.addAlternativeLoader(tccl);
-        cf.init(compoundClassLoader);
-
-        final AtlasMapComponent component = new AtlasMapComponent();
-        component.setAtlasContextFactory(cf);
-        return new RuntimeValue<AtlasMapComponent>(component);
-    }
-
-    /**
-     * TODO: remove once https://github.com/atlasmap/atlasmap/pull/2703 is fixed in an AtlasMap version we use
-     */
-    static class CamelQuarkusCompoundClassLoader extends io.atlasmap.core.CompoundClassLoader {
-        private static final Logger LOG = Logger.getLogger(CamelQuarkusCompoundClassLoader.class);
-
-        private Set<ClassLoader> delegates = new LinkedHashSet<>();
-
-        @Override
-        public Class<?> loadClass(String name) throws ClassNotFoundException {
-            for (ClassLoader cl : delegates) {
-                try {
-                    return cl.loadClass(name);
-                } catch (Throwable t) {
-                    LOG.debugf(t, "Class '%s' was not found with ClassLoader '%s'", name, cl);
-                }
-            }
-            throw new ClassNotFoundException(name);
-        }
-
-        @Override
-        public URL getResource(String name) {
-            for (ClassLoader cl : delegates) {
-                URL url = cl.getResource(name);
-                if (url != null) {
-                    return url;
-                }
-                LOG.debugf("Resource '%s' was not found with ClassLoader '%s'", name, cl);
-            }
-            return null;
-        }
-
-        @Override
-        public Enumeration<URL> getResources(String name) {
-            List<URL> answer = new LinkedList<>();
-            for (ClassLoader cl : delegates) {
-                try {
-                    Enumeration<URL> urls = cl.getResources(name);
-                    while (urls != null && urls.hasMoreElements()) {
-                        answer.add(urls.nextElement());
-                    }
-                } catch (Exception e) {
-                    LOG.debugf(e, "I/O error while looking for a resource '%s' with ClassLoader '%s'", name, cl);
-                }
-            }
-            return Collections.enumeration(answer);
-        }
-
-        @Override
-        public synchronized void addAlternativeLoader(ClassLoader cl) {
-            delegates.add(cl);
-        }
-    }
-}
diff --git a/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/graalvm/Substitutions.java b/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/graalvm/Substitutions.java
new file mode 100644
index 0000000..53779cf
--- /dev/null
+++ b/extensions/atlasmap/runtime/src/main/java/org/apache/camel/quarkus/component/atlasmap/graalvm/Substitutions.java
@@ -0,0 +1,21 @@
+package org.apache.camel.quarkus.component.atlasmap.graalvm;
+
+import java.util.Set;
+
+import com.oracle.svm.core.annotate.Alias;
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+
+public class Substitutions {
+}
+
+@TargetClass(className = "io.atlasmap.core.DefaultAtlasCompoundClassLoader")
+final class DefaultAtlasCompoundClassLoader_Substitute {
+    @Alias
+    private Set<ClassLoader> delegates;
+
+    @Substitute
+    public synchronized void addAlternativeLoader(ClassLoader cl) {
+        delegates.add(Thread.currentThread().getContextClassLoader());
+    }
+}