This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 9b5f04b Configure NativeImageResourceBuildItem for camel route classpath resources 9b5f04b is described below commit 9b5f04be79b348ad3891a5b13768be78781c5b1c Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Wed Sep 23 07:31:57 2020 +0100 Configure NativeImageResourceBuildItem for camel route classpath resources Fixes #1812 --- .../quarkus/core/deployment/util/CamelSupport.java | 7 ++++ .../CamelMainHotDeploymentProcessor.java | 7 ++-- .../deployment/CamelMainNativeImageProcessor.java | 40 ++++++++++++++++++++++ .../src/main/resources/application.properties | 3 -- .../src/main/resources/application.properties | 3 -- .../src/main/resources/application.properties | 3 -- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/util/CamelSupport.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/util/CamelSupport.java index 5c2850c..9ae4a90 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/util/CamelSupport.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/util/CamelSupport.java @@ -34,6 +34,7 @@ import io.quarkus.deployment.ApplicationArchive; import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; import org.apache.camel.impl.engine.AbstractCamelContext; import org.apache.camel.quarkus.core.deployment.spi.CamelServiceBuildItem; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.ClassInfo; public final class CamelSupport { @@ -118,4 +119,10 @@ public final class CamelSupport { return Objects.requireNonNull(version, "Could not determine Camel version"); } + + public static <T> T getOptionalConfigValue(String property, Class<T> type, T defaultValue) { + return ConfigProvider.getConfig() + .getOptionalValue(property, type) + .orElse(defaultValue); + } } diff --git a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainHotDeploymentProcessor.java b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainHotDeploymentProcessor.java index ce8d2a9..d207ea5 100644 --- a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainHotDeploymentProcessor.java +++ b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainHotDeploymentProcessor.java @@ -25,7 +25,7 @@ import java.util.stream.Stream; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; -import org.eclipse.microprofile.config.ConfigProvider; +import org.apache.camel.quarkus.core.deployment.util.CamelSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,10 +53,7 @@ class CamelMainHotDeploymentProcessor { } private static List<HotDeploymentWatchedFileBuildItem> locations(String property) { - String[] locations = ConfigProvider.getConfig() - .getOptionalValue(property, String[].class) - .orElse(EMPTY_STRING_ARRAY); - + String[] locations = CamelSupport.getOptionalConfigValue(property, String[].class, EMPTY_STRING_ARRAY); List<HotDeploymentWatchedFileBuildItem> items = Stream.of(locations) .filter(location -> location.startsWith(FILE_PREFIX)) .map(location -> location.substring(FILE_PREFIX.length())) diff --git a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainNativeImageProcessor.java b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainNativeImageProcessor.java index 2ea03b5..453f473 100644 --- a/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainNativeImageProcessor.java +++ b/extensions-core/main/deployment/src/main/java/org/apache/camel/quarkus/main/deployment/CamelMainNativeImageProcessor.java @@ -16,10 +16,21 @@ */ package org.apache.camel.quarkus.main.deployment; +import io.quarkus.deployment.Capabilities; +import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import org.apache.camel.quarkus.core.deployment.util.CamelSupport; +import org.apache.camel.quarkus.support.common.CamelCapabilities; +import org.apache.camel.support.ResourceHelper; +import org.apache.camel.util.AntPathMatcher; +import org.jboss.logging.Logger; public class CamelMainNativeImageProcessor { + + private static final Logger LOG = Logger.getLogger(CamelMainNativeImageProcessor.class); + @BuildStep ReflectiveClassBuildItem reflectiveCLasses() { // TODO: The classes below are needed to fix https://github.com/apache/camel-quarkus/issues/1005 @@ -33,4 +44,33 @@ public class CamelMainNativeImageProcessor { org.apache.camel.spi.RestConfiguration.class, org.apache.camel.quarkus.main.CamelMainApplication.class); } + + @BuildStep + void camelNativeImageResources(Capabilities capabilities, BuildProducer<NativeImageResourceBuildItem> nativeResource) { + if (capabilities.isCapabilityPresent(CamelCapabilities.XML)) { + String prefix = "camel.main."; + String[] properties = new String[] { "xml-rests", "xml-routes", "xml-route-templates" }; + for (String property : properties) { + embedCamelResource(prefix + property, nativeResource); + } + } + } + + private void embedCamelResource(String propertyName, BuildProducer<NativeImageResourceBuildItem> nativeResource) { + for (String path : CamelSupport.getOptionalConfigValue(propertyName, String[].class, new String[0])) { + String scheme = ResourceHelper.getScheme(path); + + // Null scheme is equivalent to classpath scheme + if (scheme == null || scheme.equals("classpath:")) { + if (AntPathMatcher.INSTANCE.isPattern(path)) { + // Classpath directory traversal via wildcard paths does not work on GraalVM. The exact path to the resource has to be looked up + // https://github.com/oracle/graal/issues/1108 + LOG.warnf("%s classpath wildcards does not work in native mode. Resources matching %s will not be loaded.", + propertyName, path); + } else { + nativeResource.produce(new NativeImageResourceBuildItem(path.replace("classpath:", ""))); + } + } + } + } } diff --git a/integration-tests/dataformats-json/src/main/resources/application.properties b/integration-tests/dataformats-json/src/main/resources/application.properties index 2adf8b8..70600cc 100644 --- a/integration-tests/dataformats-json/src/main/resources/application.properties +++ b/integration-tests/dataformats-json/src/main/resources/application.properties @@ -19,9 +19,6 @@ # quarkus.ssl.native=true -# include xml routes in native image -quarkus.native.additional-build-args = -H:IncludeResources=routes/.*-routes.xml - # # Camel # diff --git a/integration-tests/main-xml-io/src/main/resources/application.properties b/integration-tests/main-xml-io/src/main/resources/application.properties index b2816e3..3f0170a 100644 --- a/integration-tests/main-xml-io/src/main/resources/application.properties +++ b/integration-tests/main-xml-io/src/main/resources/application.properties @@ -19,9 +19,6 @@ # Quarkus # -# include xml routes in native image -quarkus.native.additional-build-args = -H:IncludeResources=routes/my-routes.xml - # # Camel # diff --git a/integration-tests/main-xml-jaxb/src/main/resources/application.properties b/integration-tests/main-xml-jaxb/src/main/resources/application.properties index b2816e3..3f0170a 100644 --- a/integration-tests/main-xml-jaxb/src/main/resources/application.properties +++ b/integration-tests/main-xml-jaxb/src/main/resources/application.properties @@ -19,9 +19,6 @@ # Quarkus # -# include xml routes in native image -quarkus.native.additional-build-args = -H:IncludeResources=routes/my-routes.xml - # # Camel #