camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject git commit: Added support in API component maven plugin for adding extra options to generated EndpointConfiguration
Date Tue, 24 Jun 2014 17:24:23 GMT
Repository: camel
Updated Branches:
  refs/heads/master d7a30b212 -> 5410a4f61


Added support in API component maven plugin for adding extra options to generated EndpointConfiguration


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

Branch: refs/heads/master
Commit: 5410a4f614ed5be7dc545e3ba4772c6560b2937d
Parents: d7a30b2
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Tue Jun 24 10:23:42 2014 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Tue Jun 24 10:24:14 2014 -0700

----------------------------------------------------------------------
 .../camel/util/component/ApiMethodParser.java   |  2 +-
 .../__artifactId__-component/pom.xml            | 20 +++++++++--
 .../src/it/all-it/pom.xml                       | 18 +++++++---
 .../camel/maven/AbstractApiMethodBaseMojo.java  |  3 ++
 .../maven/AbstractApiMethodGeneratorMojo.java   | 31 +++++++++++++++--
 .../camel/maven/ApiComponentGeneratorMojo.java  |  2 ++
 .../java/org/apache/camel/maven/ApiProxy.java   | 10 ++++++
 .../org/apache/camel/maven/ExtraOption.java     | 35 ++++++++++++++++++++
 .../maven/ApiComponentGeneratorMojoTest.java    |  6 +++-
 .../maven/FileApiMethodGeneratorMojoTest.java   |  2 ++
 .../JavadocApiMethodGeneratorMojoTest.java      |  3 ++
 11 files changed, 120 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/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 597a61a..92f5750 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
