You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/09/16 17:13:45 UTC
[camel-k-runtime] 01/02: Generate Configurer to bind properties
SourceLoader.Interceptor without the need for reflection
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit f0bc0ef13c0cdccfabfbc20526d9d93f6965ec03
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Wed Sep 16 18:15:25 2020 +0200
Generate Configurer to bind properties SourceLoader.Interceptor without the need for reflection
---
.../quarkus/deployment/DeploymentProcessor.java | 14 ++----
.../core/quarkus/deployment/DeploymentSupport.java | 52 ++++++++++++++++++++
.../main/java/org/apache/camel/k/Constants.java | 2 +
.../org/apache/camel/k/support/RuntimeSupport.java | 3 +-
camel-k-runtime-cron/pom.xml | 38 +++++++++++++++
.../CronSourceLoaderInterceptorConfigurer.java | 55 ++++++++++++++++++++++
...apache.camel.k.cron.CronSourceLoaderInterceptor | 2 +
.../camel/k/cron/CronSourceLoaderInterceptor.java | 2 +
...k.loader.knative.KnativeSourceLoaderInterceptor | 2 +
9 files changed, 159 insertions(+), 11 deletions(-)
diff --git a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java
index 8091756..d34c875 100644
--- a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java
+++ b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java
@@ -29,6 +29,7 @@ import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import org.apache.camel.k.Constants;
import org.apache.camel.k.ContextCustomizer;
import org.apache.camel.k.SourceDefinition;
+import org.apache.camel.k.SourceLoader;
import org.apache.camel.k.core.quarkus.RuntimeRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination;
@@ -54,21 +55,14 @@ public class DeploymentProcessor {
true,
Constants.SOURCE_LOADER_INTERCEPTOR_RESOURCE_PATH + "/*")
);
-
}
@BuildStep
List<ReflectiveClassBuildItem> registerClasses(CombinedIndexBuildItem index) {
return List.of(
- new ReflectiveClassBuildItem(
- true,
- false,
- SourceDefinition.class),
- new ReflectiveClassBuildItem(
- true,
- false,
- getAllKnownImplementors(index.getIndex(), ContextCustomizer.class, ci -> ci.name().toString())
- .toArray(String[]::new))
+ reflectiveClassBuildItem(SourceDefinition.class),
+ reflectiveClassBuildItem(getAllKnownImplementors(index.getIndex(), ContextCustomizer.class)),
+ reflectiveClassBuildItem(getAllKnownImplementors(index.getIndex(), SourceLoader.Interceptor.class))
);
}
diff --git a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentSupport.java b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentSupport.java
index 768fd26..a3170e9 100644
--- a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentSupport.java
+++ b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentSupport.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.k.core.quarkus.deployment;
+import java.util.Collection;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -104,6 +105,13 @@ public final class DeploymentSupport {
return stream(getAnnotated(view, type)).map(mapper).collect(Collectors.toList());
}
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(Class<?>... classes) {
+ return new ReflectiveClassBuildItem(true, false, classes);
+ }
+
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(boolean methods, boolean fields, Class<?>... classes) {
+ return new ReflectiveClassBuildItem(methods, fields, classes);
+ }
public static ReflectiveClassBuildItem reflectiveClassBuildItem(ClassInfo... classInfos) {
return classInfos.length == 1
@@ -121,6 +129,28 @@ public final class DeploymentSupport {
);
}
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(Collection<ClassInfo> classInfos) {
+ return new ReflectiveClassBuildItem(
+ true,
+ false,
+ classInfos.stream()
+ .map(ClassInfo::name)
+ .map(DotName::toString)
+ .toArray(String[]::new)
+ );
+ }
+
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(Iterable<ClassInfo> classInfos) {
+ return new ReflectiveClassBuildItem(
+ true,
+ false,
+ stream(classInfos)
+ .map(ClassInfo::name)
+ .map(DotName::toString)
+ .toArray(String[]::new)
+ );
+ }
+
public static ReflectiveClassBuildItem reflectiveClassBuildItem(boolean methods, boolean fields, ClassInfo... classInfos) {
return new ReflectiveClassBuildItem(
methods,
@@ -132,6 +162,28 @@ public final class DeploymentSupport {
);
}
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(boolean methods, boolean fields, Collection<ClassInfo> classInfos) {
+ return new ReflectiveClassBuildItem(
+ methods,
+ fields,
+ classInfos.stream()
+ .map(ClassInfo::name)
+ .map(DotName::toString)
+ .toArray(String[]::new)
+ );
+ }
+
+ public static ReflectiveClassBuildItem reflectiveClassBuildItem(boolean methods, boolean fields, Iterable<ClassInfo> classInfos) {
+ return new ReflectiveClassBuildItem(
+ methods,
+ fields,
+ stream(classInfos)
+ .map(ClassInfo::name)
+ .map(DotName::toString)
+ .toArray(String[]::new)
+ );
+ }
+
public static <T> Stream<T> stream(Iterable<T> iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
}
diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Constants.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Constants.java
index ed848fd..83df4f7 100644
--- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Constants.java
+++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Constants.java
@@ -56,6 +56,8 @@ public final class Constants {
public static final String CUSTOMIZER_PREFIX = "camel.k.customizer.";
public static final String CUSTOMIZER_PREFIX_FALLBACK = "customizer.";
+ public static final String LOADER_INTERCEPTOR_PREFIX = "camel.k.loader.interceptor.";
+ public static final String LOADER_INTERCEPTOR_PREFIX_FALLBACK = "loader.interceptor.";
private Constants() {
diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java
index 411a32e..4c9da08 100644
--- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java
+++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java
@@ -240,7 +240,8 @@ public final class RuntimeSupport {
LOGGER.debug("Found source loader interceptor {} from registry", id);
}
- PropertiesSupport.bindProperties(context, interceptor, "loader.interceptor." + id + ".");
+ PropertiesSupport.bindProperties(context, interceptor, Constants.LOADER_INTERCEPTOR_PREFIX + id + ".");
+ PropertiesSupport.bindProperties(context, interceptor, Constants.LOADER_INTERCEPTOR_PREFIX_FALLBACK + id + ".");
answer.add(interceptor);
} catch (Exception e) {
diff --git a/camel-k-runtime-cron/pom.xml b/camel-k-runtime-cron/pom.xml
index f005895..743e269 100644
--- a/camel-k-runtime-cron/pom.xml
+++ b/camel-k-runtime-cron/pom.xml
@@ -108,6 +108,44 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-package-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <executions>
+ <execution>
+ <id>generate-configurer</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>generate-configurer</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>${build-helper-maven-plugin-version}</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ <goal>add-resource</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/generated/java</source>
+ </sources>
+ <resources>
+ <resource>
+ <directory>src/generated/resources</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/camel-k-runtime-cron/src/generated/java/org/apache/camel/k/cron/CronSourceLoaderInterceptorConfigurer.java b/camel-k-runtime-cron/src/generated/java/org/apache/camel/k/cron/CronSourceLoaderInterceptorConfigurer.java
new file mode 100644
index 0000000..bbb5edb
--- /dev/null
+++ b/camel-k-runtime-cron/src/generated/java/org/apache/camel/k/cron/CronSourceLoaderInterceptorConfigurer.java
@@ -0,0 +1,55 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.k.cron;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.k.cron.CronSourceLoaderInterceptor;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class CronSourceLoaderInterceptorConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+ @Override
+ public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+ org.apache.camel.k.cron.CronSourceLoaderInterceptor target = (org.apache.camel.k.cron.CronSourceLoaderInterceptor) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "overridablecomponents":
+ case "OverridableComponents": target.setOverridableComponents(property(camelContext, java.lang.String.class, value)); return true;
+ case "runtime":
+ case "Runtime": target.setRuntime(property(camelContext, org.apache.camel.k.Runtime.class, value)); return true;
+ case "timeruri":
+ case "TimerUri": target.setTimerUri(property(camelContext, java.lang.String.class, value)); return true;
+ default: return false;
+ }
+ }
+
+ @Override
+ public Map<String, Object> getAllOptions(Object target) {
+ Map<String, Object> answer = new CaseInsensitiveMap();
+ answer.put("OverridableComponents", java.lang.String.class);
+ answer.put("Runtime", org.apache.camel.k.Runtime.class);
+ answer.put("TimerUri", java.lang.String.class);
+ return answer;
+ }
+
+ @Override
+ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+ org.apache.camel.k.cron.CronSourceLoaderInterceptor target = (org.apache.camel.k.cron.CronSourceLoaderInterceptor) obj;
+ switch (ignoreCase ? name.toLowerCase() : name) {
+ case "overridablecomponents":
+ case "OverridableComponents": return target.getOverridableComponents();
+ case "runtime":
+ case "Runtime": return target.getRuntime();
+ case "timeruri":
+ case "TimerUri": return target.getTimerUri();
+ default: return null;
+ }
+ }
+}
+
diff --git a/camel-k-runtime-cron/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.cron.CronSourceLoaderInterceptor b/camel-k-runtime-cron/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.cron.CronSourceLoaderInterceptor
new file mode 100644
index 0000000..5f58309
--- /dev/null
+++ b/camel-k-runtime-cron/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.cron.CronSourceLoaderInterceptor
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.k.cron.CronSourceLoaderInterceptorConfigurer
diff --git a/camel-k-runtime-cron/src/main/java/org/apache/camel/k/cron/CronSourceLoaderInterceptor.java b/camel-k-runtime-cron/src/main/java/org/apache/camel/k/cron/CronSourceLoaderInterceptor.java
index 2eb29d4..d3026d1 100644
--- a/camel-k-runtime-cron/src/main/java/org/apache/camel/k/cron/CronSourceLoaderInterceptor.java
+++ b/camel-k-runtime-cron/src/main/java/org/apache/camel/k/cron/CronSourceLoaderInterceptor.java
@@ -28,11 +28,13 @@ import org.apache.camel.k.annotation.LoaderInterceptor;
import org.apache.camel.k.support.RuntimeSupport;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.spi.Configurer;
import org.apache.camel.support.EventNotifierSupport;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Configurer
@LoaderInterceptor("cron")
public class CronSourceLoaderInterceptor implements SourceLoader.Interceptor, RuntimeAware {
diff --git a/camel-k-runtime-knative/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.loader.knative.KnativeSourceLoaderInterceptor b/camel-k-runtime-knative/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.loader.knative.KnativeSourceLoaderInterceptor
new file mode 100644
index 0000000..50833dc
--- /dev/null
+++ b/camel-k-runtime-knative/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.k.loader.knative.KnativeSourceLoaderInterceptor
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.k.loader.knative.KnativeSourceLoaderInterceptorConfigurer