Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 88c605bfa -> 1192cbd2d


CAMEL-10082: Fixed inner class name handling in camel-api-component-maven-plugin


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1192cbd2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1192cbd2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1192cbd2

Branch: refs/heads/camel-2.17.x
Commit: 1192cbd2de0a961c2480510db2495571b43295e4
Parents: 88c605b
Author: Dhiraj Bokde <dhira...@yahoo.com>
Authored: Tue Jun 21 15:54:21 2016 -0700
Committer: Dhiraj Bokde <dhira...@yahoo.com>
Committed: Tue Jun 21 15:57:27 2016 -0700

----------------------------------------------------------------------
 .../camel/util/component/ApiMethodParser.java   | 30 +++++++++++++++++---
 .../util/component/ApiMethodHelperTest.java     | 10 +++++--
 .../ArgumentSubstitutionParserTest.java         | 12 +++++---
 .../apache/camel/util/component/TestProxy.java  | 16 +++++++++++
 .../camel-api-component-maven-plugin/pom.xml    |  9 ++----
 .../apache/camel/component/test/TestProxy.java  | 16 +++++++++++
 .../test/resources/test-proxy-signatures.txt    |  1 +
 7 files changed, 77 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java 
b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
index 5040bd0..a7a1a70 100644
--- 
a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
+++ 
b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
@@ -237,7 +237,7 @@ public abstract class ApiMethodParser<T> {
     }
 
     public static Class<?> forName(String className, ClassLoader classLoader) 
