You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dh...@apache.org on 2014/06/18 07:50:51 UTC
[1/6] git commit: Initial version of API component documentation
report generator MOJO, minor re-factoring,
fixed MOJO logging to use Log4J-SLF4J bridge to work with Maven 3.1.0 logging
Repository: camel
Updated Branches:
refs/heads/master 1b0337e6e -> ef4d0a7ec
Initial version of API component documentation report generator MOJO, minor re-factoring, fixed MOJO logging to use Log4J-SLF4J bridge to work with Maven 3.1.0 logging
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c639b46d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c639b46d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c639b46d
Branch: refs/heads/master
Commit: c639b46d2e8e440ea6acfff894a7f5e22a886830
Parents: f037c2d
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Mon Jun 16 12:44:20 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 13:51:38 2014 -0700
----------------------------------------------------------------------
.../__artifactId__-component/pom.xml | 44 +-
.../camel-api-component-maven-plugin/pom.xml | 31 +-
.../src/it/all-it/pom.xml | 43 +-
.../maven/AbstractApiMethodGeneratorMojo.java | 11 +-
.../camel/maven/AbstractGeneratorMojo.java | 49 +--
.../maven/AbstractSourceGeneratorMojo.java | 34 ++
.../camel/maven/ApiComponentGeneratorMojo.java | 2 +-
.../camel/maven/DocumentGeneratorMojo.java | 432 +++++++++++++++++++
.../maven/JavadocApiMethodGeneratorMojo.java | 4 +-
.../src/main/resources/api-document.vm | 208 +++++++++
.../src/main/resources/api-endpoint-config.vm | 7 +-
.../main/resources/cameldoc-report.properties | 18 +
.../src/main/resources/log4j.properties | 36 --
.../camel/component/test/TestConfiguration.java | 9 +
.../camel/maven/AbstractGeneratorMojoTest.java | 25 +-
.../maven/ApiComponentGeneratorMojoTest.java | 2 +-
.../camel/maven/DocumentGeneratorMojoTest.java | 49 +++
.../maven/FileApiMethodGeneratorMojoTest.java | 4 +-
.../JavadocApiMethodGeneratorMojoTest.java | 2 +-
19 files changed, 893 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 05992cb..0e61120 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
@@ -145,10 +145,6 @@
<goal>fromFile</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${schemeName}</scheme>
- <componentName>${componentName}</componentName>
<proxyClass>${package}.${name}FileHello</proxyClass>
<!-- Use substitutions to manipulate parameter names and avoid name clashes
<substitutions>
@@ -170,10 +166,6 @@
<goal>fromJavadoc</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${schemeName}</scheme>
- <componentName>${componentName}</componentName>
<proxyClass>${package}.${name}JavadocHello</proxyClass>
<!-- Use substitutions to manipulate parameter names and avoid name clashes
<substitutions>
@@ -199,10 +191,6 @@
<goal>fromApis</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${schemeName}</scheme>
- <componentName>${componentName}</componentName>
<apis>
<api>
<apiName>hello-file</apiName>
@@ -262,6 +250,38 @@
</plugin>
</plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-api-component-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <configuration>
+ <scheme>${schemeName}</scheme>
+ <componentName>${componentName}</componentName>
+ <componentPackage>${componentPackage}</componentPackage>
+ <outPackage>${outPackage}</outPackage>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-api-component-maven-plugin</artifactId>
+ <version>${camel-version}</version>
+ <configuration>
+ <scheme>${schemeName}</scheme>
+ <componentName>${componentName}</componentName>
+ <componentPackage>${componentPackage}</componentPackage>
+ <outPackage>${outPackage}</outPackage>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 7ed800d..dcffb8e 100644
--- a/tooling/maven/camel-api-component-maven-plugin/pom.xml
+++ b/tooling/maven/camel-api-component-maven-plugin/pom.xml
@@ -36,8 +36,16 @@
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
@@ -49,6 +57,12 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-descriptor</artifactId>
<version>2.2.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
@@ -63,12 +77,18 @@
<!-- add some logging to the classpath -->
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <artifactId>log4j-over-slf4j</artifactId>
+ <version>${slf4j-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
@@ -204,6 +224,7 @@
<goals>
<goal>clean</goal>
<goal>verify</goal>
+ <goal>site</goal>
</goals>
</configuration>
<executions>
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 ba2bf7c..af0e4e8 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
@@ -77,10 +77,6 @@
<goal>fromFile</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${scheme}</scheme>
- <componentName>${componentName}</componentName>
<proxyClass>org.apache.camel.component.test.TestProxy</proxyClass>
<substitutions>
<substitution>
@@ -107,10 +103,6 @@
<goal>fromJavadoc</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${scheme}</scheme>
- <componentName>${componentName}</componentName>
<proxyClass>org.apache.velocity.VelocityContext</proxyClass>
<substitutions>
<substitution>
@@ -131,10 +123,6 @@
<goal>fromApis</goal>
</goals>
<configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${scheme}</scheme>
- <componentName>${componentName}</componentName>
<apis>
<api>
<apiName>test</apiName>
@@ -180,6 +168,37 @@
</executions>
</plugin>
</plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <scheme>${scheme}</scheme>
+ <componentName>${componentName}</componentName>
+ <outPackage>${outPackage}</outPackage>
+ <componentPackage>${componentPackage}</componentPackage>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <outPackage>${outPackage}</outPackage>
+ <componentPackage>${componentPackage}</componentPackage>
+ <scheme>${scheme}</scheme>
+ <componentName>${componentName}</componentName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 cba3bb1..8dff89d 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
@@ -34,7 +34,7 @@ import org.apache.velocity.VelocityContext;
/**
* Base Mojo class for ApiMethod generators.
*/
-public abstract class AbstractApiMethodGeneratorMojo extends AbstractGeneratorMojo {
+public abstract class AbstractApiMethodGeneratorMojo extends AbstractSourceGeneratorMojo {
@Parameter(required = true, property = PREFIX + "proxyClass")
protected String proxyClass;
@@ -275,13 +275,4 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractGeneratorMo
return builder.toString();
}
- public static String getCanonicalName(Class<?> type) {
- // remove java.lang prefix for default Java package
- String canonicalName = type.getCanonicalName();
- final int pkgEnd = canonicalName.lastIndexOf('.');
- if (pkgEnd > 0 && canonicalName.substring(0, pkgEnd).equals("java.lang")) {
- canonicalName = canonicalName.substring(pkgEnd + 1);
- }
- return canonicalName;
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
index faf0964..b37d272 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
@@ -28,7 +28,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Properties;
-import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -43,23 +42,16 @@ import org.apache.velocity.runtime.log.Log4JLogChute;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
/**
- * Base class for Api based code generation MOJOs.
+ * Base class for API based generation MOJOs.
*/
public abstract class AbstractGeneratorMojo extends AbstractMojo {
protected static final String PREFIX = "org.apache.camel.";
protected static final String OUT_PACKAGE = PREFIX + "component.internal";
protected static final String COMPONENT_PACKAGE = PREFIX + "component";
- private static final String LOGGER_PREFIX = "log4j.logger";
// used for velocity logging, to avoid creating velocity.log
- protected final Logger LOG = Logger.getLogger(this.getClass());
-
- @Parameter(defaultValue = "${project.build.directory}/generated-sources/camel-component")
- protected File generatedSrcDir;
-
- @Parameter(defaultValue = "${project.build.directory}/generated-test-sources/camel-component")
- protected File generatedTestDir;
+ protected final Logger log = Logger.getLogger(this.getClass());
@Parameter(defaultValue = OUT_PACKAGE)
protected String outPackage;
@@ -70,31 +62,23 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
@Parameter(required = true, property = PREFIX + "componentName")
protected String componentName;
- @Parameter(defaultValue = COMPONENT_PACKAGE)
+ @Parameter(required = true, defaultValue = COMPONENT_PACKAGE)
protected String componentPackage;
- @Parameter(defaultValue = "${project}", readonly = true)
+ @Parameter(required = true, defaultValue = "${project}", readonly = true)
MavenProject project;
private VelocityEngine engine;
private ClassLoader projectClassLoader;
- protected AbstractGeneratorMojo() {
- // configure Log4J from system properties
- for (String propertyName : System.getProperties().stringPropertyNames())
- {
- if (propertyName.startsWith(LOGGER_PREFIX)) {
- String loggerName = propertyName.substring(LOGGER_PREFIX.length());
- String levelName = System.getProperty(propertyName, "");
- Level level = Level.toLevel(levelName); // defaults to DEBUG
- if (!"".equals(levelName) && !levelName.toUpperCase().equals(level.toString())) {
- LOG.warn("Skipping unrecognized log4j log level " + levelName + ": -D" + propertyName + "=" + levelName);
- continue;
- }
- LOG.debug("Setting " + loggerName + " => " + level.toString());
- Logger.getLogger(loggerName).setLevel(level);
- }
+ public static String getCanonicalName(Class<?> type) {
+ // remove java.lang prefix for default Java package
+ String canonicalName = type.getCanonicalName();
+ final int pkgEnd = canonicalName.lastIndexOf('.');
+ if (pkgEnd > 0 && canonicalName.substring(0, pkgEnd).equals("java.lang")) {
+ canonicalName = canonicalName.substring(pkgEnd + 1);
}
+ return canonicalName;
}
public VelocityEngine getEngine() {
@@ -104,7 +88,7 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
velocityProperties.setProperty(RuntimeConstants.RESOURCE_LOADER, "cloader");
velocityProperties.setProperty("cloader.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityProperties.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Log4JLogChute.class.getName());
- velocityProperties.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, LOG.getName());
+ velocityProperties.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, log.getName());
engine = new VelocityEngine(velocityProperties);
engine.init();
}
@@ -124,7 +108,7 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
for (Iterator it = classpathElements.iterator(); it.hasNext(); i++) {
try {
urls[i] = new File((String) it.next()).toURI().toURL();
- LOG.debug("Adding project path " + urls[i]);
+ log.debug("Adding project path " + urls[i]);
} catch (MalformedURLException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
@@ -137,7 +121,10 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
protected void mergeTemplate(VelocityContext context, File outFile, String templateName) throws MojoExecutionException {
// ensure parent directories exist
- outFile.getParentFile().mkdirs();
+ final File outDir = outFile.getParentFile();
+ if (!outDir.isDirectory() && !outDir.mkdirs()) {
+ throw new MojoExecutionException("Error creating directory " + outDir);
+ }
// add generated date
context.put("generatedDate", new Date().toString());
@@ -160,7 +147,7 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
if (writer != null) {
try {
writer.close();
- } catch (IOException ignore) {}
+ } catch (IOException ignore) { }
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractSourceGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractSourceGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractSourceGeneratorMojo.java
new file mode 100644
index 0000000..9c10c6c
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractSourceGeneratorMojo.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven;
+
+import java.io.File;
+
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Base class for API based code generation MOJOs.
+ */
+public abstract class AbstractSourceGeneratorMojo extends AbstractGeneratorMojo {
+
+ @Parameter(defaultValue = "${project.build.directory}/generated-sources/camel-component")
+ protected File generatedSrcDir;
+
+ @Parameter(defaultValue = "${project.build.directory}/generated-test-sources/camel-component")
+ protected File generatedTestDir;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 28d5e3b..74dc1ae 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
@@ -31,7 +31,7 @@ import org.apache.velocity.VelocityContext;
*/
@Mojo(name = "fromApis", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresProject = true,
defaultPhase = LifecyclePhase.GENERATE_SOURCES)
-public class ApiComponentGeneratorMojo extends AbstractGeneratorMojo {
+public class ApiComponentGeneratorMojo extends AbstractSourceGeneratorMojo {
@Parameter(required = true)
protected ApiProxy[] apis;
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
new file mode 100644
index 0000000..3db7343
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/DocumentGeneratorMojo.java
@@ -0,0 +1,432 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.component.ApiCollection;
+import org.apache.camel.util.component.ApiMethod;
+import org.apache.camel.util.component.ApiMethodHelper;
+import org.apache.camel.util.component.ApiName;
+import org.apache.commons.lang.ClassUtils;
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.reporting.MavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.apache.velocity.VelocityContext;
+import org.codehaus.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Generates documentation for API Component.
+ */
+@Mojo(name = "document", requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true,
+ defaultPhase = LifecyclePhase.SITE)
+public class DocumentGeneratorMojo extends AbstractGeneratorMojo implements MavenReport {
+
+ // document output directory
+ @Parameter(property = "reportOutputDirectory",
+ defaultValue = "${project.reporting.outputDirectory}/cameldocs", required = true)
+ private File reportOutputDirectory;
+
+ /**
+ * The name of the Camel report to be displayed in the Maven Generated Reports page
+ * (i.e. <code>project-reports.html</code>).
+ */
+ @Parameter(property = "name")
+ private String name;
+
+ /**
+ * The description of the Camel report to be displayed in the Maven Generated Reports page
+ * (i.e. <code>project-reports.html</code>).
+ */
+ @Parameter(property = "description")
+ private String description;
+
+ private ApiCollection collection;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ RenderingContext context = new RenderingContext(reportOutputDirectory, getOutputName() + ".html");
+ SiteRendererSink sink = new SiteRendererSink(context);
+ Locale locale = Locale.getDefault();
+ try {
+ generate(sink, locale);
+ } catch (MavenReportException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ private void loadApiCollection() throws MavenReportException {
+ try {
+ final Class<?> collectionClass = getProjectClassLoader().loadClass(
+ outPackage + "." + componentName + "ApiCollection");
+ final Method getCollection = collectionClass.getMethod("getCollection");
+ this.collection = (ApiCollection) getCollection.invoke(null);
+ } catch (ClassNotFoundException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (NoSuchMethodException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (InvocationTargetException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (MojoExecutionException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ }
+ }
+
+ private VelocityContext getDocumentContext() throws MavenReportException {
+ final VelocityContext context = new VelocityContext();
+ context.put("helper", this);
+
+ // project GAV
+ context.put("groupId", project.getGroupId());
+ context.put("artifactId", project.getArtifactId());
+ context.put("version", project.getVersion());
+
+ // component URI format
+ // look for single API, no endpoint-prefix
+ final Set<String> apiNames = new TreeSet<String>(collection.getApiNames());
+ context.put("apiNames", apiNames);
+ String suffix;
+ if (apiNames.size() == 1 && ((Set) apiNames).contains("")) {
+ suffix = "://endpoint?[options]";
+ } else {
+ suffix = "://endpoint-prefix/endpoint?[options]";
+ }
+ context.put("uriFormat", scheme + suffix);
+
+ // API helpers
+ final Map<String, ApiMethodHelper> apiHelpers = new TreeMap<String, ApiMethodHelper>();
+ for (Object element : collection.getApiHelpers().entrySet()) {
+ Map.Entry entry = (Map.Entry) element;
+ apiHelpers.put(((ApiName) entry.getKey()).getName(), (ApiMethodHelper) entry.getValue());
+ }
+ context.put("apiHelpers", apiHelpers);
+
+ // API methods and endpoint configurations
+ final Map<String, Class<? extends ApiMethod>> apiMethods = new TreeMap<String, Class<? extends ApiMethod>>();
+ final Map<String, Class<?>> apiConfigs = new TreeMap<String, Class<?>>();
+ for (Object element : collection.getApiMethods().entrySet()) {
+ Map.Entry entry = (Map.Entry) element;
+ final String name = ((ApiName) entry.getValue()).getName();
+
+ Class<? extends ApiMethod> apiMethod = (Class<? extends ApiMethod>) entry.getKey();
+ apiMethods.put(name, apiMethod);
+
+ Class<?> configClass;
+ try {
+ configClass = getProjectClassLoader().loadClass(getEndpointConfigName(apiMethod));
+ } catch (ClassNotFoundException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (MojoExecutionException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ }
+ apiConfigs.put(name, configClass);
+ }
+ context.put("apiMethods", apiMethods);
+ context.put("apiConfigs", apiConfigs);
+
+ // API component properties
+ context.put("scheme", this.scheme);
+ context.put("componentName", this.componentName);
+ Class<?> configClass;
+ try {
+ configClass = getProjectClassLoader().loadClass(getComponentConfig());
+ } catch (ClassNotFoundException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ } catch (MojoExecutionException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ }
+ context.put("componentConfig", configClass);
+ // get declared and derived fields for component config
+ // use get/set methods instead of fields, since this class could inherit others, that have private fields
+ // so getDeclaredFields() won't work, like it does for generated endpoint config classes!!!
+ final Map<String, String> configFields = new TreeMap<String, String>();
+ do {
+ IntrospectionSupport.ClassInfo classInfo = IntrospectionSupport.cacheClass(configClass);
+ for (IntrospectionSupport.MethodInfo method : classInfo.methods) {
+ if (method.isSetter) {
+ configFields.put(method.getterOrSetterShorthandName, getCanonicalName(method.method.getParameterTypes()[0]));
+ }
+ }
+ configClass = configClass.getSuperclass();
+ } while (configClass != null && !configClass.equals(Object.class));
+ context.put("componentConfigFields", configFields);
+
+ return context;
+ }
+
+ private String getComponentConfig() {
+ StringBuilder builder = new StringBuilder(componentPackage);
+ builder.append(".").append(componentName).append("Configuration");
+ return builder.toString();
+ }
+
+ private String getEndpointConfigName(Class<? extends ApiMethod> apiMethod) {
+ final String simpleName = apiMethod.getSimpleName();
+ StringBuilder builder = new StringBuilder(componentPackage);
+ builder.append(".");
+ builder.append(simpleName.substring(0, simpleName.indexOf("ApiMethod")));
+ builder.append("EndpointConfiguration");
+ return builder.toString();
+ }
+
+ private File getDocumentFile() {
+ return new File(getReportOutputDirectory(), getOutputName() + ".html");
+ }
+
+ @Override
+ public void generate(Sink sink, Locale locale) throws MavenReportException {
+ // load APICollection
+ loadApiCollection();
+
+ try {
+ mergeTemplate(getDocumentContext(), getDocumentFile(), "/api-document.vm");
+ } catch (MojoExecutionException e) {
+ throw new MavenReportException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public String getOutputName() {
+ return this.componentName + "Component";
+ }
+
+ @Override
+ public String getCategoryName() {
+ return CATEGORY_PROJECT_REPORTS;
+ }
+
+ @Override
+ public String getName(Locale locale) {
+ if (StringUtils.isEmpty(name)) {
+ return getBundle(locale).getString("report.cameldoc.name");
+ }
+ return name;
+ }
+
+ @Override
+ public String getDescription(Locale locale) {
+ if (StringUtils.isEmpty(description)) {
+ return getBundle(locale).getString("report.cameldoc.description");
+ }
+ return description;
+ }
+
+ @Override
+ public void setReportOutputDirectory(File reportOutputDirectory) {
+ this.reportOutputDirectory = reportOutputDirectory;
+ }
+
+ @Override
+ public File getReportOutputDirectory() {
+ return reportOutputDirectory;
+ }
+
+ @Override
+ public boolean isExternalReport() {
+ return true;
+ }
+
+ @Override
+ public boolean canGenerateReport() {
+ // TODO check for class availability??
+ return true;
+ }
+
+ private ResourceBundle getBundle(Locale locale) {
+ return ResourceBundle.getBundle("cameldoc-report", locale, getClass().getClassLoader());
+ }
+
+ public static List<EndpointInfo> getEndpoints(Class<? extends ApiMethod> apiMethod,
+ ApiMethodHelper<?> helper, Class<?> endpointConfig) {
+ // get list of valid options
+ final Set<String> validOptions = new HashSet<String>();
+ for (Field field : endpointConfig.getDeclaredFields()) {
+ validOptions.add(field.getName());
+ }
+
+ // create method name map
+ final Map<String, List<ApiMethod>> methodMap = new TreeMap<String, List<ApiMethod>>();
+ for (ApiMethod method : apiMethod.getEnumConstants()) {
+ String methodName = method.getName();
+ List<ApiMethod> apiMethods = methodMap.get(methodName);
+ if (apiMethods == null) {
+ apiMethods = new ArrayList<ApiMethod>();
+ methodMap.put(methodName, apiMethods);
+ }
+ apiMethods.add(method);
+ }
+
+ // create method name to alias name map
+ final Map<String, Set<String>> aliasMap = new TreeMap<String, Set<String>>();
+ final Map<String, Set<String>> aliasToMethodMap = helper.getAliases();
+ for (Map.Entry<String, Set<String>> entry : aliasToMethodMap.entrySet()) {
+ final String alias = entry.getKey();
+ for (String method : entry.getValue()) {
+ Set<String> aliases = aliasMap.get(method);
+ if (aliases == null) {
+ aliases = new TreeSet<String>();
+ aliasMap.put(method, aliases);
+ }
+ aliases.add(alias);
+ }
+ }
+
+ // create options map and return type map
+ final Map<String, Set<String>> optionMap = new TreeMap<String, Set<String>>();
+ final Map<String, Set<String>> returnType = new TreeMap<String, Set<String>>();
+ for (Map.Entry<String, List<ApiMethod>> entry : methodMap.entrySet()) {
+ final String name = entry.getKey();
+ final List<ApiMethod> apiMethods = entry.getValue();
+
+ // count the number of times, every valid option shows up across methods
+ // and also collect return types
+ final Map<String, Integer> optionCount = new TreeMap<String, Integer>();
+ final TreeSet<String> resultTypes = new TreeSet<String>();
+ returnType.put(name, resultTypes);
+
+ for (ApiMethod method : apiMethods) {
+ for (String arg : method.getArgNames()) {
+
+ if (validOptions.contains(arg)) {
+ Integer count = optionCount.get(arg);
+ if (count == null) {
+ count = 1;
+ } else {
+ count += 1;
+ }
+ optionCount.put(arg, count);
+ }
+ }
+
+ // wrap primitive result types
+ Class<?> resultType = method.getResultType();
+ if (resultType.isPrimitive()) {
+ resultType = ClassUtils.primitiveToWrapper(resultType);
+ }
+ resultTypes.add(getCanonicalName(resultType));
+ }
+
+ // collect method options
+ final TreeSet<String> options = new TreeSet<String>();
+ optionMap.put(name, options);
+ final Set<String> mandatory = new TreeSet<String>();
+
+ // generate optional and mandatory lists for overloaded methods
+ int nMethods = apiMethods.size();
+ for (ApiMethod method : apiMethods) {
+ final Set<String> optional = new TreeSet<String>();
+
+ for (String arg : method.getArgNames()) {
+ if (validOptions.contains(arg)) {
+
+ final Integer count = optionCount.get(arg);
+ if (count == nMethods) {
+ mandatory.add(arg);
+ } else {
+ optional.add(arg);
+ }
+ }
+ }
+
+ if (!optional.isEmpty()) {
+ options.add(optional.toString());
+ }
+ }
+
+ if (!mandatory.isEmpty()) {
+ // strip [] from mandatory options
+ final String mandatoryOptions = mandatory.toString();
+ options.add(mandatoryOptions.substring(1, mandatoryOptions.length() - 1));
+ }
+ }
+
+ // create endpoint data
+ final List<EndpointInfo> infos = new ArrayList<EndpointInfo>();
+ for (Map.Entry<String, List<ApiMethod>> methodEntry : methodMap.entrySet()) {
+ final String endpoint = methodEntry.getKey();
+
+ // set endpoint name
+ EndpointInfo info = new EndpointInfo();
+ info.endpoint = endpoint;
+ info.aliases = convertSetToString(aliasMap.get(endpoint));
+ info.options = convertSetToString(optionMap.get(endpoint));
+ final Set<String> resultTypes = returnType.get(endpoint);
+ // get rid of void results
+ resultTypes.remove("void");
+ info.resultTypes = convertSetToString(resultTypes);
+
+ infos.add(info);
+ }
+
+ return infos;
+ }
+
+ private static String convertSetToString(Set<String> values) {
+ if (values != null && !values.isEmpty()) {
+ final String result = values.toString();
+ return result.substring(1, result.length() - 1);
+ } else {
+ return "";
+ }
+ }
+
+ public static class EndpointInfo {
+ private String endpoint;
+ private String aliases;
+ private String options;
+ private String resultTypes;
+
+ public String getEndpoint() {
+ return endpoint;
+ }
+
+ public String getAliases() {
+ return aliases;
+ }
+
+ public String getOptions() {
+ return options;
+ }
+
+ public String getResultTypes() {
+ return resultTypes;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
index 72116e6..a62b35e 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
@@ -91,7 +91,7 @@ public class JavadocApiMethodGeneratorMojo extends AbstractApiMethodGeneratorMoj
(classPatterns == null || !classPatterns.matcher(aClass.getSimpleName()).matches());
aClass = aClass.getSuperclass()) {
- LOG.debug("Processing " + aClass.getName());
+ log.debug("Processing " + aClass.getName());
final String javaDocPath = aClass.getName().replaceAll("\\.", "/") + ".html";
// read javadoc html text for class
@@ -99,7 +99,7 @@ public class JavadocApiMethodGeneratorMojo extends AbstractApiMethodGeneratorMoj
try {
inputStream = getProjectClassLoader().getResourceAsStream(javaDocPath);
if (inputStream == null) {
- LOG.debug("JavaDoc not found on classpath for " + aClass.getName());
+ log.debug("JavaDoc not found on classpath for " + aClass.getName());
break;
}
// transform the HTML to get method summary as text
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-document.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-document.vm b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-document.vm
new file mode 100644
index 0000000..66d7f18
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-document.vm
@@ -0,0 +1,208 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+## api-document.vm
+<!DOCTYPE html>
+<html>
+<head>
+ <title>${componentName} Component</title>
+</head>
+<style>
+ table,th,td
+ {
+ border:1px solid black;
+ border-collapse:collapse;
+ }
+ th,td
+ {
+ padding:5px;
+ }
+ th
+ {
+ text-align:left;
+ }
+</style>
+<body>
+ <h2>${componentName} Component</h2>
+ <hr/>
+ <h3>Component Description</h3>
+ <p>Maven users will need to add the following dependency to their pom.xml for this component:</p>
+ <code>
+ <pre>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+ </dependency>
+ </pre>
+ </code>
+
+ <h3>URI Format</h3>
+ <hr/>
+ <p>The ${componentName} Component uses the following URI format:</p>
+ <pre>
+ ${uriFormat}
+ </pre>
+#set( $hasApiPrefix = $uriFormat.contains("-prefix") )
+#if( $hasApiPrefix )
+ <p>Endpoint prefix can be one of:</p>
+ <ul>
+#foreach( $name in $apiNames )
+ <li>$name</li>
+#end
+#end
+ </ul>
+ <h3>${componentName}Component</h3>
+ <hr/>
+ <p>
+ The ${componentName} Component can be configured with the options below.
+ These options can be provided using the component's bean property <code>configuration</code> of type <code>$componentConfiguration.Name</code>.
+ </p>
+ <table>
+ <tr>
+ <th>Option</th>
+ <th>Type</th>
+ </tr>
+#foreach( $field in $componentConfigFields.entrySet() )
+ <tr>
+ <td>$field.Key</td>
+ <td>$field.Value</td>
+ </tr>
+#end
+ </table>
+ <h3>Producer Endpoints</h3>
+ <hr/>
+#if( !$hasApiPrefix )
+ <p>
+ Producer endpoints can use endpoint names and options listed next.
+ A shorthand alias can be used for some endpoints.
+ </p>
+#else
+ <p>
+ Producer endpoints can use endpoint prefixes followed by endpoint names and options described next.
+ A shorthand alias can be used for some endpoints. The URI MUST specify one of the following prefixes.
+ </p>
+#end
+ <p>
+ Endpoint options that are not mandatory are denoted by [].
+ Producer endpoints can also use a special option <b><code>inBody</code></b> that in turn should contain
+ the name of the endpoint option whose value will be contained in the Camel Exchange In message.
+ </p>
+ <p>
+ Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header.
+ The message header name must be of the format <code>Camel${componentName}.<option></code>.
+ Note that the <code>inBody</code> option overrides message header,
+ i.e. the endpoint option <code>inBody=option</code> would override a <code>Camel${componentName}.option</code> header.
+ </p>
+## single API use case, only list methods and options
+#if( !$hasApiPrefix )
+#set( $endpointConfig = $apiConfigs.get("") )
+#set( $endpoints = $helper.getEndpoints($apiMethods.get(""), $apiHelpers.get(""), $endpointConfig) )
+ <table>
+ <tr>
+ <th>Endpoint</th>
+ <th>Shorthand Alias</th>
+ <th>Options</th>
+ <th>Result Body Type</th>
+ </tr>
+#foreach( $endpoint in $endpoints )
+ <tr>
+ <td>$endpoint.endpoint</td>
+ <td>$endpoint.aliases</td>
+ <td>$endpoint.options</td>
+ <td>$endpoint.resultTypes</td>
+ </tr>
+#end
+ </table>
+ <h3>URI Options</h3>
+ <hr/>
+ <table>
+ <tr>
+ <th>Name</th>
+ <th>Type</th>
+ </tr>
+#foreach( $field in $endpointConfig.DeclaredFields )
+ <tr>
+ <td>$field.Name</td>
+ <td>$helper.getCanonicalName($field.Type)</td>
+ </tr>
+#end
+ </table>
+#else
+## multiple API use case, list API names and their methods and options
+#foreach( $apiMethod in $apiMethods.entrySet() )
+#set( $apiName = $apiMethod.Key )
+ <h3>${foreach.count}. Endpoint Prefix $apiName</h3>
+ <hr/>
+ <p>The following endpoints can be invoked with the prefix $apiName as follows:</p>
+ <pre>
+ ${scheme}://${apiName}/endpoint?[options]
+ </pre>
+ <table>
+ <tr>
+ <th>Endpoint</th>
+ <th>Shorthand Alias</th>
+ <th>Options</th>
+ <th>Result Body Type</th>
+ </tr>
+#set( $endpointConfig = $apiConfigs.get($apiName) )
+#set( $endpoints = $helper.getEndpoints($apiMethod.Value, $apiHelpers.get($apiName), $endpointConfig) )
+#foreach( $endpoint in $endpoints )
+ <tr>
+ <td>$endpoint.Endpoint</td>
+ <td>$endpoint.Aliases</td>
+ <td>$endpoint.Options</td>
+ <td>$endpoint.ResultTypes</td>
+ </tr>
+#end
+ </table>
+ <h4>URI Options for $apiName</h4>
+ <hr/>
+ <table>
+ <tr>
+ <th>Name</th>
+ <th>Type</th>
+ </tr>
+#foreach( $field in $endpointConfig.DeclaredFields )
+ <tr>
+ <td>$field.Name</td>
+ <td>$helper.getCanonicalName($field.Type)</td>
+ </tr>
+#end
+ </table>
+#end
+#end
+ <h3>Consumer Endpoints</h3>
+ <hr/>
+ <p>
+ Any of the producer endpoints can be used as a consumer endpoint.
+ Consumer endpoints can use <a href="http://camel.apache.org/polling-consumer.html#PollingConsumer-ScheduledPollConsumerOptions">Scheduled Poll Consumer Options</a> with a <code>consumer.</code> prefix to schedule endpoint invocation.
+ Consumer endpoints that return an array or collection will generate one exchange per element, and their routes will be executed once for each exchange.
+ </p>
+ <h3>Message Headers</h3>
+ <hr/>
+ <p>
+ Any URI option can be provided in a message header for producer endpoints with a <code>Camel${componentName}.</code> prefix.
+ </p>
+ <h3>Message Body</h3>
+ <hr/>
+ <p>
+ All result message bodies utilize objects provided by the underlying APIs used by the ${componentName}Component. Producer endpoints can specify the option name for incoming message body in the <code>inBody</code> endpoint URI parameter.
+ For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages.
+ </p>
+</body>
+</html>
+
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
index f01d29e..6bc875f 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
@@ -21,13 +21,18 @@
*/
package ${componentPackage};
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
/**
* Camel EndpointConfiguration for $proxyType.Name
*/
@SuppressWarnings("unused")
+@UriParams
public final class $configName extends ${componentName}Configuration {
-
#foreach( $parameter in $parameters.entrySet() )
+
+ @UriParam
private $helper.getCanonicalName($parameter.Value) $parameter.Key;
#end
## getters and setters
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/resources/cameldoc-report.properties
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/cameldoc-report.properties b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/cameldoc-report.properties
new file mode 100644
index 0000000..2aaf142
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/cameldoc-report.properties
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+report.cameldoc.name=Camel Component Documentation
+report.cameldoc.description=Documentation describing an API based Camel Component
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/log4j.properties b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/log4j.properties
deleted file mode 100644
index 3d544fc..0000000
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-#
-# The logging properties used
-#
-log4j.rootLogger=INFO, out
-
-# uncomment the following line to turn on Camel debugging
-#log4j.logger.org.apache.camel=DEBUG
-
-# CONSOLE appender not used by default
-log4j.appender.out=org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
-#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
-log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
-
-#log4j.logger.org.apache.camel.maven=DEBUG
-#log4j.logger.org.apache.http=DEBUG
-#log4j.logger.org.apache.camel.util.component=TRACE
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
index de22f82..f5f4d41 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
@@ -20,4 +20,13 @@ package org.apache.camel.component.test;
* Dummy component configuration.
*/
public class TestConfiguration {
+ private String testProperty;
+
+ public String getTestProperty() {
+ return testProperty;
+ }
+
+ public void setTestProperty(String testProperty) {
+ this.testProperty = testProperty;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java
index 7d67a7b..afc8fc6 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java
@@ -45,11 +45,15 @@ public abstract class AbstractGeneratorMojoTest {
assertTrue("Generated file not found " + outFile.getPath(), outFile.exists());
}
- protected void configureMojo(AbstractGeneratorMojo mojo) {
- mojo.componentName = COMPONENT_NAME;
- mojo.scheme = SCHEME;
+ protected void configureSourceGeneratorMojo(AbstractSourceGeneratorMojo mojo) {
+ configureGeneratorMojo(mojo);
mojo.generatedSrcDir = new File(OUT_DIR);
mojo.generatedTestDir = new File(OUT_DIR);
+ }
+
+ protected void configureGeneratorMojo(AbstractGeneratorMojo mojo) {
+ mojo.componentName = COMPONENT_NAME;
+ mojo.scheme = SCHEME;
mojo.outPackage = OUT_PACKAGE;
mojo.componentPackage = COMPONENT_PACKAGE;
mojo.project = new MavenProject((Model) null) {
@@ -67,6 +71,21 @@ public abstract class AbstractGeneratorMojoTest {
}
};
}
+
+ @Override
+ public String getGroupId() {
+ return "org.apache.camel.component";
+ }
+
+ @Override
+ public String getArtifactId() {
+ return "camel-test";
+ }
+
+ @Override
+ public String getVersion() {
+ return "1.0-SNAPSHOT";
+ }
};
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 3e9400c..05e989d 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
@@ -38,7 +38,7 @@ public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest {
collectionFile.delete();
final ApiComponentGeneratorMojo mojo = new ApiComponentGeneratorMojo();
- configureMojo(mojo);
+ configureSourceGeneratorMojo(mojo);
mojo.apis = new ApiProxy[2];
mojo.apis[0] = new ApiProxy("test", TestProxy.class.getName());
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/DocumentGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/DocumentGeneratorMojoTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/DocumentGeneratorMojoTest.java
new file mode 100644
index 0000000..a0459a3
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/DocumentGeneratorMojoTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven;
+
+import java.io.File;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Tests {@link org.apache.camel.maven.FileApiMethodGeneratorMojo}
+ */
+public class DocumentGeneratorMojoTest extends AbstractGeneratorMojoTest {
+
+ @Ignore(value = "Can only be run manually after generating and compiling code from other generators")
+ @Test
+ public void testExecute() throws Exception {
+ // delete target file to begin
+ final File outDir = new File("target/site/camelDocs");
+ final File outFile = new File(outDir, "TestComponent.html");
+ if (outFile.exists()) {
+ outFile.delete();
+ }
+
+ final DocumentGeneratorMojo mojo = new DocumentGeneratorMojo();
+ configureGeneratorMojo(mojo);
+ mojo.setReportOutputDirectory(outDir);
+
+ mojo.execute();
+
+ // check target file was generated
+ assertExists(outFile);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 a68fba8..d52de9d 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
@@ -44,7 +44,7 @@ public class FileApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest {
mojo.substitutions[0] = new Substitution(".+", "(.+)", "java.util.List", "$1List", false);
mojo.substitutions[1] = new Substitution(".+", "(.+)", ".*?(\\w++)\\[\\]", "$1Array", true);
- configureMojo(mojo);
+ configureSourceGeneratorMojo(mojo);
mojo.proxyClass = TestProxy.class.getCanonicalName();
mojo.signatureFile = new File("src/test/resources/test-proxy-signatures.txt");
@@ -55,7 +55,7 @@ public class FileApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest {
mojo.execute();
// check target file was generated
- assertTrue("Generated file not found " + outFile.getPath(), outFile.exists());
+ assertExists(outFile);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/c639b46d/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 ded66dd..c9e9f1c 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
@@ -40,7 +40,7 @@ public class JavadocApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest
final JavadocApiMethodGeneratorMojo mojo = new JavadocApiMethodGeneratorMojo();
- configureMojo(mojo);
+ configureSourceGeneratorMojo(mojo);
// use VelocityEngine javadoc
mojo.proxyClass = VelocityContext.class.getCanonicalName();
[5/6] git commit: Major refactor of API component framework to
generify base classes, added AbstractApiComponent to reduce boilderplate code,
minor compiler warnings removed
Posted by dh...@apache.org.
Major refactor of API component framework to generify base classes, added AbstractApiComponent to reduce boilderplate code, minor compiler warnings removed
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7dc2bb13
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7dc2bb13
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7dc2bb13
Branch: refs/heads/master
Commit: 7dc2bb13a645c2c2a4dbfc9ec0ed0e5b2a63b914
Parents: 5dd9cc0
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Tue Jun 17 13:50:34 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 13:51:39 2014 -0700
----------------------------------------------------------------------
.../util/component/AbstractApiComponent.java | 267 +++++++++++++++++++
.../util/component/AbstractApiConsumer.java | 25 +-
.../util/component/AbstractApiEndpoint.java | 35 ++-
.../util/component/AbstractApiProducer.java | 28 +-
.../camel/util/component/ApiCollection.java | 18 +-
.../apache/camel/util/component/ApiMethod.java | 11 +-
.../camel/util/component/ApiMethodHelper.java | 76 +++---
.../camel/util/component/ApiMethodImpl.java | 1 -
.../util/component/ApiMethodHelperTest.java | 26 +-
.../ApiMethodPropertiesHelperTest.java | 4 +-
.../src/main/java/__name__Component.java | 82 +-----
.../src/main/java/__name__Consumer.java | 4 +-
.../src/main/java/__name__Endpoint.java | 19 +-
.../src/main/java/__name__Producer.java | 3 +-
.../org/apache/camel/maven/ApiMethodAlias.java | 1 +
.../java/org/apache/camel/maven/ApiProxy.java | 3 +-
16 files changed, 408 insertions(+), 195 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiComponent.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiComponent.java
new file mode 100644
index 0000000..9d20455
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiComponent.java
@@ -0,0 +1,267 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util.component;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelException;
+import org.apache.camel.ComponentConfiguration;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.EndpointCompleter;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Abstract base class for API Component Camel {@link org.apache.camel.Component} classes.
+ */
+public abstract class AbstractApiComponent<E extends Enum<E> & ApiName, T, S extends ApiCollection<E, T>>
+ extends UriEndpointComponent implements EndpointCompleter {
+
+ @UriParam
+ protected T configuration;
+
+ // API collection
+ protected final S collection;
+
+ // API name class
+ protected final Class<E> apiNameClass;
+
+ public AbstractApiComponent(Class<? extends Endpoint> endpointClass,
+ Class<E> apiNameClass, S collection) {
+ super(endpointClass);
+ this.collection = collection;
+ this.apiNameClass = apiNameClass;
+ }
+
+ public AbstractApiComponent(CamelContext context, Class<? extends Endpoint> endpointClass,
+ Class<E> apiNameClass, S collection) {
+ super(context, endpointClass);
+ this.collection = collection;
+ this.apiNameClass = apiNameClass;
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ // split remaining path to get API name and method
+ final String[] pathElements = remaining.split("/");
+ String apiNameStr;
+ String methodName;
+ switch (pathElements.length) {
+ case 1:
+ apiNameStr = "";
+ methodName = pathElements[0];
+ break;
+ case 2:
+ apiNameStr = pathElements[0];
+ methodName = pathElements[1];
+ break;
+ default:
+ throw new CamelException("Invalid URI path [" + remaining
+ + "], must be of the format " + collection.getApiNames() + "/<operation-name>");
+ }
+
+ try {
+ // get API enum from apiName string
+ final E apiName = getApiName(apiNameStr);
+
+ final T endpointConfiguration = createEndpointConfiguration(apiName);
+ final Endpoint endpoint = createEndpoint(uri, methodName, apiName, endpointConfiguration);
+
+ // set endpoint property inBody
+ setProperties(endpoint, parameters);
+
+ // configure endpoint properties and initialize state
+ endpoint.configureProperties(parameters);
+
+ return endpoint;
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof IllegalArgumentException) {
+ throw new CamelException("Invalid URI path prefix [" + remaining
+ + "], must be one of " + collection.getApiNames());
+ }
+ throw e;
+ }
+ }
+
+ protected abstract E getApiName(String apiNameStr) throws IllegalArgumentException;
+
+ protected abstract Endpoint createEndpoint(String uri, String methodName, E apiName, T endpointConfiguration);
+
+ protected T createEndpointConfiguration(E name) throws Exception {
+ final Map<String, Object> componentProperties = new HashMap<String, Object>();
+ // copy component configuration, if set
+ if (configuration != null) {
+ IntrospectionSupport.getProperties(configuration, componentProperties, null, false);
+ }
+
+ // create endpoint configuration with component properties
+ final T endpointConfiguration = collection.getEndpointConfiguration(name);
+ IntrospectionSupport.setProperties(endpointConfiguration, componentProperties);
+ return endpointConfiguration;
+ }
+
+ public T getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(T configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public List<String> completeEndpointPath(ComponentConfiguration configuration, String completionText) {
+ final List<String> result = new ArrayList<String>();
+
+ final Set<String> apiNames = collection.getApiNames();
+ boolean useDefaultName = apiNames.size() == 1 && apiNames.contains("");
+
+ // check if there is an API name present
+ completionText = ObjectHelper.isEmpty(completionText) ? "" : completionText;
+ final int prefixEnd = completionText.indexOf('/');
+ final int pathEnd = completionText.lastIndexOf('?');
+
+ // empty or incomplete API prefix, and no options, add API names or method names if useDefaultName
+ final Map<E, ? extends ApiMethodHelper<? extends ApiMethod>> apiHelpers = collection.getApiHelpers();
+ if (prefixEnd == -1 && pathEnd == -1) {
+
+ if (useDefaultName) {
+
+ // complete method names for default API
+ final Set<Class<? extends ApiMethod>> apiMethods = collection.getApiMethods().keySet();
+ final Class<? extends ApiMethod> apiMethod = apiMethods.iterator().next();
+ final ApiMethodHelper<? extends ApiMethod> helper = apiHelpers.values().iterator().next();
+ getCompletedMethods(result, completionText, apiMethod, helper);
+ } else {
+
+ // complete API names
+ for (String name : apiNames) {
+ if (!name.isEmpty() || name.startsWith(completionText)) {
+ result.add(name);
+ }
+ }
+ }
+
+ // path with complete API name prefix, but no options
+ } else if (prefixEnd != -1 && pathEnd == -1) {
+
+ // complete method names for specified API
+ final E apiName = getApiNameOrNull(completionText.substring(0, prefixEnd));
+ if (apiName != null) {
+ final ApiMethodHelper<? extends ApiMethod> helper = apiHelpers.get(apiName);
+ completionText = completionText.substring(prefixEnd + 1);
+ for (Map.Entry<Class<? extends ApiMethod>, E> entry : collection.getApiMethods().entrySet()) {
+ if (entry.getValue().equals(apiName)) {
+ getCompletedMethods(result, completionText, entry.getKey(), helper);
+ break;
+ }
+ }
+ }
+
+ // complete options
+ } else {
+
+ // get last option text
+ final int lastParam = completionText.lastIndexOf('&');
+ String optionText;
+ if (lastParam != -1) {
+ optionText = completionText.substring(lastParam + 1);
+ } else {
+ optionText = completionText.substring(pathEnd);
+ }
+
+ String methodName = null;
+ ApiMethodHelper<? extends ApiMethod> helper = null;
+ if (useDefaultName) {
+
+ // get default endpoint configuration and helper
+ methodName = completionText.substring(0, pathEnd);
+ helper = apiHelpers.values().iterator().next();
+ } else {
+
+ // get API name and method name, if they exist
+ final String[] pathElements = completionText.substring(0, pathEnd).split("/");
+ if (pathElements.length == 2) {
+ final E apiName = getApiNameOrNull(pathElements[0]);
+ methodName = pathElements[1];
+ helper = collection.getHelper(apiName);
+ }
+ }
+ if (helper != null && !ObjectHelper.isEmpty(methodName)) {
+ // get other options from configuration
+ Set<String> existingOptions = configuration.getParameters().keySet();
+ // get all method options
+ try {
+ final List arguments = helper.getArguments(methodName);
+ final int nArgs = arguments.size();
+ final Set<String> options = new HashSet<String>();
+ for (int i = 1; i < nArgs; i += 2) {
+ options.add((String) arguments.get(i));
+ }
+ options.removeAll(existingOptions);
+
+ // return matching options
+ for (String option : options) {
+ if (option.startsWith(optionText)) {
+ result.add(option);
+ }
+ }
+ } catch (IllegalArgumentException ignore) {
+ // thrown from getArguments() when no matching methods,
+ // return an empty result
+ }
+ }
+ }
+
+ return result;
+ }
+
+ // returns null instead of throwing IllegalArgumentException for invalid name
+ protected E getApiNameOrNull(String nameStr) {
+ try {
+ return getApiName(nameStr);
+ } catch (IllegalArgumentException ignore) {
+ return null;
+ }
+ }
+
+ protected void getCompletedMethods(List<String> result, String completionText,
+ Class<? extends ApiMethod> apiMethod, ApiMethodHelper<? extends ApiMethod> helper) {
+ // add potential method names
+ final ApiMethod[] methods = apiMethod.getEnumConstants();
+ for (ApiMethod method : methods) {
+ final String name = method.getName();
+ if (name.startsWith(completionText)) {
+ result.add(name);
+ }
+ }
+ // add potential aliases
+ final Map<String, Set<String>> aliases = helper.getAliases();
+ for (String alias : aliases.keySet()) {
+ if (alias.startsWith(completionText)) {
+ result.add(alias);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
index 1d63339..44fad39 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
@@ -35,25 +35,25 @@ import org.slf4j.LoggerFactory;
/**
* Abstract base class for API Component Consumers.
*/
-public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
+public abstract class AbstractApiConsumer<E extends Enum<E> & ApiName, T> extends ScheduledPollConsumer {
// logger
protected final Logger log = LoggerFactory.getLogger(getClass());
// API Endpoint
- protected final AbstractApiEndpoint endpoint;
+ protected final AbstractApiEndpoint<E, T> endpoint;
// helpers
- protected final ApiMethodPropertiesHelper propertiesHelper;
- protected final ApiMethodHelper methodHelper;
+ protected final ApiMethodPropertiesHelper<T> propertiesHelper;
+ protected final ApiMethodHelper<? extends ApiMethod> methodHelper;
// API method to invoke
- protected final Enum<? extends ApiMethod> method;
+ protected final ApiMethod method;
// properties used to invoke
protected final Map<String, Object> endpointProperties;
- public AbstractApiConsumer(AbstractApiEndpoint endpoint, Processor processor) {
+ public AbstractApiConsumer(AbstractApiEndpoint<E, T> endpoint, Processor processor) {
super(endpoint, processor);
this.endpoint = endpoint;
@@ -76,10 +76,9 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
return false;
}
- @SuppressWarnings("unchecked")
- private Enum<? extends ApiMethod> findMethod() {
+ private ApiMethod findMethod() {
- Enum<? extends ApiMethod> result;
+ ApiMethod result;
// find one that takes the largest subset of endpoint parameters
final Set<String> argNames = new HashSet<String>();
argNames.addAll(propertiesHelper.getEndpointPropertyNames(endpoint.getConfiguration()));
@@ -87,7 +86,7 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
interceptArgumentNames(argNames);
final String[] argNamesArray = argNames.toArray(new String[argNames.size()]);
- List<Enum<? extends ApiMethod>> filteredMethods = methodHelper.filterMethods(
+ List<ApiMethod> filteredMethods = ApiMethodHelper.filterMethods(
endpoint.getCandidates(), ApiMethodHelper.MatchType.SUPER_SET, argNamesArray);
if (filteredMethods.isEmpty()) {
@@ -99,9 +98,10 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
// single match
result = filteredMethods.get(0);
} else {
- result = methodHelper.getHighestPriorityMethod(filteredMethods);
+ result = ApiMethodHelper.getHighestPriorityMethod(filteredMethods);
log.warn("Using highest priority operation {} from operations {}", method, filteredMethods);
}
+
return result;
}
@@ -147,9 +147,8 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
* @param args method arguments from endpoint parameters.
* @return method invocation result.
*/
- @SuppressWarnings("unchecked")
protected Object doInvokeMethod(Map<String, Object> args) {
- return methodHelper.invokeMethod(endpoint.getApiProxy(), method, args);
+ return ApiMethodHelper.invokeMethod(endpoint.getApiProxy(), method, args);
}
private void processResult(Object result) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
index 4217c4a..2a4ef13 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
@@ -34,34 +34,39 @@ import org.slf4j.LoggerFactory;
/**
* Abstract base class for API Component Endpoints.
*/
-public abstract class AbstractApiEndpoint extends DefaultEndpoint {
+public abstract class AbstractApiEndpoint<E extends ApiName, T> extends DefaultEndpoint {
// logger
protected final Logger log = LoggerFactory.getLogger(getClass());
// API name
- protected final ApiName apiName;
+ protected final E apiName;
// API method name
protected final String methodName;
// API method helper
- protected final ApiMethodHelper methodHelper;
+ protected final ApiMethodHelper<? extends ApiMethod> methodHelper;
+
+ // endpoint configuration
+ @UriParam
+ protected final T configuration;
// property name for Exchange 'In' message body
@UriParam
protected String inBody;
// candidate methods based on method name and endpoint configuration
- private List<Enum<? extends ApiMethod>> candidates;
+ private List<ApiMethod> candidates;
public AbstractApiEndpoint(String endpointUri, Component component,
- ApiName apiName, String methodName, ApiMethodHelper methodHelper) {
+ E apiName, String methodName, ApiMethodHelper<? extends ApiMethod> methodHelper, T endpointConfiguration) {
super(endpointUri, component);
this.apiName = apiName;
this.methodName = methodName;
this.methodHelper = methodHelper;
+ this.configuration = endpointConfiguration;
}
public boolean isSingleton() {
@@ -72,7 +77,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
* Returns generated helper that extends {@link ApiMethodPropertiesHelper} to work with API properties.
* @return properties helper.
*/
- protected abstract ApiMethodPropertiesHelper getPropertiesHelper();
+ protected abstract ApiMethodPropertiesHelper<T> getPropertiesHelper();
@Override
public void configureProperties(Map<String, Object> options) {
@@ -80,11 +85,11 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
// set configuration properties first
try {
- Object configuration = getConfiguration();
+ T configuration = getConfiguration();
EndpointHelper.setReferenceProperties(getCamelContext(), configuration, options);
EndpointHelper.setProperties(getCamelContext(), configuration, options);
} catch (Exception e) {
- throw new IllegalArgumentException(e.getMessage(), e);
+ throw new IllegalArgumentException(e);
}
// validate and initialize state
@@ -101,7 +106,6 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
/**
* Initialize endpoint state, including endpoint arguments, find candidate methods, etc.
*/
- @SuppressWarnings("unchecked")
protected void initState() {
// get endpoint property names
@@ -117,7 +121,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
final String[] argNames = arguments.toArray(new String[arguments.size()]);
// create a list of candidate methods
- candidates = new ArrayList<Enum<? extends ApiMethod>>();
+ candidates = new ArrayList<ApiMethod>();
candidates.addAll(methodHelper.getCandidateMethods(methodName, argNames));
// error if there are no candidates
@@ -148,15 +152,18 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
/**
* Returns endpoint configuration object.
* One of the generated *EndpointConfiguration classes that extends component configuration class.
+ *
* @return endpoint configuration object
*/
- public abstract Object getConfiguration();
+ public T getConfiguration() {
+ return configuration;
+ }
/**
* Returns API name.
* @return apiName property.
*/
- public ApiName getApiName() {
+ public E getApiName() {
return apiName;
}
@@ -172,7 +179,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
* Returns method helper.
* @return methodHelper property.
*/
- public ApiMethodHelper getMethodHelper() {
+ public ApiMethodHelper<? extends ApiMethod> getMethodHelper() {
return methodHelper;
}
@@ -180,7 +187,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
* Returns candidate methods for this endpoint.
* @return list of candidate methods.
*/
- public List<Enum<? extends ApiMethod>> getCandidates() {
+ public List<ApiMethod> getCandidates() {
return Collections.unmodifiableList(candidates);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
index a9795f2..cb0d7f1 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
@@ -36,24 +36,24 @@ import org.slf4j.LoggerFactory;
/**
* Base class for API based Producers
*/
-public abstract class AbstractApiProducer extends DefaultAsyncProducer {
+public abstract class AbstractApiProducer<E extends Enum<E> & ApiName, T> extends DefaultAsyncProducer {
// thread pool executor
protected static ExecutorService executorService;
// API Endpoint
- protected final AbstractApiEndpoint endpoint;
+ protected final AbstractApiEndpoint<E, T> endpoint;
// properties helper
protected final ApiMethodPropertiesHelper propertiesHelper;
// method helper
- protected final ApiMethodHelper methodHelper;
+ protected final ApiMethodHelper<?> methodHelper;
// logger
private final transient Logger log = LoggerFactory.getLogger(getClass());
- public AbstractApiProducer(AbstractApiEndpoint endpoint, ApiMethodPropertiesHelper propertiesHelper) {
+ public AbstractApiProducer(AbstractApiEndpoint<E, T> endpoint, ApiMethodPropertiesHelper propertiesHelper) {
super(endpoint);
this.propertiesHelper = propertiesHelper;
this.endpoint = endpoint;
@@ -70,7 +70,7 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
interceptProperties(properties);
// decide which method to invoke
- final Enum<? extends ApiMethod> method = findMethod(exchange, properties);
+ final ApiMethod method = findMethod(exchange, properties);
if (method == null) {
// synchronous failure
callback.done(true);
@@ -84,7 +84,7 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
public void run() {
try {
if (log.isDebugEnabled()) {
- log.debug("Invoking operation {} with {}", ((ApiMethod) method).getName(), properties.keySet());
+ log.debug("Invoking operation {} with {}", method.getName(), properties.keySet());
}
Object result = doInvokeMethod(method, properties);
@@ -125,9 +125,8 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
* @return API method invocation result.
* @throws RuntimeCamelException on error. Exceptions thrown by API method are wrapped.
*/
- @SuppressWarnings("unchecked")
- protected Object doInvokeMethod(Enum<? extends ApiMethod> method, Map<String, Object> properties) throws RuntimeCamelException {
- return methodHelper.invokeMethod(endpoint.getApiProxy(), method, properties);
+ protected Object doInvokeMethod(ApiMethod method, Map<String, Object> properties) throws RuntimeCamelException {
+ return ApiMethodHelper.invokeMethod(endpoint.getApiProxy(), method, properties);
}
/**
@@ -139,16 +138,15 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
// do nothing by default
}
- @SuppressWarnings("unchecked")
- private Enum<? extends ApiMethod> findMethod(Exchange exchange, Map<String, Object> properties) {
+ private ApiMethod findMethod(Exchange exchange, Map<String, Object> properties) {
- Enum<? extends ApiMethod> method = null;
- final List<Enum<? extends ApiMethod>> candidates = endpoint.getCandidates();
+ ApiMethod method = null;
+ final List<ApiMethod> candidates = endpoint.getCandidates();
if (processInBody(exchange, properties)) {
// filter candidates based on endpoint and exchange properties
final Set<String> argNames = properties.keySet();
- final List<Enum<? extends ApiMethod>> filteredMethods = methodHelper.filterMethods(candidates,
+ final List<ApiMethod> filteredMethods = ApiMethodHelper.filterMethods(candidates,
ApiMethodHelper.MatchType.SUPER_SET,
argNames.toArray(new String[argNames.size()]));
@@ -161,7 +159,7 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
// found an exact match
method = filteredMethods.get(0);
} else {
- method = methodHelper.getHighestPriorityMethod(filteredMethods);
+ method = ApiMethodHelper.getHighestPriorityMethod(filteredMethods);
log.warn("Calling highest priority operation {} from operations {}", method, filteredMethods);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
index 2231ceb..f39440f 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
@@ -26,16 +26,16 @@ import java.util.Set;
* Base class for a collection of ApiMethods. Meant to be extended by Components to create the api name map.
*/
@SuppressWarnings("unused")
-public abstract class ApiCollection<T extends Enum & ApiName, C> {
+public abstract class ApiCollection<E extends Enum<E> & ApiName, T> {
- protected final Map<T, ApiMethodHelper> apis = new HashMap<T, ApiMethodHelper>();
- protected final HashMap<Class<? extends ApiMethod>, T> apiMethods = new HashMap<Class<? extends ApiMethod>, T>();
+ protected final Map<E, ApiMethodHelper<? extends ApiMethod>> apis = new HashMap<E, ApiMethodHelper<? extends ApiMethod>>();
+ protected final HashMap<Class<? extends ApiMethod>, E> apiMethods = new HashMap<Class<? extends ApiMethod>, E>();
- public final Map<T, ApiMethodHelper> getApiHelpers() {
+ public final Map<E, ApiMethodHelper<? extends ApiMethod>> getApiHelpers() {
return Collections.unmodifiableMap(apis);
}
- public final Map<Class<? extends ApiMethod>, T> getApiMethods() {
+ public final Map<Class<? extends ApiMethod>, E> getApiMethods() {
return Collections.unmodifiableMap(apiMethods);
}
@@ -44,7 +44,7 @@ public abstract class ApiCollection<T extends Enum & ApiName, C> {
* @param apiName name of the API
* @return helper class to work with {@link ApiMethod}
*/
- public final ApiMethodHelper getHelper(T apiName) {
+ public final ApiMethodHelper<? extends ApiMethod> getHelper(E apiName) {
return apis.get(apiName);
}
@@ -54,13 +54,13 @@ public abstract class ApiCollection<T extends Enum & ApiName, C> {
*/
public final Set<String> getApiNames() {
final Set<String> result = new HashSet<String>();
- for (T api : apis.keySet()) {
+ for (E api : apis.keySet()) {
result.add(api.getName());
}
return Collections.unmodifiableSet(result);
}
- public final T getApiName(Class<? extends ApiMethod> apiMethod) {
+ public final E getApiName(Class<? extends ApiMethod> apiMethod) {
return apiMethods.get(apiMethod);
}
@@ -69,5 +69,5 @@ public abstract class ApiCollection<T extends Enum & ApiName, C> {
* @param apiName name of the API.
* @return Endpoint configuration object for the API.
*/
- public abstract C getEndpointConfiguration(T apiName);
+ public abstract T getEndpointConfiguration(E apiName);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/ApiMethod.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethod.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethod.java
index 7ee7cb9..a2274bf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethod.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethod.java
@@ -26,32 +26,31 @@ public interface ApiMethod {
/**
* Returns method name.
- * @return
+ * @return name
*/
String getName();
/**
* Returns method result type.
- * @return
+ * @return result type
*/
Class<?> getResultType();
/**
* Returns method argument names.
- * @return
+ * @return argument names
*/
List<String> getArgNames();
/**
* Return method argument types.
- * @return
+ * @return argument types
*/
List<Class<?>> getArgTypes();
/**
* Returns {@link Method} in proxy type.
- * @return
+ * @return method
*/
Method getMethod();
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
index 7ce841b..27ba116 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
@@ -42,16 +42,16 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
private static final Logger LOG = LoggerFactory.getLogger(ApiMethodHelper.class);
// maps method name to ApiMethod
- private final Map<String, List<T>> METHOD_MAP = new HashMap<String, List<T>>();
+ private final Map<String, List<T>> methodMap = new HashMap<String, List<T>>();
// maps method name to method arguments of the form Class type1, String name1, Class type2, String name2,...
- private final Map<String, List<Object>> ARGUMENTS_MAP = new HashMap<String, List<Object>>();
+ private final Map<String, List<Object>> argumentsMap = new HashMap<String, List<Object>>();
// maps argument name to argument type
- private final Map<String, Class<?>> VALID_ARGUMENTS = new HashMap<String, Class<?>>();
+ private final Map<String, Class<?>> validArguments = new HashMap<String, Class<?>>();
// maps aliases to actual method names
- private final HashMap<String, Set<String>> ALIASES = new HashMap<String, Set<String>>();
+ private final HashMap<String, Set<String>> aliases = new HashMap<String, Set<String>>();
/**
* Create a helper to work with a {@link ApiMethod}, using optional method aliases.
@@ -95,28 +95,28 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
builder.append(Character.toLowerCase(firstChar)).append(alias.substring(1));
alias = builder.toString();
}
- Set<String> names = ALIASES.get(alias);
+ Set<String> names = this.aliases.get(alias);
if (names == null) {
names = new HashSet<String>();
- ALIASES.put(alias, names);
+ this.aliases.put(alias, names);
}
names.add(name);
}
}
// map method name to Enum
- List<T> overloads = METHOD_MAP.get(name);
+ List<T> overloads = methodMap.get(name);
if (overloads == null) {
overloads = new ArrayList<T>();
- METHOD_MAP.put(method.getName(), overloads);
+ methodMap.put(method.getName(), overloads);
}
overloads.add(method);
// add arguments for this method
- List<Object> arguments = ARGUMENTS_MAP.get(name);
+ List<Object> arguments = argumentsMap.get(name);
if (arguments == null) {
arguments = new ArrayList<Object>();
- ARGUMENTS_MAP.put(name, arguments);
+ argumentsMap.put(name, arguments);
}
// process all arguments for this method
@@ -132,35 +132,36 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
}
// also collect argument names for all methods, and detect clashes here
- final Class<?> previousType = VALID_ARGUMENTS.get(argName);
+ final Class<?> previousType = validArguments.get(argName);
if (previousType != null && previousType != argType) {
throw new IllegalArgumentException(String.format(
"Argument %s has ambiguous types (%s, %s) across methods!",
name, previousType, argType));
} else if (previousType == null) {
- VALID_ARGUMENTS.put(argName, argType);
+ validArguments.put(argName, argType);
}
}
}
- LOG.debug("Found {} unique method names in {} methods", METHOD_MAP.size(), methods.length);
+ LOG.debug("Found {} unique method names in {} methods", methodMap.size(), methods.length);
}
/**
* Gets methods that match the given name and arguments.<p/>
* Note that the args list is a required subset of arguments for returned methods.
+ *
* @param name case sensitive method name or alias to lookup
* @param argNames unordered required argument names
* @return non-null unmodifiable list of methods that take all of the given arguments, empty if there is no match
*/
- public List<T> getCandidateMethods(String name, String... argNames) {
- List<T> methods = METHOD_MAP.get(name);
+ public List<ApiMethod> getCandidateMethods(String name, String... argNames) {
+ List<T> methods = methodMap.get(name);
if (methods == null) {
- if (ALIASES.containsKey(name)) {
+ if (aliases.containsKey(name)) {
methods = new ArrayList<T>();
- for (String method : ALIASES.get(name)) {
- methods.addAll(METHOD_MAP.get(method));
+ for (String method : aliases.get(name)) {
+ methods.addAll(methodMap.get(method));
}
}
}
@@ -171,9 +172,9 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
int nArgs = argNames != null ? argNames.length : 0;
if (nArgs == 0) {
LOG.debug("Found {} methods for method {}", methods.size(), name);
- return Collections.unmodifiableList(methods);
+ return Collections.<ApiMethod>unmodifiableList(methods);
} else {
- final List<T> filteredSet = filterMethods(methods, MatchType.SUBSET, argNames);
+ final List<ApiMethod> filteredSet = filterMethods(methods, MatchType.SUBSET, argNames);
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} filtered methods for {}",
filteredSet.size(), name + Arrays.toString(argNames).replace('[', '(').replace(']', ')'));
@@ -191,14 +192,14 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return methods with arguments that satisfy the match type.<p/>
* For SUPER_SET match, if methods with exact match are found, methods that take a subset are ignored
*/
- public List<T> filterMethods(List<T> methods, MatchType matchType,
+ public static List<ApiMethod> filterMethods(List<? extends ApiMethod> methods, MatchType matchType,
String... argNames) {
List<String> argsList = Arrays.asList(argNames);
// list of methods that have all args in the given names
- final List<T> result = new ArrayList<T>();
- final List<T> extraArgs = new ArrayList<T>();
+ final List<ApiMethod> result = new ArrayList<ApiMethod>();
+ final List<ApiMethod> extraArgs = new ArrayList<ApiMethod>();
- for (T method : methods) {
+ for (ApiMethod method : methods) {
final List<String> methodArgs = method.getArgNames();
switch (matchType) {
case EXACT:
@@ -238,12 +239,12 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return list of arguments of the form Class type1, String name1, Class type2, String name2,...
*/
public List<Object> getArguments(final String name) throws IllegalArgumentException {
- List<Object> arguments = ARGUMENTS_MAP.get(name);
+ List<Object> arguments = argumentsMap.get(name);
if (arguments == null) {
- if (ALIASES.containsKey(name)) {
+ if (aliases.containsKey(name)) {
arguments = new ArrayList<Object>();
- for (String method : ALIASES.get(name)) {
- arguments.addAll(ARGUMENTS_MAP.get(method));
+ for (String method : aliases.get(name)) {
+ arguments.addAll(argumentsMap.get(method));
}
}
}
@@ -278,7 +279,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return alias names mapped to method names.
*/
public Map<String, Set<String>> getAliases() {
- return Collections.unmodifiableMap(ALIASES);
+ return Collections.unmodifiableMap(aliases);
}
/**
@@ -286,7 +287,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return map with argument names as keys, and types as values
*/
public Map<String, Class<?>> allArguments() {
- return Collections.unmodifiableMap(VALID_ARGUMENTS);
+ return Collections.unmodifiableMap(validArguments);
}
/**
@@ -295,17 +296,20 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return argument type
*/
public Class<?> getType(String argName) throws IllegalArgumentException {
- final Class<?> type = VALID_ARGUMENTS.get(argName);
+ final Class<?> type = validArguments.get(argName);
if (type == null) {
throw new IllegalArgumentException(argName);
}
return type;
}
- public T getHighestPriorityMethod(List<T> filteredMethods) {
- T highest = null;
- for (T method : filteredMethods) {
- if (highest == null || method.compareTo(highest) > 0) {
+ // this method is always called with Enum value lists, so the cast inside is safe
+ // the alternative of trying to convert ApiMethod and associated classes to generic classes would a bear!!!
+ @SuppressWarnings("unchecked")
+ public static ApiMethod getHighestPriorityMethod(List<? extends ApiMethod> filteredMethods) {
+ ApiMethod highest = null;
+ for (ApiMethod method : filteredMethods) {
+ if (highest == null || ((Enum)method).compareTo((Enum) highest) > 0) {
highest = method;
}
}
@@ -321,7 +325,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
* @return result of method invocation
* @throws org.apache.camel.RuntimeCamelException on errors
*/
- public Object invokeMethod(Object proxy, T method, Map<String, Object> properties)
+ public static Object invokeMethod(Object proxy, ApiMethod method, Map<String, Object> properties)
throws RuntimeCamelException {
if (LOG.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodImpl.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodImpl.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodImpl.java
index 2884164..75c66a6 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodImpl.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodImpl.java
@@ -119,5 +119,4 @@ public final class ApiMethodImpl implements ApiMethod {
.append("}");
return builder.toString();
}
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/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 12bc877..1fb84b7 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
@@ -39,7 +39,7 @@ public class ApiMethodHelperTest {
@Test
public void testGetCandidateMethods() {
- List<TestMethod> methods = apiMethodHelper.getCandidateMethods("sayHi");
+ List<ApiMethod> methods = apiMethodHelper.getCandidateMethods("sayHi");
assertEquals("Can't find sayHi(*)", 2, methods.size());
methods = apiMethodHelper.getCandidateMethods("hi");
@@ -57,22 +57,22 @@ public class ApiMethodHelperTest {
@Test
public void testFilterMethods() {
- List<TestMethod> methods = apiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.EXACT);
+ List<ApiMethod> methods = ApiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.EXACT);
assertEquals("Exact match failed for sayHi()", 1, methods.size());
assertEquals("Exact match failed for sayHi()", TestMethod.SAYHI, methods.get(0));
- methods = apiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUBSET);
+ methods = ApiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUBSET);
assertEquals("Subset match failed for sayHi(*)", 2, methods.size());
- methods = apiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUBSET, "name");
+ methods = ApiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUBSET, "name");
assertEquals("Subset match failed for sayHi(name)", 1, methods.size());
assertEquals("Exact match failed for sayHi()", TestMethod.SAYHI_1, methods.get(0));
- methods = apiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUPER_SET, "name");
+ methods = ApiMethodHelper.filterMethods(Arrays.asList(sayHis), ApiMethodHelper.MatchType.SUPER_SET, "name");
assertEquals("Super set match failed for sayHi(name)", 1, methods.size());
assertEquals("Exact match failed for sayHi()", TestMethod.SAYHI_1, methods.get(0));
- methods = apiMethodHelper.filterMethods(Arrays.asList(TestMethod.values()), ApiMethodHelper.MatchType.SUPER_SET, "name");
+ methods = ApiMethodHelper.filterMethods(Arrays.asList(TestMethod.values()), ApiMethodHelper.MatchType.SUPER_SET, "name");
assertEquals("Super set match failed for sayHi(name)", 2, methods.size());
}
@@ -114,28 +114,28 @@ public class ApiMethodHelperTest {
@Test
public void testGetHighestPriorityMethod() throws Exception {
assertEquals("Get highest priority method",
- TestMethod.SAYHI_1, apiMethodHelper.getHighestPriorityMethod(Arrays.asList(sayHis)));
+ TestMethod.SAYHI_1, ApiMethodHelper.getHighestPriorityMethod(Arrays.asList(sayHis)));
}
@Test
public void testInvokeMethod() throws Exception {
TestProxy proxy = new TestProxy();
- assertEquals("sayHi()", "Hello!", apiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI, Collections.EMPTY_MAP));
+ assertEquals("sayHi()", "Hello!", ApiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI, Collections.<String, Object>emptyMap()));
final HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("name", "Dave");
- assertEquals("sayHi(name)", "Hello Dave", apiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI_1, properties));
- assertEquals("greetMe(name)", "Greetings Dave", apiMethodHelper.invokeMethod(proxy, TestMethod.GREETME, properties));
+ assertEquals("sayHi(name)", "Hello Dave", ApiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI_1, properties));
+ assertEquals("greetMe(name)", "Greetings Dave", ApiMethodHelper.invokeMethod(proxy, TestMethod.GREETME, properties));
properties.clear();
properties.put("name1", "Dave");
properties.put("name2", "Frank");
- assertEquals("greetUs(name1, name2)", "Greetings Dave, Frank", apiMethodHelper.invokeMethod(proxy, TestMethod.GREETUS, properties));
+ assertEquals("greetUs(name1, name2)", "Greetings Dave, Frank", ApiMethodHelper.invokeMethod(proxy, TestMethod.GREETUS, properties));
properties.clear();
properties.put("names", new String[] { "Dave", "Frank" });
- assertEquals("greetAll(names)", "Greetings Dave, Frank", apiMethodHelper.invokeMethod(proxy, TestMethod.GREETALL, properties));
+ assertEquals("greetAll(names)", "Greetings Dave, Frank", ApiMethodHelper.invokeMethod(proxy, TestMethod.GREETALL, properties));
// test with a derived proxy
proxy = new TestProxy() {
@@ -146,7 +146,7 @@ public class ApiMethodHelperTest {
};
properties.clear();
properties.put("name", "Dave");
- assertEquals("Derived sayHi(name)", "Howdy Dave", apiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI_1, properties));
+ assertEquals("Derived sayHi(name)", "Howdy Dave", ApiMethodHelper.invokeMethod(proxy, TestMethod.SAYHI_1, properties));
}
static enum TestMethod implements ApiMethod {
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
index cfc29d1..65b7538 100644
--- a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
@@ -38,7 +38,7 @@ public class ApiMethodPropertiesHelperTest {
private static final String VALUE_4 = "true";
private static ApiMethodPropertiesHelper propertiesHelper =
- new ApiMethodPropertiesHelper(TestComponentConfiguration.class, TEST_PREFIX){};
+ new ApiMethodPropertiesHelper<TestComponentConfiguration>(TestComponentConfiguration.class, TEST_PREFIX){};
@Test
public void testGetExchangeProperties() throws Exception {
@@ -77,6 +77,7 @@ public class ApiMethodPropertiesHelperTest {
assertEquals(2, propertiesHelper.getValidEndpointProperties(new TestEndpointConfiguration()).size());
}
+ @SuppressWarnings("unused")
private static class TestComponentConfiguration {
private String property1;
private Long property2;
@@ -98,6 +99,7 @@ public class ApiMethodPropertiesHelperTest {
}
}
+ @SuppressWarnings("unused")
private static class TestEndpointConfiguration extends TestComponentConfiguration {
private String property3;
private Boolean property4;
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
index 34ce74c..05fd2d0 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
@@ -16,16 +16,10 @@
## ------------------------------------------------------------------------
package ${package};
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.camel.CamelContext;
-import org.apache.camel.CamelException;
import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.component.AbstractApiComponent;
import ${package}.internal.${name}ApiCollection;
import ${package}.internal.${name}ApiName;
@@ -34,78 +28,24 @@ import ${package}.internal.${name}ApiName;
* Represents the component that manages {@link ${name}Endpoint}.
*/
@UriEndpoint(scheme = "${scheme}", consumerClass = ${name}Consumer.class, consumerPrefix = "consumer")
-public class ${name}Component extends UriEndpointComponent {
-
- @UriParam
- private ${name}Configuration configuration;
-
- private final ${name}ApiCollection collection = ${name}ApiCollection.getCollection();
+public class ${name}Component extends AbstractApiComponent<${name}ApiName, ${name}Configuration, ${name}ApiCollection> {
public ${name}Component() {
- super(${name}Endpoint.class);
+ super(${name}Endpoint.class, ${name}ApiName.class, ${name}ApiCollection.getCollection());
}
public ${name}Component(CamelContext context) {
- super(context, ${name}Endpoint.class);
- }
-
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- // split remaining path to get API name and method
- final String[] pathElements = remaining.split("/");
- String apiNameStr;
- String methodName;
- switch (pathElements.length) {
- case 1:
- apiNameStr = "";
- methodName = pathElements[0];
- break;
- case 2:
- apiNameStr = pathElements[0];
- methodName = pathElements[1];
- break;
- default:
- throw new CamelException("Invalid URI path [" + remaining
- + "], must be of the format " + collection.getApiNames() + "/<operation-name>");
- }
-
- // get API enum from apiName string
- final ${name}ApiName apiName;
- try {
- apiName = ${name}ApiName.fromValue(apiNameStr);
- } catch (IllegalArgumentException e) {
- throw new CamelException("Invalid URI path prefix [" + remaining
- + "], must be one of " + collection.getApiNames());
- }
-
- final ${name}Configuration endpointConfiguration = createEndpointConfiguration(apiName);
- final Endpoint endpoint = new ${name}Endpoint(uri, this, apiName, methodName, endpointConfiguration);
-
- // set endpoint property inBody
- setProperties(endpoint, parameters);
-
- // configure endpoint properties and initialize state
- endpoint.configureProperties(parameters);
-
- return endpoint;
- }
-
- private ${name}Configuration createEndpointConfiguration(${name}ApiName name) throws Exception {
- final Map<String, Object> componentProperties = new HashMap<String, Object>();
- if (configuration != null) {
- IntrospectionSupport.getProperties(configuration, componentProperties, null, false);
- }
-
- // create endpoint configuration with component properties
- final ${name}Configuration endpointConfiguration = collection.getEndpointConfiguration(name);
- IntrospectionSupport.setProperties(endpointConfiguration, componentProperties);
- return endpointConfiguration;
+ super(context, ${name}Endpoint.class, ${name}ApiName.class, ${name}ApiCollection.getCollection());
}
- public ${name}Configuration getConfiguration() {
- return configuration;
+ @Override
+ protected ${name}ApiName getApiName(String apiNameStr) throws IllegalArgumentException {
+ return ${name}ApiName.fromValue(apiNameStr);
}
- public void setConfiguration(${name}Configuration configuration) {
- this.configuration = configuration;
+ @Override
+ protected Endpoint createEndpoint(String uri, String methodName, ${name}ApiName apiName,
+ ${name}Configuration endpointConfiguration) {
+ return new ${name}Endpoint(uri, this, apiName, methodName, endpointConfiguration);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Consumer.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Consumer.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Consumer.java
index 56ae89d..d493267 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Consumer.java
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Consumer.java
@@ -19,10 +19,12 @@ package ${package};
import org.apache.camel.Processor;
import org.apache.camel.util.component.AbstractApiConsumer;
+import ${package}.internal.${name}ApiName;
+
/**
* The ${name} consumer.
*/
-public class ${name}Consumer extends AbstractApiConsumer {
+public class ${name}Consumer extends AbstractApiConsumer<${name}ApiName, ${name}Configuration> {
public ${name}Consumer(${name}Endpoint endpoint, Processor processor) {
super(endpoint, processor);
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
index 3b68f84..aaed38f 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
@@ -20,7 +20,6 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
import org.apache.camel.util.component.AbstractApiEndpoint;
import org.apache.camel.util.component.ApiMethodPropertiesHelper;
@@ -32,19 +31,15 @@ import ${package}.internal.${name}PropertiesHelper;
* Represents a ${name} endpoint.
*/
@UriEndpoint(scheme = "${scheme}", consumerClass = ${name}Consumer.class, consumerPrefix = "consumer")
-public class ${name}Endpoint extends AbstractApiEndpoint {
-
- @UriParam
- protected final ${name}Configuration configuration;
+public class ${name}Endpoint extends AbstractApiEndpoint<${name}ApiName, ${name}Configuration> {
// TODO create and manage API proxy
private Object apiProxy;
public ${name}Endpoint(String uri, ${name}Component component,
${name}ApiName apiName, String methodName, ${name}Configuration endpointConfiguration) {
- super(uri, component, apiName, methodName, ${name}ApiCollection.getCollection().getHelper(apiName));
+ super(uri, component, apiName, methodName, ${name}ApiCollection.getCollection().getHelper(apiName), endpointConfiguration);
- this.configuration = endpointConfiguration;
}
public Producer createProducer() throws Exception {
@@ -63,7 +58,7 @@ public class ${name}Endpoint extends AbstractApiEndpoint {
}
@Override
- protected ApiMethodPropertiesHelper getPropertiesHelper() {
+ protected ApiMethodPropertiesHelper<${name}Configuration> getPropertiesHelper() {
return ${name}PropertiesHelper.getHelper();
}
@@ -76,15 +71,13 @@ public class ${name}Endpoint extends AbstractApiEndpoint {
break;
case HELLO_JAVADOC:
apiProxy = new ${name}JavadocHello();
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid API name " + apiName);
}
}
@Override
- public ${name}Configuration getConfiguration() {
- return configuration;
- }
-
- @Override
public Object getApiProxy() {
return apiProxy;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Producer.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Producer.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Producer.java
index 46c4871..3a9adba 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Producer.java
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Producer.java
@@ -18,13 +18,14 @@ package ${package};
import org.apache.camel.util.component.AbstractApiProducer;
+import ${package}.internal.${name}ApiName;
import ${package}.internal.${name}Constants;
import ${package}.internal.${name}PropertiesHelper;
/**
* The ${name} producer.
*/
-public class ${name}Producer extends AbstractApiProducer {
+public class ${name}Producer extends AbstractApiProducer<${name}ApiName, ${name}Configuration> {
public ${name}Producer(${name}Endpoint endpoint) {
super(endpoint, ${name}PropertiesHelper.getHelper());
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
index 71bb89e..8002fba 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
@@ -19,6 +19,7 @@ package org.apache.camel.maven;
/**
* Represents method alias
*/
+@SuppressWarnings("unused")
public class ApiMethodAlias {
private String methodPattern;
http://git-wip-us.apache.org/repos/asf/camel/blob/7dc2bb13/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 69a759b..22c3870 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
@@ -22,11 +22,12 @@ import java.util.List;
/**
* Represents an API to use for generating Camel Component.
*/
+@SuppressWarnings("unused")
public class ApiProxy {
private String apiName;
private String proxyClass;
- private List<ApiMethodAlias> aliases = Collections.EMPTY_LIST;
+ private List<ApiMethodAlias> aliases = Collections.emptyList();
public ApiProxy() {
}
[6/6] git commit: Moved sample APIs to api package,
added bnd instructions in archetype
Posted by dh...@apache.org.
Moved sample APIs to api package, added bnd instructions in archetype
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef4d0a7e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef4d0a7e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef4d0a7e
Branch: refs/heads/master
Commit: ef4d0a7ec43f4c702c75aafc3c6cba72ff9b9281
Parents: 7dc2bb1
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Tue Jun 17 15:01:04 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 15:01:04 2014 -0700
----------------------------------------------------------------------
.../src/main/java/__name__FileHello.java | 35 --------------------
.../src/main/java/__name__JavadocHello.java | 35 --------------------
.../src/main/java/api/__name__FileHello.java | 35 ++++++++++++++++++++
.../src/main/java/api/__name__JavadocHello.java | 35 ++++++++++++++++++++
.../__artifactId__-component/pom.xml | 23 ++++++++++---
.../src/main/java/__name__Endpoint.java | 2 ++
6 files changed, 90 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__FileHello.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__FileHello.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__FileHello.java
deleted file mode 100644
index 071e281..0000000
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__FileHello.java
+++ /dev/null
@@ -1,35 +0,0 @@
-## ------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ------------------------------------------------------------------------
-package ${package};
-
-/**
- * Sample API used by ${name} Component whose method signatures are read from File.
- */
-public class ${name}FileHello {
-
- public String sayHi() {
- return "Hello!";
- }
-
- public String greetMe(String name) {
- return "Hello " + name;
- }
-
- public String greetUs(String name1, String name2) {
- return "Hello " + name1 + ", " + name2;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__JavadocHello.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__JavadocHello.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__JavadocHello.java
deleted file mode 100644
index 39430f2..0000000
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/__name__JavadocHello.java
+++ /dev/null
@@ -1,35 +0,0 @@
-## ------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ------------------------------------------------------------------------
-package ${package};
-
-/**
- * Sample API used by ${name} Component whose method signatures are read from Javadoc.
- */
-public class ${name}JavadocHello {
-
- public String sayHi() {
- return "Hello!";
- }
-
- public String greetMe(String name) {
- return "Hello " + name;
- }
-
- public String greetUs(String name1, String name2) {
- return "Hello " + name1 + ", " + name2;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__FileHello.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__FileHello.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__FileHello.java
new file mode 100644
index 0000000..8f509df
--- /dev/null
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__FileHello.java
@@ -0,0 +1,35 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+package ${package}.api;
+
+/**
+ * Sample API used by ${name} Component whose method signatures are read from File.
+ */
+public class ${name}FileHello {
+
+ public String sayHi() {
+ return "Hello!";
+ }
+
+ public String greetMe(String name) {
+ return "Hello " + name;
+ }
+
+ public String greetUs(String name1, String name2) {
+ return "Hello " + name1 + ", " + name2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__JavadocHello.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__JavadocHello.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__JavadocHello.java
new file mode 100644
index 0000000..0b983a0
--- /dev/null
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/src/main/java/api/__name__JavadocHello.java
@@ -0,0 +1,35 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+package ${package}.api;
+
+/**
+ * Sample API used by ${name} Component whose method signatures are read from Javadoc.
+ */
+public class ${name}JavadocHello {
+
+ public String sayHi() {
+ return "Hello!";
+ }
+
+ public String greetMe(String name) {
+ return "Hello " + name;
+ }
+
+ public String greetUs(String name1, String name2) {
+ return "Hello " + name1 + ", " + name2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/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 1f676e8..add5147 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
@@ -128,8 +128,21 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Bundle-Name>Camel Component for ${componentName}</Bundle-Name>
<Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName>
- <Export-Service>org.apache.camel.spi.ComponentResolver;component=${scheme}</Export-Service>
+ <Export-Service>org.apache.camel.spi.ComponentResolver;component=${schemeName}</Export-Service>
+ <Export-Package>${componentPackage};version=${project.version}</Export-Package>
+ <Import-Package>
+ ${componentPackage}.api;version=${project.version},
+ ${componentPackage};version=${project.version},
+ org.apache.camel.*;version=${camel-version}
+ </Import-Package>
+ <Private-Package>${outPackage}</Private-Package>
+ <Implementation-Title>Apache Camel</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Karaf-Info>Camel;${project.artifactId}=${project.version}</Karaf-Info>
+ <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
+ <_failok>false</_failok>
</instructions>
</configuration>
</plugin>
@@ -146,7 +159,7 @@
<goal>fromFile</goal>
</goals>
<configuration>
- <proxyClass>${package}.${name}FileHello</proxyClass>
+ <proxyClass>${package}.api.${name}FileHello</proxyClass>
<!-- Use substitutions to manipulate parameter names and avoid name clashes
<substitutions>
<substitution>
@@ -167,7 +180,7 @@
<goal>fromJavadoc</goal>
</goals>
<configuration>
- <proxyClass>${package}.${name}JavadocHello</proxyClass>
+ <proxyClass>${package}.api.${name}JavadocHello</proxyClass>
<!-- Use substitutions to manipulate parameter names and avoid name clashes
<substitutions>
<substitution>
@@ -195,7 +208,7 @@
<apis>
<api>
<apiName>hello-file</apiName>
- <proxyClass>${package}.${name}FileHello</proxyClass>
+ <proxyClass>${package}.api.${name}FileHello</proxyClass>
<!-- Use method aliases in endpoint URIs, e.g. support 'widget' as alias for getWidget or setWidget
<aliases>
<alias>
@@ -211,7 +224,7 @@
</api>
<api>
<apiName>hello-javadoc</apiName>
- <proxyClass>${package}.${name}JavadocHello</proxyClass>
+ <proxyClass>${package}.api.${name}JavadocHello</proxyClass>
</api>
</apis>
</configuration>
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4d0a7e/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
index aaed38f..dec1ba3 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Endpoint.java
@@ -23,6 +23,8 @@ import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.util.component.AbstractApiEndpoint;
import org.apache.camel.util.component.ApiMethodPropertiesHelper;
+import ${package}.api.${name}FileHello;
+import ${package}.api.${name}JavadocHello;
import ${package}.internal.${name}ApiCollection;
import ${package}.internal.${name}ApiName;
import ${package}.internal.${name}PropertiesHelper;
[4/6] git commit: Added project description to api-component archetype
Posted by dh...@apache.org.
Added project description to api-component archetype
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dee15fb2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dee15fb2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dee15fb2
Branch: refs/heads/master
Commit: dee15fb2a59644c00073b5cf922e71896d6776d6
Parents: c639b46
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Mon Jun 16 12:58:59 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 13:51:39 2014 -0700
----------------------------------------------------------------------
.../main/resources/archetype-resources/__artifactId__-api/pom.xml | 1 +
.../resources/archetype-resources/__artifactId__-component/pom.xml | 1 +
.../src/main/resources/archetype-resources/pom.xml | 1 +
3 files changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/dee15fb2/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/pom.xml b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/pom.xml
index c4af2c8..da5ed70 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/pom.xml
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-api/pom.xml
@@ -28,6 +28,7 @@
<artifactId>${artifactId}-api</artifactId>
<name>Camel ${name} Component API</name>
<url>http://www.myorganization.org</url>
+ <description>API for Camel ${name} Component</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
http://git-wip-us.apache.org/repos/asf/camel/blob/dee15fb2/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 0e61120..1f676e8 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
@@ -28,6 +28,7 @@
<artifactId>${artifactId}</artifactId>
<packaging>bundle</packaging>
<name>Camel ${name} Component</name>
+ <description>Camel Component for ${name}</description>
<url>http://www.myorganization.org</url>
<properties>
http://git-wip-us.apache.org/repos/asf/camel/blob/dee15fb2/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/pom.xml b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/pom.xml
index c623fa3..6876c18 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/pom.xml
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/pom.xml
@@ -26,6 +26,7 @@
<name>Camel ${name} Component Parent</name>
<url>http://www.myorganization.org</url>
+ <description>Parent project for Camel {$name} Component</description>
<modules>
<module>${artifactId}-component</module>
[2/6] git commit: Minor polish,
added utility methods for document generation
Posted by dh...@apache.org.
Minor polish, added utility methods for document generation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f037c2da
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f037c2da
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f037c2da
Branch: refs/heads/master
Commit: f037c2da57492eac1819e415752f9d2b6585d5d6
Parents: 1b0337e
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Fri Jun 13 14:55:54 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 13:51:38 2014 -0700
----------------------------------------------------------------------
.../apache/camel/util/component/AbstractApiConsumer.java | 4 +++-
.../apache/camel/util/component/AbstractApiEndpoint.java | 4 ++--
.../apache/camel/util/component/AbstractApiProducer.java | 1 +
.../org/apache/camel/util/component/ApiCollection.java | 10 +++++++++-
.../org/apache/camel/util/component/ApiMethodHelper.java | 8 ++++++++
5 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f037c2da/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
index 9406f35..1d63339 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiConsumer.java
@@ -110,6 +110,7 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
* Used to add any custom/hidden method arguments, which MUST be provided in getMethodArguments() override.
* @param argNames argument names.
*/
+ @SuppressWarnings("unused")
protected void interceptArgumentNames(Set<String> argNames) {
// do nothing by default
}
@@ -172,6 +173,7 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
* Derived classes can do additional result exchange processing, for example, adding custom headers.
* @param resultExchange result as a Camel exchange.
*/
+ @SuppressWarnings("unused")
protected void doProcessResult(Exchange resultExchange) {
// do nothing by default
}
@@ -190,7 +192,7 @@ public abstract class AbstractApiConsumer extends ScheduledPollConsumer {
* Return method arguments to use in doInvokeMethod().
* Derived classes can override it to add custom arguments.
* Overriding method MUST first call super.getMethodArguments() to get endpoint properties.
- * @return
+ * @return argument names mapped to argument values
*/
protected Map<String, Object> getMethodArguments() {
Map<String, Object> arguments = new HashMap<String, Object>();
http://git-wip-us.apache.org/repos/asf/camel/blob/f037c2da/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
index 6d09251..4217c4a 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiEndpoint.java
@@ -138,7 +138,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
/**
* Intercept initial endpoint arguments to add custom/hidden arguments for method calls, etc.
- * @param arguments
+ * @param arguments argument names
*/
@SuppressWarnings("unused")
protected void interceptEndpointArguments(Set<String> arguments) {
@@ -148,7 +148,7 @@ public abstract class AbstractApiEndpoint extends DefaultEndpoint {
/**
* Returns endpoint configuration object.
* One of the generated *EndpointConfiguration classes that extends component configuration class.
- * @return
+ * @return endpoint configuration object
*/
public abstract Object getConfiguration();
http://git-wip-us.apache.org/repos/asf/camel/blob/f037c2da/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
index 817c63b..a9795f2 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/AbstractApiProducer.java
@@ -134,6 +134,7 @@ public abstract class AbstractApiProducer extends DefaultAsyncProducer {
* Do additional result processing, for example, add custom headers, etc.
* @param resultExchange API method result as exchange.
*/
+ @SuppressWarnings("unused")
protected void doProcessResult(Exchange resultExchange) {
// do nothing by default
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f037c2da/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
index 3d0fce8..2231ceb 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
@@ -29,7 +29,15 @@ import java.util.Set;
public abstract class ApiCollection<T extends Enum & ApiName, C> {
protected final Map<T, ApiMethodHelper> apis = new HashMap<T, ApiMethodHelper>();
- protected final Map<Class<? extends ApiMethod>, T> apiMethods = new HashMap<Class<? extends ApiMethod>, T>();
+ protected final HashMap<Class<? extends ApiMethod>, T> apiMethods = new HashMap<Class<? extends ApiMethod>, T>();
+
+ public final Map<T, ApiMethodHelper> getApiHelpers() {
+ return Collections.unmodifiableMap(apis);
+ }
+
+ public final Map<Class<? extends ApiMethod>, T> getApiMethods() {
+ return Collections.unmodifiableMap(apiMethods);
+ }
/**
* Returns a {@link ApiMethodHelper} for a particular API.
http://git-wip-us.apache.org/repos/asf/camel/blob/f037c2da/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
index a698c1e..2561adc 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
@@ -273,6 +273,14 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
}
/**
+ * Returns alias map.
+ * @return alias names mapped to method names.
+ */
+ public Map<String, Set<String>> getAliases() {
+ return Collections.unmodifiableMap(ALIASES);
+ }
+
+ /**
* Get argument types and names used by all methods.
* @return map with argument names as keys, and types as values
*/
[3/6] git commit: Fixed ApiMethodHelper to throw
RuntimeCamelException with API exception on InvocationTargetException
Posted by dh...@apache.org.
Fixed ApiMethodHelper to throw RuntimeCamelException with API exception on InvocationTargetException
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5dd9cc0f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5dd9cc0f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5dd9cc0f
Branch: refs/heads/master
Commit: 5dd9cc0f0981603ea1ac8f0f6ee6dfcb7ad56a26
Parents: dee15fb
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Mon Jun 16 21:21:57 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 17 13:51:39 2014 -0700
----------------------------------------------------------------------
.../java/org/apache/camel/util/component/ApiMethodHelper.java | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5dd9cc0f/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
index 2561adc..7ce841b 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
@@ -17,6 +17,7 @@
package org.apache.camel.util.component;
import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -375,6 +376,11 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
try {
return method.getMethod().invoke(proxy, values);
} catch (Throwable e) {
+ if (e instanceof InvocationTargetException) {
+ // get API exception
+ final Throwable cause = e.getCause();
+ e = (cause != null) ? cause : e;
+ }
throw new RuntimeCamelException(
String.format("Error invoking %s with %s: %s", method.getName(), properties, e.getMessage()), e);
}