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/10 21:52:01 UTC
[33/35] Renamed component-util plugin to api-component
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
new file mode 100644
index 0000000..a3acad1
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
@@ -0,0 +1,109 @@
+## ------------------------------------------------------------------------
+## 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-route-test.vm
+/*
+ * Camel Api Route test generated by camel-component-util-maven-plugin
+ * Generated on: $generatedDate
+ */
+package $packageName;
+
+import java.util.HashMap;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for $proxyType.Name APIs.
+ * TODO Move the file to src/test/java, populate parameter values, and remove @Ignore annotations.
+ * The class source won't be generated again if the generator MOJO finds it under src/test/java.
+ */
+public class ${testName} extends CamelTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(${testName}.class);
+ private static final String PATH_PREFIX = ${componentName}ApiCollection.getCollection().getApiName(${enumName}.class).getName();
+
+#foreach ( $model in $models )
+#set ( $testName = $helper.getTestName($model) )
+#set ( $args = $model.Arguments )
+#set ( $resultType = $model.ResultType )
+#set ( $voidResult = $helper.isVoidType($resultType) )
+## are parameter values needed
+#if ( !$args.isEmpty() )
+ // TODO provide parameter values for $model.Name
+#end
+ @Ignore
+ @Test
+ public void test${testName}() throws Exception {
+## single argument, use as body
+#if ( $args.size() == 1 )
+#set ( $argType = $args.get(0).Type )
+ // using $helper.getCanonicalName($argType) message body for single parameter "$args.get(0).Name"
+## multiple arguments, pass them as headers
+#elseif ( $args.size() > 1 )
+ final HashMap<String, Object> headers = new HashMap<String, Object>();
+#foreach ( $arg in $args )
+#if ( !$arg.Type.isPrimitive() )
+ // parameter type is $helper.getCanonicalName($arg.Type)
+ headers.put("${helper.getExchangePropertyPrefix()}${arg.Name}", null);
+#else
+ headers.put("${helper.getExchangePropertyPrefix()}${arg.Name}", $helper.getDefaultArgValue($arg.Type));
+#end
+#end
+#end
+## method invocation result
+ #if ( !$voidResult )#set ( $type = $helper.getResultDeclaration($resultType) )$type result = (${type})#end
+## actual template call
+#if ( $args.isEmpty() )
+template().requestBody("direct://${model.UniqueName}", (Object)null);
+#elseif ( $args.size() == 1 )
+## typecast body to avoid requestBody() conflict
+template().requestBody("direct://${model.UniqueName}", (${helper.getCanonicalName($argType)}) $helper.getDefaultArgValue($argType));
+#else
+template().requestBodyAndHeader("direct://${model.UniqueName}", null, headers);
+#end
+#if ( !$voidResult )
+
+ LOG.debug("${model.Name} :" + result);
+#end
+ }
+
+#end
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+#foreach ( $model in $models )
+#set ( $args = $model.Arguments )
+ // test route for $model.Name
+ from("direct://${model.UniqueName}")
+ .to("${scheme}://" + PATH_PREFIX + "/${model.Name}#if ( $args.size() == 1 )?inBody=${args.get(0).Name}#end");
+
+#end
+ }
+ };
+ }
+
+ @Override
+ public boolean isCreateCamelContextPerClass() {
+ // only create the context once for this class
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/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
new file mode 100644
index 0000000..3d544fc
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/log4j.properties
@@ -0,0 +1,36 @@
+#
+# 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/0c9fbb62/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
new file mode 100644
index 0000000..de22f82
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
@@ -0,0 +1,23 @@
+/**
+ * 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.component.test;
+
+/**
+ * Dummy component configuration.
+ */
+public class TestConfiguration {
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
new file mode 100644
index 0000000..48eb11b
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/TestProxy.java
@@ -0,0 +1,68 @@
+/**
+ * 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.component.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestProxy {
+ public String sayHi() {
+ return "Hello!";
+ }
+
+ public String sayHi(boolean hello) {
+ return hello ? "Hello!" : "Hi!";
+ }
+
+ public String sayHi(final String name) {
+ return "Hello " + name;
+ }
+
+ public final String greetMe(final String name) {
+ return "Greetings " + name;
+ }
+
+ public final String greetUs(final String name1, String name2) {
+ return "Greetings " + name1 + ", " + name2;
+ }
+
+ public final String greetAll(final String[] names) {
+ StringBuilder builder = new StringBuilder("Greetings ");
+ for (String name : names) {
+ builder.append(name).append(", ");
+ }
+ builder.delete(builder.length() - 2, builder.length());
+ return builder.toString();
+ }
+
+ public final String greetAll(List<String> names) {
+ StringBuilder builder = new StringBuilder("Greetings ");
+ for (String name : names) {
+ builder.append(name).append(", ");
+ }
+ builder.delete(builder.length() - 2, builder.length());
+ return builder.toString();
+ }
+
+ public final String[] greetTimes(String name, int times) {
+ final List<String> result = new ArrayList<String>();
+ for (int i = 0; i < times; i++) {
+ result.add("Greetings " + name);
+ }
+ return result.toArray(new String[result.size()]);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/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
new file mode 100644
index 0000000..641b34e
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/AbstractGeneratorMojoTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.project.MavenProject;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Base class for Generator MOJO tests.
+ */
+public class AbstractGeneratorMojoTest {
+ protected static final String OUT_DIR = "target/generated-test-sources/camel-component";
+
+ private static final String COMPONENT_PACKAGE = "org.apache.camel.component.test";
+ private static final String OUT_PACKAGE = COMPONENT_PACKAGE + ".internal";
+
+ protected static final String PACKAGE_PATH = OUT_PACKAGE.replaceAll("\\.", "/") + "/";
+ protected static final String COMPONENT_PACKAGE_PATH = COMPONENT_PACKAGE.replaceAll("\\.", "/") + "/";
+
+ protected static final String COMPONENT_NAME = "Test";
+ protected static final String SCHEME = "testComponent";
+
+ protected void assertExists(File outFile) {
+ assertTrue("Generated file not found " + outFile.getPath(), outFile.exists());
+ }
+
+ protected void configureMojo(AbstractGeneratorMojo mojo) {
+ mojo.componentName = COMPONENT_NAME;
+ mojo.scheme = SCHEME;
+ mojo.generatedSrcDir = new File(OUT_DIR);
+ mojo.generatedTestDir = new File(OUT_DIR);
+ mojo.outPackage = OUT_PACKAGE;
+ mojo.componentPackage = COMPONENT_PACKAGE;
+ mojo.project = new MavenProject((Model) null) {
+ @Override
+ public List getTestClasspathElements() throws DependencyResolutionRequiredException {
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public Build getBuild() {
+ return new Build() {
+ @Override
+ public String getTestSourceDirectory() {
+ return OUT_DIR;
+ }
+ };
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/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
new file mode 100644
index 0000000..3e9400c
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/ApiComponentGeneratorMojoTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.component.test.TestProxy;
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+
+/**
+ * Tests {@link ApiComponentGeneratorMojo}
+ */
+public class ApiComponentGeneratorMojoTest extends AbstractGeneratorMojoTest {
+
+ @Test
+ public void testExecute() throws Exception {
+
+ final File collectionFile = new File(OUT_DIR, PACKAGE_PATH + COMPONENT_NAME + "ApiCollection.java");
+
+ // delete target files to begin
+ collectionFile.delete();
+
+ final ApiComponentGeneratorMojo mojo = new ApiComponentGeneratorMojo();
+ configureMojo(mojo);
+
+ mojo.apis = new ApiProxy[2];
+ mojo.apis[0] = new ApiProxy("test", TestProxy.class.getName());
+ 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.execute();
+
+ // check target file was generated
+ assertExists(collectionFile);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/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
new file mode 100644
index 0000000..d77bad7
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/FileApiMethodGeneratorMojoTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.io.IOException;
+
+import org.apache.camel.component.test.TestProxy;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests {@link FileApiMethodGeneratorMojo}
+ */
+public class FileApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest {
+
+ @Test
+ public void testExecute() throws IOException, MojoFailureException, MojoExecutionException {
+
+ // delete target file to begin
+ final File outFile = new File(OUT_DIR, PACKAGE_PATH + "TestProxyApiMethod.java");
+ if (outFile.exists()) {
+ outFile.delete();
+ }
+
+ final FileApiMethodGeneratorMojo mojo = new FileApiMethodGeneratorMojo();
+ mojo.substitutions = new Substitution[2];
+ mojo.substitutions[0] = new Substitution(".+", "(.+)", "java.util.List", "$1List", false);
+ mojo.substitutions[1] = new Substitution(".+", "(.+)", ".*?(\\w++)\\[\\]", "$1Array", true);
+
+ configureMojo(mojo);
+ mojo.proxyClass = TestProxy.class.getCanonicalName();
+ mojo.signatureFile = new File("src/test/resources/test-proxy-signatures.txt");
+
+ mojo.execute();
+
+ // check target file was generated
+ assertTrue("Generated file not found " + outFile.getPath(), outFile.exists());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/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
new file mode 100644
index 0000000..ded66dd
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojoTest.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 java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+
+/**
+ * Tests {@link JavadocApiMethodGeneratorMojo}
+ */
+public class JavadocApiMethodGeneratorMojoTest extends AbstractGeneratorMojoTest {
+
+ @Test
+ public void testExecute() throws IOException, MojoFailureException, MojoExecutionException {
+
+ // delete target file to begin
+ final File outFile = new File(OUT_DIR, PACKAGE_PATH + "VelocityContextApiMethod.java");
+ if (outFile.exists()) {
+ outFile.delete();
+ }
+
+ final JavadocApiMethodGeneratorMojo mojo = new JavadocApiMethodGeneratorMojo();
+
+ configureMojo(mojo);
+
+ // use VelocityEngine javadoc
+ mojo.proxyClass = VelocityContext.class.getCanonicalName();
+ Substitution substitution = new Substitution(".*", "key", "java.lang.Object", "applicationKey", false);
+ mojo.substitutions = new Substitution[]{ substitution };
+ mojo.excludePackages = JavadocApiMethodGeneratorMojo.DEFAULT_EXCLUDE_PACKAGES;
+ mojo.excludeMethods = "clone|Current|internal|icache";
+
+ mojo.execute();
+
+ // check target file was generated
+ assertExists(outFile);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
new file mode 100644
index 0000000..4c47474
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/resources/test-proxy-signatures.txt
@@ -0,0 +1,8 @@
+public String sayHi();
+public String sayHi(boolean hello);
+public String sayHi(final String name);
+public final String greetMe(final String name);
+public final String greetUs(final String name1, String name2);
+public final String greetAll(String[] names);
+public final String greetAll(java.util.List<String> names);
+public final String[] greetTimes(String name, int times);
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/pom.xml b/tooling/maven/camel-component-util-maven-plugin/pom.xml
deleted file mode 100644
index ed197ac..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/pom.xml
+++ /dev/null
@@ -1,225 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>maven-plugins</artifactId>
- <version>2.14-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-component-util-maven-plugin</artifactId>
- <packaging>maven-plugin</packaging>
- <name>Camel :: Maven Plugins :: Camel Component Utilities</name>
- <description>Maven plugin to generate Camel Components for APIs</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-annotations</artifactId>
- <version>3.3</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-descriptor</artifactId>
- <version>2.2.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact</artifactId>
- <version>2.2.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>${velocity-version}</version>
- </dependency>
-
- <!-- add some logging to the classpath -->
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- VelocityEngine javadoc for testing -->
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>${velocity-version}</version>
- <classifier>javadoc</classifier>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugin-plugin</artifactId>
- <version>3.3</version>
- <configuration>
- <!-- see http://jira.codehaus.org/browse/MNG-5346 -->
- <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
- </configuration>
- <executions>
- <execution>
- <id>mojo-descriptor</id>
- <goals>
- <goal>descriptor</goal>
- </goals>
- </execution>
- <execution>
- <id>help-goal</id>
- <goals>
- <goal>helpmojo</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <!-- copy test utility classes to integration test project -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-it-resources</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <encoding>UTF-8</encoding>
- <overwrite>true</overwrite>
- <outputDirectory>${project.build.directory}/it/all-it/src/main/java/org/apache/camel/component/test</outputDirectory>
- <resources>
- <resource>
- <directory>src/test/java/org/apache/camel/component/test</directory>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <!-- validate generated code after unit tests -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>add-generated-test-sources</id>
- <phase>verify</phase>
- <goals>
- <goal>add-test-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${project.build.directory}/generated-test-sources/camel-component</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <executions>
- <execution>
- <id>validate-generated-test-sources</id>
- <phase>verify</phase>
- <goals>
- <goal>testCompile</goal>
- </goals>
- <configuration>
- <fork>false</fork>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <!-- Plugin integration test profile -->
- <profiles>
- <profile>
- <id>plugin-itest</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-invoker-plugin</artifactId>
- <version>1.8</version>
- <configuration>
- <debug>true</debug>
- <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
- <pomIncludes>
- <pomInclude>*/pom.xml</pomInclude>
- </pomIncludes>
- <postBuildHookScript>verify</postBuildHookScript>
- <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
- <settingsFile>src/it/settings.xml</settingsFile>
- <goals>
- <goal>clean</goal>
- <goal>verify</goal>
- </goals>
- </configuration>
- <executions>
- <execution>
- <id>integration-test</id>
- <goals>
- <goal>install</goal>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
-
- </build>
- </profile>
- </profiles>
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/pom.xml b/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/pom.xml
deleted file mode 100644
index d13ef72..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/pom.xml
+++ /dev/null
@@ -1,185 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-component-util-maven-plugin-it</artifactId>
- <version>1.0-SNAPSHOT</version>
-
- <description>Integration Test to verify all goals.</description>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <outPackage>org.apache.camel.component.test.internal</outPackage>
- <componentPackage>org.apache.camel.component.test</componentPackage>
- <scheme>testComponent</scheme>
- <componentName>Test</componentName>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- <version>@project.version@</version>
- </dependency>
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <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 -->
- <dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>@velocity-version@</version>
- <classifier>javadoc</classifier>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <!-- execute component-util plugin -->
- <plugin>
- <groupId>@project.groupId@</groupId>
- <artifactId>@project.artifactId@</artifactId>
- <version>@project.version@</version>
- <executions>
- <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>
- </goals>
- <configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${scheme}</scheme>
- <componentName>${componentName}</componentName>
- <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>
- <signatureFile>../../../src/test/resources/test-proxy-signatures.txt</signatureFile>
- </configuration>
- </execution>
- <execution>
- <id>generate-velocity-context-api-method</id>
- <phase>generate-test-sources</phase>
- <goals>
- <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>
- <method>.+</method>
- <argName>key</argName>
- <argType>java.lang.Object</argType>
- <replacement>applicationKey</replacement>
- </substitution>
- </substitutions>
- <excludeClasses>InternalContextBase</excludeClasses>
- <excludeMethods>clone|Current|internal|icache</excludeMethods>
- </configuration>
- </execution>
- <execution>
- <id>generate-test-component-classes</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>fromApis</goal>
- </goals>
- <configuration>
- <outPackage>${outPackage}</outPackage>
- <componentPackage>${componentPackage}</componentPackage>
- <scheme>${scheme}</scheme>
- <componentName>${componentName}</componentName>
- <apis>
- <api>
- <apiName>test</apiName>
- <proxyClass>org.apache.camel.component.test.TestProxy</proxyClass>
- </api>
- <api>
- <apiName>velocity</apiName>
- <proxyClass>org.apache.velocity.VelocityContext</proxyClass>
- <aliases>
- <alias>
- <methodPattern>get(.+)</methodPattern>
- <methodAlias>$1</methodAlias>
- </alias>
- <alias>
- <methodPattern>set(.+)</methodPattern>
- <methodAlias>$1</methodAlias>
- </alias>
- </aliases>
- </api>
- </apis>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <!-- add generated source and test source to build for test-compile -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>@build-helper-maven-plugin-version@</version>
- <executions>
- <execution>
- <id>add-generated-test-sources</id>
- <goals>
- <goal>add-test-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${project.build.directory}/generated-sources/camel-component</source>
- <source>${project.build.directory}/generated-test-sources/camel-component</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/verify.groovy
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/verify.groovy b/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/verify.groovy
deleted file mode 100644
index 73edefd..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/it/all-it/verify.groovy
+++ /dev/null
@@ -1,22 +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.
- */
-// assert that the generated files directory exists
-File sourceDir = new File( basedir, "target/generated-sources/camel-component" );
-File testDir = new File( basedir, "target/generated-test-sources/camel-component" );
-
-assert sourceDir.isDirectory()
-assert testDir.isDirectory()
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/it/settings.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/it/settings.xml b/tooling/maven/camel-component-util-maven-plugin/src/it/settings.xml
deleted file mode 100644
index c8f77f0..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/it/settings.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-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.
--->
-
-<settings>
- <profiles>
- <profile>
- <id>it-repo</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <repositories>
- <repository>
- <id>local.central</id>
- <url>@localRepositoryUrl@</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>local.central</id>
- <url>@localRepositoryUrl@</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
-</settings>
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
deleted file mode 100644
index 852b09e..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ /dev/null
@@ -1,265 +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 org.apache.camel.maven;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.apache.camel.util.component.ApiMethodParser;
-import org.apache.camel.util.component.ArgumentSubstitutionParser;
-import org.apache.commons.lang.ClassUtils;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.velocity.VelocityContext;
-
-/**
- * Base Mojo class for ApiMethod generators.
- */
-public abstract class AbstractApiMethodGeneratorMojo extends AbstractGeneratorMojo {
-
- @Parameter(required = true, property = PREFIX + "proxyClass")
- protected String proxyClass;
-
- @Parameter(property = PREFIX + "substitutions")
- protected Substitution[] substitutions = new Substitution[0];
-
- // cached fields
- private Class<?> proxyType;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- // load proxy class and get enumeration file to generate
- final Class proxyType = getProxyType();
-
- // create parser
- ApiMethodParser parser = createAdapterParser(proxyType);
- parser.setSignatures(getSignatureList());
- parser.setClassLoader(getProjectClassLoader());
-
- // parse signatures
- final List<ApiMethodParser.ApiMethodModel> models = parser.parse();
-
- // generate enumeration from model
- mergeTemplate(getApiMethodContext(models), getApiMethodFile(), "/api-method-enum.vm");
-
- // generate EndpointConfiguration for this Api
- mergeTemplate(getEndpointContext(models), getConfigurationFile(), "/api-endpoint-config.vm");
-
- // generate junit test if it doesn't already exist under test source directory
- // i.e. it may have been generated then moved there and populated with test values
- final String testFilePath = getTestFilePath();
- if (!new File(project.getBuild().getTestSourceDirectory(), testFilePath).exists()) {
- mergeTemplate(getApiTestContext(models), new File(generatedTestDir, testFilePath), "/api-route-test.vm");
- }
- }
-
- protected ApiMethodParser createAdapterParser(Class proxyType) {
- return new ArgumentSubstitutionParser(proxyType, getArgumentSubstitutions()){};
- }
-
- public abstract List<String> getSignatureList() throws MojoExecutionException;
-
- public Class getProxyType() throws MojoExecutionException {
- if (proxyType == null) {
- // load proxy class from Project runtime dependencies
- try {
- proxyType = getProjectClassLoader().loadClass(proxyClass);
- } catch (ClassNotFoundException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- }
- return proxyType;
- }
-
- private VelocityContext getApiMethodContext(List<ApiMethodParser.ApiMethodModel> models) throws MojoExecutionException {
- VelocityContext context = getCommonContext(models);
- context.put("enumName", getEnumName());
- return context;
- }
-
- public File getApiMethodFile() throws MojoExecutionException {
- final StringBuilder fileName = new StringBuilder();
- fileName.append(outPackage.replaceAll("\\.", File.separator)).append(File.separator);
- fileName.append(getEnumName()).append(".java");
- return new File(generatedSrcDir, fileName.toString());
- }
-
- private String getEnumName() throws MojoExecutionException {
- return getProxyType().getSimpleName() + "ApiMethod";
- }
-
- private VelocityContext getApiTestContext(List<ApiMethodParser.ApiMethodModel> models) throws MojoExecutionException {
- VelocityContext context = getCommonContext(models);
- context.put("testName", getUnitTestName());
- context.put("scheme", scheme);
- context.put("componentName", componentName);
- context.put("enumName", getEnumName());
- return context;
- }
-
- private String getTestFilePath() throws MojoExecutionException {
- final StringBuilder fileName = new StringBuilder();
- fileName.append(outPackage.replaceAll("\\.", File.separator)).append(File.separator);
- fileName.append(getUnitTestName()).append(".java");
- return fileName.toString();
- }
-
- private String getUnitTestName() throws MojoExecutionException {
- return getProxyType().getSimpleName() + "IntegrationTest";
- }
-
- private VelocityContext getEndpointContext(List<ApiMethodParser.ApiMethodModel> models) throws MojoExecutionException {
- VelocityContext context = getCommonContext(models);
- context.put("configName", getConfigName());
- context.put("componentName", componentName);
- context.put("componentPackage", componentPackage);
-
- // generate parameter names and types for configuration, sorted by parameter name
- Map<String, Class<?>> parameters = new TreeMap<String, Class<?>>();
- for (ApiMethodParser.ApiMethodModel model : models) {
- for (ApiMethodParser.Argument argument : model.getArguments()) {
- if (!parameters.containsKey(argument.getName())) {
- Class<?> type = argument.getType();
- if (type.isPrimitive()) {
- // replace primitives with wrapper classes
- type = ClassUtils.primitiveToWrapper(type);
- }
- parameters.put(argument.getName(), type);
- }
- }
- }
- context.put("parameters", parameters);
- return context;
- }
-
- private File getConfigurationFile() throws MojoExecutionException {
- final StringBuilder fileName = new StringBuilder();
- // endpoint configuration goes in component package
- fileName.append(componentPackage.replaceAll("\\.", File.separator)).append(File.separator);
- fileName.append(getConfigName()).append(".java");
- return new File(generatedSrcDir, fileName.toString());
- }
-
- private String getConfigName() throws MojoExecutionException {
- return getProxyType().getSimpleName() + "EndpointConfiguration";
- }
-
- private VelocityContext getCommonContext(List<ApiMethodParser.ApiMethodModel> models) throws MojoExecutionException {
- VelocityContext context = new VelocityContext();
- context.put("models", models);
- context.put("proxyType", getProxyType());
- context.put("helper", this);
- return context;
- }
-
- public ArgumentSubstitutionParser.Substitution[] getArgumentSubstitutions() {
- ArgumentSubstitutionParser.Substitution[] subs = new ArgumentSubstitutionParser.Substitution[substitutions.length];
- for (int i = 0; i < substitutions.length; i++) {
- final Substitution substitution = substitutions[i];
- subs[i] = new ArgumentSubstitutionParser.Substitution(substitution.getMethod(),
- substitution.getArgName(), substitution.getArgType(),
- substitution.getReplacement(), substitution.isReplaceWithType());
- }
- return subs;
- }
-
- public static String getType(Class<?> clazz) {
- if (clazz.isArray()) {
- // create a zero length array and get the class from the instance
- return "new " + getCanonicalName(clazz).replaceAll("\\[\\]", "[0]") + ".getClass()";
- } else {
- return getCanonicalName(clazz) + ".class";
- }
- }
-
- public static String getTestName(ApiMethodParser.ApiMethodModel model) {
- final StringBuilder builder = new StringBuilder();
- final String name = model.getMethod().getName();
- builder.append(Character.toUpperCase(name.charAt(0)));
- builder.append(name.substring(1));
- // find overloaded method suffix from unique name
- final String uniqueName = model.getUniqueName();
- if (uniqueName.length() > name.length()) {
- builder.append(uniqueName.substring(name.length()));
- }
- return builder.toString();
- }
-
- public static boolean isVoidType(Class<?> resultType) {
- return resultType == Void.TYPE;
- }
-
- public String getExchangePropertyPrefix() {
- // exchange property prefix
- return "Camel" + componentName + ".";
- }
-
- public static String getResultDeclaration(Class<?> resultType) {
- if (resultType.isPrimitive()) {
- return ClassUtils.primitiveToWrapper(resultType).getSimpleName();
- } else {
- return getCanonicalName(resultType);
- }
- }
-
- private static final Map<Class<?>, String> PRIMITIVE_VALUES;
-
- static {
- PRIMITIVE_VALUES = new HashMap<Class<?>, String>();
- PRIMITIVE_VALUES.put(Boolean.TYPE, "Boolean.FALSE");
- PRIMITIVE_VALUES.put(Byte.TYPE, "(byte) 0");
- PRIMITIVE_VALUES.put(Character.TYPE, "(char) 0");
- PRIMITIVE_VALUES.put(Short.TYPE, "(short) 0");
- PRIMITIVE_VALUES.put(Integer.TYPE, "0");
- PRIMITIVE_VALUES.put(Long.TYPE, "0L");
- PRIMITIVE_VALUES.put(Float.TYPE, "0.0f");
- PRIMITIVE_VALUES.put(Double.TYPE, "0.0d");
- }
-
- public static String getDefaultArgValue(Class<?> aClass) {
- if (aClass.isPrimitive()) {
- // lookup default primitive value string
- return PRIMITIVE_VALUES.get(aClass);
- } else {
- // return type cast null string
- return "null";
- }
- }
-
- public static String getBeanPropertySuffix(String parameter) {
- // capitalize first character
- StringBuilder builder = new StringBuilder();
- builder.append(Character.toUpperCase(parameter.charAt(0)));
- builder.append(parameter.substring(1));
- 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/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
deleted file mode 100644
index faf0964..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractGeneratorMojo.java
+++ /dev/null
@@ -1,167 +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 org.apache.camel.maven;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Date;
-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;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.VelocityException;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.log.Log4JLogChute;
-import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-
-/**
- * Base class for Api based code 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;
-
- @Parameter(defaultValue = OUT_PACKAGE)
- protected String outPackage;
-
- @Parameter(required = true, property = PREFIX + "scheme")
- protected String scheme;
-
- @Parameter(required = true, property = PREFIX + "componentName")
- protected String componentName;
-
- @Parameter(defaultValue = COMPONENT_PACKAGE)
- protected String componentPackage;
-
- @Parameter(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 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());
- engine = new VelocityEngine(velocityProperties);
- engine.init();
- }
- return engine;
- }
-
- protected ClassLoader getProjectClassLoader() throws MojoExecutionException {
- if (projectClassLoader == null) {
- final List classpathElements;
- try {
- classpathElements = project.getTestClasspathElements();
- } catch (org.apache.maven.artifact.DependencyResolutionRequiredException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- final URL[] urls = new URL[classpathElements.size()];
- int i = 0;
- 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]);
- } catch (MalformedURLException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- }
- final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- projectClassLoader = new URLClassLoader(urls, tccl != null ? tccl : getClass().getClassLoader());
- }
- return projectClassLoader;
- }
-
- protected void mergeTemplate(VelocityContext context, File outFile, String templateName) throws MojoExecutionException {
- // ensure parent directories exist
- outFile.getParentFile().mkdirs();
-
- // add generated date
- context.put("generatedDate", new Date().toString());
- // add output package
- context.put("packageName", outPackage);
-
- // load velocity template
- final Template template = getEngine().getTemplate(templateName, "UTF-8");
-
- // generate file
- BufferedWriter writer = null;
- try {
- writer = new BufferedWriter(new FileWriter(outFile));
- template.merge(context, writer);
- } catch (IOException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- } catch (VelocityException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException ignore) {}
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
deleted file mode 100644
index 28d5e3b..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
+++ /dev/null
@@ -1,115 +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 org.apache.camel.maven;
-
-import java.io.File;
-
-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.velocity.VelocityContext;
-
-/**
- * Generates Camel Component based on a collection of APIs.
- */
-@Mojo(name = "fromApis", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresProject = true,
- defaultPhase = LifecyclePhase.GENERATE_SOURCES)
-public class ApiComponentGeneratorMojo extends AbstractGeneratorMojo {
-
- @Parameter(required = true)
- protected ApiProxy[] apis;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- if (apis == null || apis.length == 0) {
- throw new MojoExecutionException("One or more API proxies are required");
- }
-
- // generate ApiCollection
- mergeTemplate(getApiContext(), getApiCollectionFile(), "/api-collection.vm");
-
- // generate ApiName
- mergeTemplate(getApiContext(), getApiNameFile(), "/api-name-enum.vm");
- }
-
- private VelocityContext getApiContext() {
- final VelocityContext context = new VelocityContext();
- context.put("componentName", componentName);
- context.put("componentPackage", componentPackage);
- context.put("apis", apis);
- context.put("helper", getClass());
- context.put("collectionName", getApiCollectionName());
- context.put("apiNameEnum", getApiNameEnum());
- return context;
- }
-
- private String getApiCollectionName() {
- return componentName + "ApiCollection";
- }
-
- private String getApiNameEnum() {
- return componentName + "ApiName";
- }
-
- private File getApiCollectionFile() {
- final StringBuilder fileName = getFileBuilder();
- fileName.append(getApiCollectionName()).append(".java");
- return new File(generatedSrcDir, fileName.toString());
- }
-
- private File getApiNameFile() {
- final StringBuilder fileName = getFileBuilder();
- fileName.append(getApiNameEnum()).append(".java");
- return new File(generatedSrcDir, fileName.toString());
- }
-
- private StringBuilder getFileBuilder() {
- final StringBuilder fileName = new StringBuilder();
- fileName.append(outPackage.replaceAll("\\.", File.separator)).append(File.separator);
- return fileName;
- }
-
- public static String getApiMethod(String proxyClass) {
- return proxyClass.substring(proxyClass.lastIndexOf('.') + 1) + "ApiMethod";
- }
-
- public static String getEndpointConfig(String proxyClass) {
- return proxyClass.substring(proxyClass.lastIndexOf('.') + 1) + "EndpointConfiguration";
- }
-
- public static String getEnumConstant(String enumValue) {
- if (enumValue == null || enumValue.isEmpty()) {
- return "DEFAULT";
- }
- StringBuilder builder = new StringBuilder();
- if (!Character.isJavaIdentifierStart(enumValue.charAt(0))) {
- builder.append('_');
- }
- for (char c : enumValue.toCharArray()) {
- char upperCase = Character.toUpperCase(c);
- if (!Character.isJavaIdentifierPart(upperCase)) {
- builder.append('_');
- } else {
- builder.append(upperCase);
- }
- }
- return builder.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
deleted file mode 100644
index 71bb89e..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiMethodAlias.java
+++ /dev/null
@@ -1,50 +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 org.apache.camel.maven;
-
-/**
- * Represents method alias
- */
-public class ApiMethodAlias {
-
- private String methodPattern;
- private String methodAlias;
-
- public ApiMethodAlias() {
- }
-
- public ApiMethodAlias(String methodPattern, String methodAlias) {
- this.methodPattern = methodPattern;
- this.methodAlias = methodAlias;
- }
-
- public String getMethodPattern() {
- return methodPattern;
- }
-
- public void setMethodPattern(String methodPattern) {
- this.methodPattern = methodPattern;
- }
-
- public String getMethodAlias() {
- return methodAlias;
- }
-
- public void setMethodAlias(String methodAlias) {
- this.methodAlias = methodAlias;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
deleted file mode 100644
index 69a759b..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/ApiProxy.java
+++ /dev/null
@@ -1,73 +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 org.apache.camel.maven;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Represents an API to use for generating Camel Component.
- */
-public class ApiProxy {
- private String apiName;
- private String proxyClass;
-
- private List<ApiMethodAlias> aliases = Collections.EMPTY_LIST;
-
- public ApiProxy() {
- }
-
- public ApiProxy(String apiName, String proxyClass) {
- this.apiName = apiName;
- this.proxyClass = proxyClass;
- }
-
- public ApiProxy(String apiName, String proxyClass, List<ApiMethodAlias> aliases) {
- this(apiName, proxyClass);
- this.aliases = aliases;
- }
-
- public String getApiName() {
- return apiName;
- }
-
- public void setApiName(String apiName) {
- this.apiName = apiName;
- }
-
- public String getProxyClass() {
- return proxyClass;
- }
-
- public void setProxyClass(String proxyClass) {
- this.proxyClass = proxyClass;
- }
-
- public List<ApiMethodAlias> getAliases() {
- return aliases;
- }
-
- public void setAliases(List<ApiMethodAlias> aliases) {
- this.aliases = aliases;
- }
-
- public void validate() {
- if (apiName == null || proxyClass == null) {
- throw new IllegalArgumentException("Properties apiName and proxyClass are required");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0c9fbb62/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/FileApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/FileApiMethodGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/FileApiMethodGeneratorMojo.java
deleted file mode 100644
index 566ef0a..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/FileApiMethodGeneratorMojo.java
+++ /dev/null
@@ -1,64 +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 org.apache.camel.maven;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.plugin.MojoExecutionException;
-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;
-
-/**
- * Parses ApiMethod signatures from a File.
- */
-@Mojo(name = "fromFile", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresProject = true,
- defaultPhase = LifecyclePhase.GENERATE_SOURCES)
-public class FileApiMethodGeneratorMojo extends AbstractApiMethodGeneratorMojo {
-
- @Parameter(required = true, property = PREFIX + "signatureFile")
- protected File signatureFile;
-
- @Override
- public List<String> getSignatureList() throws MojoExecutionException {
- // get signatureFile as a list of Strings
- List<String> result = new ArrayList<String>();
- try {
- BufferedReader reader = new BufferedReader(new FileReader(this.signatureFile));
- String line = reader.readLine();
- while (line != null) {
- result.add(line);
- line = reader.readLine();
- }
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- } catch (IOException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- if (result.isEmpty()) {
- throw new MojoExecutionException("Signature file " + signatureFile.getPath() + " is empty");
- }
- return result;
- }
-}