You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/06/18 10:07:40 UTC

[camel] 02/02: CAMEL-13647: Allow to do autowrire by classpath.

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ea4b7334d9adaaf7bb7e9320439f938742502424
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 18 12:07:25 2019 +0200

    CAMEL-13647: Allow to do autowrire by classpath.
---
 .../main/java/org/apache/camel/maven/AutowireMojo.java    | 15 +++++++++------
 examples/camel-example-main-artemis/pom.xml               |  5 +++--
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
index 6950bb6..7b66a5c 100644
--- a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
+++ b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java
@@ -44,7 +44,6 @@ import org.apache.camel.catalog.JSonSchemaHelper;
 import org.apache.camel.catalog.maven.MavenVersionManager;
 import org.apache.camel.support.PatternHelper;
 import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.OrderedProperties;
 import org.apache.camel.util.StringHelper;
 import org.apache.maven.artifact.Artifact;
@@ -290,9 +289,13 @@ public class AutowireMojo extends AbstractExecMojo {
                         Class clazz = classLoader.loadClass(javaType);
                         if (clazz.isInterface() && isComplexUserType(clazz)) {
                             Set<Class<?>> classes = reflections.getSubTypesOf(clazz);
-                            // filter classes (must not be interfaces, must not be abstract, must be top level) and also a valid autowire class
+                            // filter classes (must not be interfaces, must be public, must not be abstract, must be top level) and also a valid autowire class
                             classes = classes.stream().filter(
-                                    c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers()) && c.getEnclosingClass() == null && isValidAutowireClass(c))
+                                    c -> !c.isInterface()
+                                            && Modifier.isPublic(c.getModifiers())
+                                            && !Modifier.isAbstract(c.getModifiers())
+                                            && c.getEnclosingClass() == null
+                                            && isValidAutowireClass(c))
                                     .collect(Collectors.toSet());
                             Class best = chooseBestKnownType(componentName, name, clazz, classes, mappingProperties);
                             if (best != null) {
@@ -336,7 +339,7 @@ public class AutowireMojo extends AbstractExecMojo {
                 getLog().info("Cannot autowire option camel.component." + componentName + "." + optionName
                         + " as the interface: " + type.getName() + " has " + candidates.size() + " implementations in the classpath:");
                 for (Class c : candidates) {
-                    getLog().info("    Class: " + c.getName());
+                    getLog().info("\t\t" + c.getName());
                 }
             }
         }
@@ -348,7 +351,7 @@ public class AutowireMojo extends AbstractExecMojo {
         String prefix = "camel.component." + componentName + ".";
         name = StringHelper.dashToCamelCase(name);
 
-        if (ObjectHelper.isNotEmpty(exclude)) {
+        if (exclude != null && exclude.length > 0) {
             // works on components too
             for (String pattern : exclude) {
                 pattern = pattern.trim();
@@ -362,7 +365,7 @@ public class AutowireMojo extends AbstractExecMojo {
             }
         }
 
-        if (ObjectHelper.isNotEmpty(include)) {
+        if (include != null && include.length > 0) {
             for (String pattern : include) {
                 pattern = pattern.trim();
                 pattern = StringHelper.dashToCamelCase(pattern);
diff --git a/examples/camel-example-main-artemis/pom.xml b/examples/camel-example-main-artemis/pom.xml
index d4bf15e..b0132bb 100644
--- a/examples/camel-example-main-artemis/pom.xml
+++ b/examples/camel-example-main-artemis/pom.xml
@@ -105,9 +105,10 @@
                 <version>${project.version}</version>
                 <configuration>
                     <logClasspath>false</logClasspath>
-                    <logUnmapped>true</logUnmapped>
+                    <!-- lets show which options are unmapped -->
+                    <!-- <logUnmapped>true</logUnmapped> -->
                     <!-- just include only the jms component -->
-                    <include>jms</include>
+                    <!-- <include>jms</include> -->
                 </configuration>
                 <executions>
                     <execution>