@@ -315,7 +315,7 @@ public abstract class ApiMethodParser<T> {
         private final Class<?> type;
         private final String typeArgs;
 
-        protected Argument(String name, Class<?> type, String typeArgs) {
+        public Argument(String name, Class<?> type, String typeArgs) {
             this.name = name;
             this.type = type;
             this.typeArgs = typeArgs;

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
index 70735f3..a77b6a3 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
@@ -180,7 +180,20 @@
                     </substitution>
                   </substitutions>
                   -->
-
+                  <!-- Exclude automatically generated endpoint options by name
+                  <excludeConfigNames>name-pattern<excludeConfigNames>
+                  -->
+                  <!-- Exclude automatically generated endpoint options by type
+                  <excludeConfigTypes>type-pattern<excludeConfigTypes>
+                  -->
+                  <!-- Add custom endpoint options to generated EndpointConfiguration
class for this API
+                  <extraOptions>
+                    <extraOption>
+                      <type>java.util.List&lt;String&gt;</type>
+                      <name>customOption</name>
+                    </extraOption>
+                  </extraOptions>
+                  -->
                   <!-- Use method aliases in endpoint URIs, e.g. support 'widget' as alias
for getWidget or setWidget
                   <aliases>
                     <alias>
@@ -203,8 +216,11 @@
                   </fromJavadoc>
                 </api>
               </apis>
-              <!-- Specify global values for all APIs here, only aliases are merged, others
are overridden at API level
+              <!-- Specify global values for all APIs here, these are overridden at API
level
               <substitutions/>
+              <excludeConfigNames/>
+              <excludeConfigTypes/>
+              <extraOptions>
               <fromJavadoc/>
               <aliases/>
               -->

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml b/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
index daf7d64..9295755 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
+++ b/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
@@ -144,6 +144,12 @@
                       <replaceWithType>true</replaceWithType>
                     </substitution>
                   </substitutions>
+                  <extraOptions>
+                    <extraOption>
+                      <type>java.util.List&lt;String&gt;</type>
+                      <name>extraString</name>
+                    </extraOption>
+                  </extraOptions>
                   <fromSignatureFile>../../../src/test/resources/test-proxy-signatures.txt</fromSignatureFile>
                 </api>
                 <api>
@@ -157,17 +163,19 @@
                       <replacement>applicationKey</replacement>
                     </substitution>
                   </substitutions>
+                  <extraOptions>
+                    <extraOption>
+                      <type>java.util.Map&lt;String, String&gt;</type>
+                      <name>extraMap</name>
+                    </extraOption>
+                  </extraOptions>
                   <fromJavadoc>
                     <excludeClasses>InternalContextBase</excludeClasses>
                     <excludeMethods>clone|Current|internal|icache</excludeMethods>
                   </fromJavadoc>
                   <aliases>
                     <alias>
-                      <methodPattern>get(.+)</methodPattern>
-                      <methodAlias>$1</methodAlias>
-                    </alias>
-                    <alias>
-                      <methodPattern>set(.+)</methodPattern>
+                      <methodPattern>[gs]et(.+)</methodPattern>
                       <methodAlias>$1</methodAlias>
                     </alias>
                   </aliases>

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java
index c5e6f1b..aa2f84c 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java
@@ -31,4 +31,7 @@ public abstract class AbstractApiMethodBaseMojo extends AbstractSourceGeneratorM
 
     @Parameter(property = PREFIX + "excludeConfigTypes")
     protected String excludeConfigTypes;
+
+    @Parameter
+    protected ExtraOption[] extraOptions;
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
index 32a9b0e..3881d84 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
@@ -150,8 +150,9 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
         Map<String, ApiMethodParser.Argument> parameters = new TreeMap<String, ApiMethodParser.Argument>();
         for (ApiMethodParser.ApiMethodModel model : models) {
             for (ApiMethodParser.Argument argument : model.getArguments()) {
+
                 final String name = argument.getName();
-                Class<?> type = argument.getType();
+                final Class<?> type = argument.getType();
                 final String typeName = type.getCanonicalName();
                 if (!parameters.containsKey(name)
                         && (propertyNamePattern == null || !propertyNamePattern.matcher(name).matches())
@@ -160,6 +161,30 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
                 }
             }
         }
+
+        // add custom parameters
+        if (extraOptions != null && extraOptions.length > 0) {
+            for (ExtraOption option : extraOptions) {
+                final String name = option.getName();
+                final String argWithTypes = option.getType().replaceAll(" ", "");
+                final int rawEnd = argWithTypes.indexOf('<');
+                String typeArgs = null;
+                Class<?> argType;
+                try {
+                    if (rawEnd != -1) {
+                        argType = getProjectClassLoader().loadClass(argWithTypes.substring(0,
rawEnd));
+                        typeArgs = argWithTypes.substring(rawEnd + 1, argWithTypes.lastIndexOf('>'));
+                    } else {
+                        argType = getProjectClassLoader().loadClass(argWithTypes);
+                    }
+                } catch (ClassNotFoundException e) {
+                    throw new MojoExecutionException(String.format("Error loading extra option
[%s %s] : %s",
+                        argWithTypes, name, e.getMessage()), e);
+                }
+                parameters.put(name, new ApiMethodParser.Argument(name, argType, typeArgs));
+            }
+        }
+
         context.put("parameters", parameters);
         return context;
     }
@@ -300,8 +325,8 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
                         parameterizedType.append(
                             getCanonicalName(getProjectClassLoader().loadClass("java.lang."
+ argType)));
                     } catch (ClassNotFoundException e1) {
-                        log.warn("Ignoring type parameters " + typeArgs + "> for argument
" + argument.getName()
-                                 + ", unable to load parameteric type argument " + argType,
e1);
+                        log.warn("Ignoring type parameters < " + typeArgs + "> for
argument " + argument.getName()
+                                 + ", unable to load parametric type argument " + argType,
e1);
                         ignore = true;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
index 6171c03..290d322 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
@@ -137,6 +137,8 @@ public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo
{
                 ? apiProxy.getExcludeConfigNames() : excludeConfigNames;
         mojo.excludeConfigTypes = apiProxy.getExcludeConfigTypes() != null
                 ? apiProxy.getExcludeConfigTypes() : excludeConfigTypes;
+        mojo.extraOptions = apiProxy.getExtraOptions() != null
+                ? apiProxy.getExtraOptions() : extraOptions;
 
         // set AbstractAPIMethodGeneratorMojo properties
         mojo.proxyClass = apiProxy.getProxyClass();

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
index 1036ecf..a8b8912 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
@@ -42,6 +42,8 @@ public class ApiProxy {
 
     private String excludeConfigTypes;
 
+    private ExtraOption[] extraOptions;
+
     private List<ApiMethodAlias> aliases = Collections.emptyList();
 
     public String getApiName() {
@@ -100,6 +102,14 @@ public class ApiProxy {
         this.excludeConfigTypes = excludeConfigTypes;
     }
 
+    public ExtraOption[] getExtraOptions() {
+        return extraOptions;
+    }
+
+    public void setExtraOptions(ExtraOption[] extraOptions) {
+        this.extraOptions = extraOptions;
+    }
+
     public List<ApiMethodAlias> getAliases() {
         return aliases;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ExtraOption.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ExtraOption.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ExtraOption.java
new file mode 100644
index 0000000..6aebcc8
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ExtraOption.java
@@ -0,0 +1,35 @@
+package org.apache.camel.maven;
+
+/**
+ * Extra endpoint option to add to generated *EndpointConfiguration
+ */
+public class ExtraOption {
+
+    private String type;
+
+    private String name;
+
+    public ExtraOption() {
+    }
+
+    public ExtraOption(String type, String name) {
+        this.type = type;
+        this.name = name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
index b58d6d6..05153ea 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
@@ -53,7 +53,6 @@ public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest
{
         mojo.apis[0].setExcludeConfigNames("name2");
         mojo.apis[0].setExcludeConfigTypes("int");
 
-
         List<ApiMethodAlias> aliases = new ArrayList<ApiMethodAlias>();
         aliases.add(new ApiMethodAlias("get(.+)", "$1"));
         aliases.add(new ApiMethodAlias("set(.+)", "$1"));
@@ -63,6 +62,11 @@ public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest
{
         mojo.apis[1].setAliases(aliases);
         Substitution substitution = new Substitution(".*", "key", "java.lang.Object", "applicationKey",
false);
         mojo.apis[1].setSubstitutions(new Substitution[] {substitution});
+        mojo.apis[1].setExtraOptions(new ExtraOption[] { new ExtraOption("java.util.Map<String,
String>", "extraMap") });
+
+        mojo.extraOptions = new ExtraOption[1];
+        mojo.extraOptions[0] = new ExtraOption("java.util.List<String>", "extraStrings");
+
         final FromJavadoc fromJavadoc = new FromJavadoc();
         fromJavadoc.setExcludePackages(JavadocApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES);
         fromJavadoc.setExcludeMethods("clone|Current|internal|icache");

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
index 86d7575..3988bb3 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
@@ -42,6 +42,8 @@ public class FileApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest
{
         mojo.substitutions = new Substitution[2];
         mojo.substitutions[0] = new Substitution(".+", "(.+)", "java.util.List", "$1List",
false);
         mojo.substitutions[1] = new Substitution(".+", "(.+)", ".*?(\\w++)\\[\\]", "$1Array",
true);
+        mojo.extraOptions = new ExtraOption[1];
+        mojo.extraOptions[0] = new ExtraOption("java.util.List<String>", "extraStrings");
 
         configureSourceGeneratorMojo(mojo);
         mojo.proxyClass = TestProxy.class.getCanonicalName();

http://git-wip-us.apache.org/repos/asf/camel/blob/5410a4f6/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.java
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.java
index cbf11dc..6e34298 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.java
@@ -46,6 +46,9 @@ public class JavadocApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest
         mojo.proxyClass = VelocityContext.class.getCanonicalName();
         Substitution substitution = new Substitution(".*", "key", "java.lang.Object", "applicationKey",
false);
         mojo.substitutions = new Substitution[] {substitution};
+        mojo.extraOptions = new ExtraOption[1];
+        mojo.extraOptions[0] = new ExtraOption("java.util.Map<String, String>", "extraMap");
+
         mojo.excludePackages = JavadocApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES;
         mojo.includeMethods = ".+";
         mojo.excludeMethods = "clone|Current|internal|icache";


Mime
View raw message