Repository: camel Updated Branches: refs/heads/master 34e441e00 -> a26eee003
Major refactor of camel-api-component-maven-plugin to simplify generated API pom.xml Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a26eee00 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a26eee00 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a26eee00 Branch: refs/heads/master Commit: a26eee003b4c5beac951bf5ef92099b7afb1c924 Parents: 34e441e Author: Dhiraj Bokde <dhira...@yahoo.com> Authored: Thu Jun 19 18:59:07 2014 -0700 Committer: Dhiraj Bokde <dhira...@yahoo.com> Committed: Thu Jun 19 18:59:07 2014 -0700 ---------------------------------------------------------------------- .../src/it/all-it/pom.xml | 48 +++++-- .../camel/maven/AbstractApiMethodBaseMojo.java | 58 +++++++++ .../maven/AbstractApiMethodGeneratorMojo.java | 19 ++- .../camel/maven/AbstractGeneratorMojo.java | 67 +++++++++- .../maven/AbstractSourceGeneratorMojo.java | 15 +++ .../camel/maven/ApiComponentGeneratorMojo.java | 129 +++++++++++++++++-- .../java/org/apache/camel/maven/ApiProxy.java | 68 ++++++++-- .../org/apache/camel/maven/FromJavadoc.java | 53 ++++++++ .../maven/ApiComponentGeneratorMojoTest.java | 25 +++- 9 files changed, 430 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 af0e4e8..daf7d64 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 @@ -44,19 +44,19 @@ <artifactId>velocity</artifactId> <version>@velocity-version@</version> </dependency> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> - <version>@project.version@</version> - <scope>test</scope> - </dependency> - <!-- VelocityEngine javadoc for testing --> + <!-- VelocityEngine javadoc for generating API classes --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>@velocity-version@</version> <classifier>javadoc</classifier> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <version>@project.version@</version> <scope>test</scope> </dependency> </dependencies> @@ -69,9 +69,10 @@ <artifactId>@project.artifactId@</artifactId> <version>@project.version@</version> <executions> + <!-- using generate-test-sources instead of generate-sources to be able to load TestProxy.class --> +<!-- <execution> <id>generate-file-api-method</id> - <!-- using generate-test-sources instead of generate-sources to be able to load TestProxy.class --> <phase>generate-test-sources</phase> <goals> <goal>fromFile</goal> @@ -116,6 +117,7 @@ <excludeMethods>clone|Current|internal|icache</excludeMethods> </configuration> </execution> +--> <execution> <id>generate-test-component-classes</id> <phase>generate-test-sources</phase> @@ -127,10 +129,38 @@ <api> <apiName>test</apiName> <proxyClass>org.apache.camel.component.test.TestProxy</proxyClass> + <substitutions> + <substitution> + <method>.+</method> + <argName>(.+)</argName> + <argType>java.util.List</argType> + <replacement>$1List</replacement> + </substitution> + <substitution> + <method>.+</method> + <argName>(.+)</argName> + <argType>.*?(\w++)\[\]</argType> + <replacement>$1Array</replacement> + <replaceWithType>true</replaceWithType> + </substitution> + </substitutions> + <fromSignatureFile>../../../src/test/resources/test-proxy-signatures.txt</fromSignatureFile> </api> <api> <apiName>velocity</apiName> <proxyClass>org.apache.velocity.VelocityContext</proxyClass> + <substitutions> + <substitution> + <method>.+</method> + <argName>key</argName> + <argType>java.lang.Object</argType> + <replacement>applicationKey</replacement> + </substitution> + </substitutions> + <fromJavadoc> + <excludeClasses>InternalContextBase</excludeClasses> + <excludeMethods>clone|Current|internal|icache</excludeMethods> + </fromJavadoc> <aliases> <alias> <methodPattern>get(.+)</methodPattern> http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java new file mode 100644 index 0000000..07b2bff --- /dev/null +++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodBaseMojo.java @@ -0,0 +1,58 @@ +/** + * 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 org.apache.maven.plugins.annotations.Parameter; + +/** + * Base class to share API method generator properties with @{link ApiComponentGeneratorMojo}. + */ +public abstract class AbstractApiMethodBaseMojo extends AbstractSourceGeneratorMojo { + + @Parameter(property = PREFIX + "substitutions") + protected Substitution[] substitutions = new Substitution[0]; + + @Parameter(property = PREFIX + "excludeConfigNames") + protected String excludeConfigNames; + + @Parameter(property = PREFIX + "excludeConfigTypes") + protected String excludeConfigTypes; + + public Substitution[] getSubstitutions() { + return substitutions; + } + + public void setSubstitutions(Substitution[] substitutions) { + this.substitutions = substitutions; + } + + public String getExcludeConfigNames() { + return excludeConfigNames; + } + + public void setExcludeConfigNames(String excludeConfigNames) { + this.excludeConfigNames = excludeConfigNames; + } + + public String getExcludeConfigTypes() { + return excludeConfigTypes; + } + + public void setExcludeConfigTypes(String excludeConfigTypes) { + this.excludeConfigTypes = excludeConfigTypes; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 82132ed..3cb3e8f 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,26 +34,25 @@ import org.apache.velocity.VelocityContext; /** * Base Mojo class for ApiMethod generators. */ -public abstract class AbstractApiMethodGeneratorMojo extends AbstractSourceGeneratorMojo { +public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBaseMojo { @Parameter(required = true, property = PREFIX + "proxyClass") protected String proxyClass; - @Parameter(property = PREFIX + "substitutions") - protected Substitution[] substitutions = new Substitution[0]; - - @Parameter(property = PREFIX + "excludeConfigNames") - protected String excludeConfigNames; - - @Parameter(property = PREFIX + "excludeConfigTypes") - protected String excludeConfigTypes; - // cached fields private Class<?> proxyType; private Pattern propertyNamePattern; private Pattern propertyTypePattern; + public String getProxyClass() { + return proxyClass; + } + + public void setProxyClass(String proxyClass) { + this.proxyClass = proxyClass; + } + @Override public void execute() throws MojoExecutionException, MojoFailureException { http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 26ebdaf..a308da0 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 @@ -66,19 +66,36 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo { protected String componentPackage; @Parameter(required = true, defaultValue = "${project}", readonly = true) - MavenProject project; + protected MavenProject project; - private VelocityEngine engine; - private ClassLoader projectClassLoader; + private static VelocityEngine engine; + private static ClassLoader projectClassLoader; - public VelocityEngine getEngine() { + private static boolean sharedProjectState; + + public static void setSharedProjectState(boolean sharedProjectState) { + AbstractGeneratorMojo.sharedProjectState = sharedProjectState; + } + + protected static void clearSharedProjectState() { + if (!sharedProjectState) { + projectClassLoader = null; + } + } + + protected AbstractGeneratorMojo() { + clearSharedProjectState(); + } + + protected static VelocityEngine getEngine() { if (engine == null) { // initialize velocity to load resources from class loader and use Log4J Properties velocityProperties = new Properties(); 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()); + final Logger velocityLogger = Logger.getLogger("org.apache.camel.maven.Velocity"); + velocityProperties.setProperty(Log4JLogChute.RUNTIME_LOG_LOG4J_LOGGER, velocityLogger.getName()); engine = new VelocityEngine(velocityProperties); engine.init(); } @@ -151,4 +168,44 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo { } return canonicalName; } + + public String getOutPackage() { + return outPackage; + } + + public void setOutPackage(String outPackage) { + this.outPackage = outPackage; + } + + public String getScheme() { + return scheme; + } + + public void setScheme(String scheme) { + this.scheme = scheme; + } + + public String getComponentName() { + return componentName; + } + + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + public String getComponentPackage() { + return componentPackage; + } + + public void setComponentPackage(String componentPackage) { + this.componentPackage = componentPackage; + } + + public MavenProject getProject() { + return project; + } + + public void setProject(MavenProject project) { + this.project = project; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 index 9c10c6c..cc0e85c 100644 --- 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 @@ -31,4 +31,19 @@ public abstract class AbstractSourceGeneratorMojo extends AbstractGeneratorMojo @Parameter(defaultValue = "${project.build.directory}/generated-test-sources/camel-component") protected File generatedTestDir; + public File getGeneratedSrcDir() { + return generatedSrcDir; + } + + public void setGeneratedSrcDir(File generatedSrcDir) { + this.generatedSrcDir = generatedSrcDir; + } + + public File getGeneratedTestDir() { + return generatedTestDir; + } + + public void setGeneratedTestDir(File generatedTestDir) { + this.generatedTestDir = generatedTestDir; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 2d49313..c924cdf 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 @@ -17,7 +17,6 @@ package org.apache.camel.maven; import java.io.File; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -34,11 +33,23 @@ import org.apache.velocity.VelocityContext; */ @Mojo(name = "fromApis", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresProject = true, defaultPhase = LifecyclePhase.GENERATE_SOURCES) -public class ApiComponentGeneratorMojo extends AbstractSourceGeneratorMojo { +public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo { + /** + * List of API names, proxies and code generation settings. + */ @Parameter(required = true) protected ApiProxy[] apis; + /** + * Common Javadoc code generation settings. + */ + @Parameter + protected FromJavadoc fromJavadoc = new FromJavadoc(); + + /** + * Method alias patterns for all APIs. + */ @Parameter private List<ApiMethodAlias> aliases = Collections.emptyList(); @@ -48,23 +59,115 @@ public class ApiComponentGeneratorMojo extends AbstractSourceGeneratorMojo { throw new MojoExecutionException("One or more API proxies are required"); } - // if set, merge common aliases with every API proxy's aliases - if (!aliases.isEmpty()) { + // starting with a new project + clearSharedProjectState(); + setSharedProjectState(true); + + try { + // generate API methods for each API proxy for (ApiProxy api : apis) { - List<ApiMethodAlias> apiAliases = api.getAliases(); - if (apiAliases.isEmpty()) { - apiAliases = new ArrayList<ApiMethodAlias>(); - apiAliases.addAll(aliases); + // validate API configuration + api.validate(); + + // create the appropriate code generator if signatureFile or fromJavaDoc are specified + // this way users can skip generating API classes for duplicate proxy class references + final AbstractApiMethodGeneratorMojo apiMethodGenerator = getApiMethodGenerator(api); + + if (apiMethodGenerator != null) { + // configure API method properties and generate Proxy classes + configureMethodGenerator(apiMethodGenerator, api); + apiMethodGenerator.execute(); + } else { + // make sure the proxy class is being generated elsewhere + final String proxyClass = api.getProxyClass(); + boolean found = false; + for (ApiProxy other : apis) { + if (other != api && proxyClass.equals(other.getProxyClass())) { + found = true; + break; + } + } + if (!found) { + throw new MojoExecutionException("Missing one of fromSignatureFile or fromJavadoc for " + + proxyClass); + } + } + + // if set, merge common aliases with proxy's aliases + if (!aliases.isEmpty()) { + final List<ApiMethodAlias> apiAliases = api.getAliases(); + if (apiAliases.isEmpty()) { + api.setAliases(aliases); + } else { + apiAliases.addAll(aliases); + } } - api.setAliases(apiAliases); } + + // generate ApiCollection + mergeTemplate(getApiContext(), getApiCollectionFile(), "/api-collection.vm"); + + // generate ApiName + mergeTemplate(getApiContext(), getApiNameFile(), "/api-name-enum.vm"); + + } finally { + // clear state for next Mojo + setSharedProjectState(false); + clearSharedProjectState(); } + } - // generate ApiCollection - mergeTemplate(getApiContext(), getApiCollectionFile(), "/api-collection.vm"); + private void configureMethodGenerator(AbstractApiMethodGeneratorMojo mojo, ApiProxy apiProxy) { + + // set AbstractGeneratorMojo properties + mojo.setComponentName(componentName); + mojo.setScheme(scheme); + mojo.setOutPackage(outPackage); + mojo.setComponentPackage(componentPackage); + mojo.setProject(project); + + // set AbstractSourceGeneratorMojo properties + mojo.setGeneratedSrcDir(generatedSrcDir); + mojo.setGeneratedTestDir(generatedTestDir); + + // set AbstractAPIMethodBaseMojo properties + mojo.setSubstitutions(apiProxy.getSubstitutions().length != 0 ? + apiProxy.getSubstitutions() : substitutions); + mojo.setExcludeConfigNames(apiProxy.getExcludeConfigNames() != null ? + apiProxy.getExcludeConfigNames() : excludeConfigNames); + mojo.setExcludeConfigTypes(apiProxy.getExcludeConfigTypes() != null ? + apiProxy.getExcludeConfigTypes() : excludeConfigTypes); + + // set AbstractAPIMethodGeneratorMojo properties + mojo.setProxyClass(apiProxy.getProxyClass()); + } + + private AbstractApiMethodGeneratorMojo getApiMethodGenerator(ApiProxy api) { + AbstractApiMethodGeneratorMojo apiMethodGenerator = null; + + final File signatureFile = api.getFromSignatureFile(); + if (signatureFile != null) { + + final FileApiMethodGeneratorMojo fileMojo = new FileApiMethodGeneratorMojo(); + fileMojo.signatureFile = signatureFile; + apiMethodGenerator = fileMojo; - // generate ApiName - mergeTemplate(getApiContext(), getApiNameFile(), "/api-name-enum.vm"); + } else { + + final FromJavadoc apiFromJavadoc = api.getFromJavadoc(); + if (apiFromJavadoc != null) { + final JavadocApiMethodGeneratorMojo javadocMojo = new JavadocApiMethodGeneratorMojo(); + javadocMojo.excludePackages = apiFromJavadoc.getExcludePackages() != null ? + apiFromJavadoc.getExcludePackages() : fromJavadoc.getExcludePackages(); + javadocMojo.excludeClasses = apiFromJavadoc.getExcludeClasses() != null ? + apiFromJavadoc.getExcludeClasses() : fromJavadoc.getExcludeClasses(); + javadocMojo.excludeMethods = apiFromJavadoc.getExcludeMethods() != null ? + apiFromJavadoc.getExcludeMethods() : fromJavadoc.getExcludeMethods(); + + apiMethodGenerator = javadocMojo; + } + } + return apiMethodGenerator; } private VelocityContext getApiContext() { http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 22c3870..1036ecf 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 @@ -16,31 +16,33 @@ */ package org.apache.camel.maven; +import java.io.File; import java.util.Collections; import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; + /** * 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.emptyList(); + private File fromSignatureFile; - public ApiProxy() { - } + private FromJavadoc fromJavadoc; - public ApiProxy(String apiName, String proxyClass) { - this.apiName = apiName; - this.proxyClass = proxyClass; - } + private Substitution[] substitutions = new Substitution[0]; - public ApiProxy(String apiName, String proxyClass, List<ApiMethodAlias> aliases) { - this(apiName, proxyClass); - this.aliases = aliases; - } + private String excludeConfigNames; + + private String excludeConfigTypes; + + private List<ApiMethodAlias> aliases = Collections.emptyList(); public String getApiName() { return apiName; @@ -58,6 +60,46 @@ public class ApiProxy { this.proxyClass = proxyClass; } + public File getFromSignatureFile() { + return fromSignatureFile; + } + + public void setFromSignatureFile(File fromSignatureFile) { + this.fromSignatureFile = fromSignatureFile; + } + + public FromJavadoc getFromJavadoc() { + return fromJavadoc; + } + + public void setFromJavadoc(FromJavadoc fromJavadoc) { + this.fromJavadoc = fromJavadoc; + } + + public Substitution[] getSubstitutions() { + return substitutions; + } + + public void setSubstitutions(Substitution[] substitutions) { + this.substitutions = substitutions; + } + + public String getExcludeConfigNames() { + return excludeConfigNames; + } + + public void setExcludeConfigNames(String excludeConfigNames) { + this.excludeConfigNames = excludeConfigNames; + } + + public String getExcludeConfigTypes() { + return excludeConfigTypes; + } + + public void setExcludeConfigTypes(String excludeConfigTypes) { + this.excludeConfigTypes = excludeConfigTypes; + } + public List<ApiMethodAlias> getAliases() { return aliases; } @@ -66,9 +108,9 @@ public class ApiProxy { this.aliases = aliases; } - public void validate() { + public void validate() throws MojoExecutionException { if (apiName == null || proxyClass == null) { - throw new IllegalArgumentException("Properties apiName and proxyClass are required"); + throw new MojoExecutionException("Properties apiName and proxyClass are required"); } } } http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavadoc.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavadoc.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavadoc.java new file mode 100644 index 0000000..fb2ce5f --- /dev/null +++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/FromJavadoc.java @@ -0,0 +1,53 @@ +/** + * 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; + +/** + * Javadoc API generator properties. + */ +public class FromJavadoc { + + protected String excludePackages = JavadocApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES; + + protected String excludeClasses; + + protected String excludeMethods; + + public String getExcludePackages() { + return excludePackages; + } + + public void setExcludePackages(String excludePackages) { + this.excludePackages = excludePackages; + } + + public String getExcludeClasses() { + return excludeClasses; + } + + public void setExcludeClasses(String excludeClasses) { + this.excludeClasses = excludeClasses; + } + + public String getExcludeMethods() { + return excludeMethods; + } + + public void setExcludeMethods(String excludeMethods) { + this.excludeMethods = excludeMethods; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a26eee00/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 05e989d..a7ac4a5 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 @@ -41,11 +41,32 @@ public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest { configureSourceGeneratorMojo(mojo); mojo.apis = new ApiProxy[2]; - mojo.apis[0] = new ApiProxy("test", TestProxy.class.getName()); + mojo.apis[0] = new ApiProxy(); + mojo.apis[0].setApiName("test"); + mojo.apis[0].setProxyClass(TestProxy.class.getName()); + mojo.apis[0].setFromSignatureFile(new File("src/test/resources/test-proxy-signatures.txt")); + Substitution[] substitutions = new Substitution[2]; + substitutions[0] = new Substitution(".+", "(.+)", "java.util.List", "$1List", false); + substitutions[1] = new Substitution(".+", "(.+)", ".*?(\\w++)\\[\\]", "$1Array", true); + mojo.apis[0].setSubstitutions(substitutions); + // exclude name2, and int times + mojo.apis[0].setExcludeConfigNames("name2"); + mojo.apis[0].setExcludeConfigTypes("int"); + + List<ApiMethodAlias> aliases = new ArrayList<ApiMethodAlias>(); aliases.add(new ApiMethodAlias("get(.+)", "$1")); aliases.add(new ApiMethodAlias("set(.+)", "$1")); - mojo.apis[1] = new ApiProxy("velocity", VelocityContext.class.getName(), aliases); + mojo.apis[1] = new ApiProxy(); + mojo.apis[1].setApiName("velocity"); + mojo.apis[1].setProxyClass(VelocityContext.class.getName()); + mojo.apis[1].setAliases(aliases); + Substitution substitution = new Substitution(".*", "key", "java.lang.Object", "applicationKey", false); + mojo.apis[1].setSubstitutions(new Substitution[]{ substitution }); + final FromJavadoc fromJavadoc = new FromJavadoc(); + fromJavadoc.setExcludePackages(JavadocApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES); + fromJavadoc.setExcludeMethods("clone|Current|internal|icache"); + mojo.apis[1].setFromJavadoc(fromJavadoc); mojo.execute();