throws ClassNotFoundException {
-        Class<?> result;
+        Class<?> result = null;
         try {
             // lookup primitive types first
             result = PRIMITIVE_TYPES.get(className);
@@ -249,10 +249,32 @@ public abstract class ApiMethodParser<T> {
             if (className.endsWith("[]")) {
                 final int firstDim = className.indexOf('[');
                 final int nDimensions = (className.length() - firstDim) / 2;
-                return Array.newInstance(forName(className.substring(0, 
firstDim), classLoader), new int[nDimensions]).getClass();
+                result = Array.newInstance(forName(className.substring(0, 
firstDim), classLoader), new int[nDimensions]).getClass();
+            } else if (className.indexOf('.') != -1) {
+                // try replacing last '.' with $ to look for inner classes
+                String innerClass = className;
+                while (result == null && innerClass.indexOf('.') != -1) {
+                    int endIndex = innerClass.lastIndexOf('.');
+                    innerClass = innerClass.substring(0, endIndex) + "$" + 
innerClass.substring(endIndex + 1);
+                    try {
+                        result = Class.forName(innerClass, true, classLoader);
+                    } catch (ClassNotFoundException ignore) {
+                        // ignore
+                    }
+                }
+            }
+            if (result == null && !className.startsWith(JAVA_LANG)) {
+                // try loading from default Java package java.lang
+                try {
+                    result = forName(JAVA_LANG + className, classLoader);
+                } catch (ClassNotFoundException ignore) {
+                    // ignore
+                }
             }
-            // try loading from default Java package java.lang
-            result = Class.forName(JAVA_LANG + className, true, classLoader);
+        }
+
+        if (result == null) {
+            throw new ClassNotFoundException(className);
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodHelperTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodHelperTest.java
 
b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodHelperTest.java
index 2287993..574c9d4 100644
--- 
a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodHelperTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodHelperTest.java
@@ -60,6 +60,9 @@ public class ApiMethodHelperTest {
 
         methods = apiMethodHelper.getCandidateMethods("greetAll", "nameMap");
         assertEquals("Can't find greetAll(nameMap)", 1, methods.size());
+
+        methods = apiMethodHelper.getCandidateMethods("greetInnerChild", 
"child");
+        assertEquals("Can't find greetInnerChild(child)", 1, methods.size());
     }
 
     @Test
@@ -95,6 +98,7 @@ public class ApiMethodHelperTest {
         assertEquals("GetArguments failed for greetMe", 2, 
apiMethodHelper.getArguments("greetMe").size());
         assertEquals("GetArguments failed for greetUs", 4, 
apiMethodHelper.getArguments("greetUs").size());
         assertEquals("GetArguments failed for greetAll", 6, 
apiMethodHelper.getArguments("greetAll").size());
+        assertEquals("GetArguments failed for greetInnerChild", 2, 
apiMethodHelper.getArguments("greetInnerChild").size());
     }
 
     @Test
@@ -115,7 +119,7 @@ public class ApiMethodHelperTest {
 
     @Test
     public void testAllArguments() throws Exception {
-        assertEquals("Get all arguments", 7, 
apiMethodHelper.allArguments().size());
+        assertEquals("Get all arguments", 8, 
apiMethodHelper.allArguments().size());
     }
 
     @Test
@@ -124,6 +128,7 @@ public class ApiMethodHelperTest {
         assertEquals("Get type name1", String.class, 
apiMethodHelper.getType("name1"));
         assertEquals("Get type name2", String.class, 
apiMethodHelper.getType("name2"));
         assertEquals("Get type nameMap", Map.class, 
apiMethodHelper.getType("nameMap"));
+        assertEquals("Get type child", TestProxy.InnerChild.class, 
apiMethodHelper.getType("child"));
     }
 
     @Test
@@ -184,7 +189,8 @@ public class ApiMethodHelperTest {
         GREETALL(String.class, "greetAll", new String[0].getClass(), "names"),
         GREETALL_1(String.class, "greetAll", List.class, "nameList"),
         GREETALL_2(Map.class, "greetAll", Map.class, "nameMap"),
-        GREETTIMES(new String[0].getClass(), "greetTimes", String.class, 
"name", int.class, "times");
+        GREETTIMES(new String[0].getClass(), "greetTimes", String.class, 
"name", int.class, "times"),
+        GREETINNERCHILD(new String[0].getClass(), "greetInnerChild", 
TestProxy.InnerChild.class, "child");
 
         private final ApiMethod apiMethod;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
 
b/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
index 56f7886..9947283 100644
--- 
a/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/util/component/ArgumentSubstitutionParserTest.java
@@ -48,19 +48,20 @@ public class ArgumentSubstitutionParserTest {
         signatures.add("public final String greetAll(java.util.List<String> 
names);");
         signatures.add("public final java.util.Map<String, String> 
greetAll(java.util.Map<String> nameMap);");
         signatures.add("public final String[] greetTimes(String name, int 
times);");
+        signatures.add("public final String 
greetInnerChild(org.apache.camel.util.component.TestProxy.InnerChild child);");
         parser.setSignatures(signatures);
 
         final List<ApiMethodParser.ApiMethodModel> methodModels = 
parser.parse();
-        assertEquals(8, methodModels.size());
+        assertEquals(9, methodModels.size());
 
-        final ApiMethodParser.ApiMethodModel sayHi1 = methodModels.get(7);
+        final ApiMethodParser.ApiMethodModel sayHi1 = methodModels.get(8);
         assertEquals(PERSON, sayHi1.getArguments().get(0).getName());
         assertEquals("SAYHI_1", sayHi1.getUniqueName());
 
-        final ApiMethodParser.ApiMethodModel greetMe = methodModels.get(3);
+        final ApiMethodParser.ApiMethodModel greetMe = methodModels.get(4);
         assertEquals(PERSON, greetMe.getArguments().get(0).getName());
 
-        final ApiMethodParser.ApiMethodModel greetUs = methodModels.get(5);
+        final ApiMethodParser.ApiMethodModel greetUs = methodModels.get(6);
         assertEquals("astronaut1", greetUs.getArguments().get(0).getName());
         assertEquals("astronaut2", greetUs.getArguments().get(1).getName());
 
@@ -72,6 +73,9 @@ public class ArgumentSubstitutionParserTest {
 
         final ApiMethodParser.ApiMethodModel greetAll2 = methodModels.get(2);
         assertEquals("stringArray", greetAll2.getArguments().get(0).getName());
+
+        final ApiMethodParser.ApiMethodModel greetInnerChild = 
methodModels.get(3);
+        assertEquals("child", greetInnerChild.getArguments().get(0).getName());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java 
b/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
index 2b4a320..1a61ac9 100644
--- a/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
+++ b/camel-core/src/test/java/org/apache/camel/util/component/TestProxy.java
@@ -73,4 +73,20 @@ class TestProxy {
         }
         return result;
     }
+
+    public final String greetInnerChild(InnerChild child) {
+        return sayHi(child.getName());
+    }
+
+    public static class InnerChild {
+        private String name;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/tooling/maven/camel-api-component-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/pom.xml 
b/tooling/maven/camel-api-component-maven-plugin/pom.xml
index 2045593..8abecf4 100644
--- a/tooling/maven/camel-api-component-maven-plugin/pom.xml
+++ b/tooling/maven/camel-api-component-maven-plugin/pom.xml
@@ -122,15 +122,10 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
+    <!-- add maven slf4j simple logger -->
     <dependency>
       <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <scope>test</scope>
+      <artifactId>slf4j-simple</artifactId>
     </dependency>
 
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
 
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
index 48eb11b..e6c4c1c 100644
--- 
a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
+++ 
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
@@ -65,4 +65,20 @@ public class TestProxy {
         }
         return result.toArray(new String[result.size()]);
     }
+
+    public final String greetInnerChild(InnerChild child) {
+        return sayHi(child.getName());
+    }
+
+    public static class InnerChild {
+        private String name;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1192cbd2/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
----------------------------------------------------------------------
diff --git 
a/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
 
b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
index 4c47474..d9214f0 100644
--- 
a/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
+++ 
b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
@@ -6,3 +6,4 @@ public final String greetUs(final String name1, String name2);
 public final String greetAll(String[] names);
 public final String greetAll(java.util.List<String> names);
 public final String[] greetTimes(String name, int times);
+public final String 
greetInnerChild(org.apache.camel.component.test.TestProxy.InnerChild child);

Reply via email to