You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/06/07 12:50:31 UTC
[3/8] camel git commit: Experiment with generating spring-boot auto
configuration for the Camel components.
Experiment with generating spring-boot auto configuration for the Camel components.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/09491459
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/09491459
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/09491459
Branch: refs/heads/boot-generate
Commit: 09491459010371dfd29eb924dfe8ae74b9b63c2f
Parents: 4548609
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 7 11:23:01 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 7 11:23:01 2016 +0200
----------------------------------------------------------------------
components-starter/pom.xml | 34 ++++
.../springboot/AhcComponentConfiguration.java | 100 +++++++++++
components/pom.xml | 32 +++-
pom.xml | 1 +
tooling/apt-spring-boot/pom.xml | 68 --------
.../ComponentAnnotationProcessor.java | 34 ----
.../javax.annotation.processing.Processor | 17 --
.../maven/camel-package-maven-plugin/pom.xml | 15 +-
.../SpringBootAutoConfigurationMojo.java | 171 +++++++------------
tooling/pom.xml | 1 -
10 files changed, 229 insertions(+), 244 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/components-starter/pom.xml
----------------------------------------------------------------------
diff --git a/components-starter/pom.xml b/components-starter/pom.xml
new file mode 100644
index 0000000..5164e77
--- /dev/null
+++ b/components-starter/pom.xml
@@ -0,0 +1,34 @@
+<?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>camel-parent</artifactId>
+ <version>2.18-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <artifactId>components-starter</artifactId>
+ <name>Camel :: Components Starter</name>
+ <description>Camel Components Spring Boot Starter</description>
+ <packaging>pom</packaging>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentConfiguration.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentConfiguration.java
new file mode 100644
index 0000000..c032051
--- /dev/null
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentConfiguration.java
@@ -0,0 +1,100 @@
+package org.apache.camel.component.ahc.springboot;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import com.ning.http.client.AsyncHttpClient;
+import org.apache.camel.component.ahc.AhcBinding;
+import com.ning.http.client.AsyncHttpClientConfig;
+import org.apache.camel.util.jsse.SSLContextParameters;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * To call external HTTP services using Async Http Client.
+ */
+@ConfigurationProperties(prefix = "camel.component.ahc")
+public class AhcComponentConfiguration {
+
+ /**
+ * To use a custom AsyncHttpClient
+ */
+ private AsyncHttpClient client;
+ /**
+ * To use a custom AhcBinding which allows to control how to bind between
+ * AHC and Camel.
+ */
+ private AhcBinding binding;
+ /**
+ * To configure the AsyncHttpClient to use a custom
+ * com.ning.http.client.AsyncHttpClientConfig instance.
+ */
+ private AsyncHttpClientConfig clientConfig;
+ /**
+ * Reference to a org.apache.camel.util.jsse.SSLContextParameters in the
+ * Registry. Note that configuring this option will override any SSL/TLS
+ * configuration options provided through the clientConfig option at the
+ * endpoint or component level.
+ */
+ private SSLContextParameters sslContextParameters;
+ /**
+ * Whether to allow java serialization when a request uses
+ * context-type=application/x-java-serialized-object This is by default
+ * turned off. If you enable this then be aware that Java will deserialize
+ * the incoming data from the request to Java and that can be a potential
+ * security risk.
+ */
+ private boolean allowJavaSerializedObject;
+ /**
+ * To use a custom HeaderFilterStrategy to filter header to and from Camel
+ * message.
+ */
+ private HeaderFilterStrategy headerFilterStrategy;
+
+ public AsyncHttpClient getClient() {
+ return client;
+ }
+
+ public void setClient(AsyncHttpClient client) {
+ this.client = client;
+ }
+
+ public AhcBinding getBinding() {
+ return binding;
+ }
+
+ public void setBinding(AhcBinding binding) {
+ this.binding = binding;
+ }
+
+ public AsyncHttpClientConfig getClientConfig() {
+ return clientConfig;
+ }
+
+ public void setClientConfig(AsyncHttpClientConfig clientConfig) {
+ this.clientConfig = clientConfig;
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return sslContextParameters;
+ }
+
+ public void setSslContextParameters(
+ SSLContextParameters sslContextParameters) {
+ this.sslContextParameters = sslContextParameters;
+ }
+
+ public boolean isAllowJavaSerializedObject() {
+ return allowJavaSerializedObject;
+ }
+
+ public void setAllowJavaSerializedObject(boolean allowJavaSerializedObject) {
+ this.allowJavaSerializedObject = allowJavaSerializedObject;
+ }
+
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ public void setHeaderFilterStrategy(
+ HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index c559328..848127f 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -31,6 +31,16 @@
<description>Camel Components</description>
<packaging>pom</packaging>
+ <!-- to support spring-boot auto configuration in the Camel components -->
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ <version>${spring-boot-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
<modules>
<!-- we want to test these modules first to catch any errors early as possible -->
<module>camel-test</module>
@@ -286,15 +296,16 @@
<goal>prepare-components</goal>
</goals>
<phase>generate-resources</phase>
- </execution>
+ </execution>
<execution>
<id>validate</id>
<goals>
<goal>validate-components</goal>
+ <goal>prepare-spring-boot-auto-configuration</goal>
</goals>
<phase>prepare-package</phase>
- </execution>
- <execution>
+ </execution>
+ <execution>
<id>readme</id>
<goals>
<goal>update-readme</goal>
@@ -324,12 +335,15 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>apt-spring-boot</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
+
+ <!-- spring-boot auto configuration APT processor -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <optional>true</optional>
+ <version>${spring-boot-version}</version>
+ </dependency>
+
</dependencies>
</profile>
</profiles>
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d062d59..dc1823f 100755
--- a/pom.xml
+++ b/pom.xml
@@ -138,6 +138,7 @@
<module>buildingtools</module>
<module>camel-core</module>
<module>components</module>
+ <module>components-starter</module>
<module>tooling</module>
<module>platforms</module>
<module>tests</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/apt-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/pom.xml b/tooling/apt-spring-boot/pom.xml
deleted file mode 100644
index bc92167..0000000
--- a/tooling/apt-spring-boot/pom.xml
+++ /dev/null
@@ -1,68 +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>tooling</artifactId>
- <version>2.18-SNAPSHOT</version>
- </parent>
-
- <artifactId>apt-spring-boot</artifactId>
- <name>Camel :: Annotation Processor for Spring Boot</name>
- <description>Processes Camel components to generate Spring Boot auto configuration files</description>
-
- <properties>
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>spi-annotations</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <!-- re-use spring-boot APT -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-configuration-processor</artifactId>
- <version>${spring-boot-version}</version>
- </dependency>
-
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${jdk.version}</source>
- <target>${jdk.version}</target>
- <!-- Disable annotation processing for ourselves. -->
- <proc>none</proc>
- <verbose>false</verbose>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java b/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
deleted file mode 100644
index 627b573..0000000
--- a/tooling/apt-spring-boot/src/main/java/org/apache/camel/tools/apt/springboot/ComponentAnnotationProcessor.java
+++ /dev/null
@@ -1,34 +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.tools.apt.springboot;
-
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
-
-import org.apache.camel.spi.UriComponent;
-import org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor;
-
-@SupportedAnnotationTypes({ "*" })
-@SupportedSourceVersion(SourceVersion.RELEASE_8)
-public class ComponentAnnotationProcessor extends ConfigurationMetadataAnnotationProcessor {
-
- @Override
- protected String configurationPropertiesAnnotation() {
- return UriComponent.class.getName();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
----------------------------------------------------------------------
diff --git a/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
deleted file mode 100644
index a96c928..0000000
--- a/tooling/apt-spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
+++ /dev/null
@@ -1,17 +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.
-#
-org.apache.camel.tools.apt.springboot.ComponentAnnotationProcessor
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/maven/camel-package-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/pom.xml b/tooling/maven/camel-package-maven-plugin/pom.xml
index 4393469..5dd6991 100644
--- a/tooling/maven/camel-package-maven-plugin/pom.xml
+++ b/tooling/maven/camel-package-maven-plugin/pom.xml
@@ -15,7 +15,8 @@
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">
+<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>
@@ -87,6 +88,18 @@
<artifactId>commons-io</artifactId>
</dependency>
+ <!-- roaster to create java source -->
+ <dependency>
+ <groupId>org.jboss.forge.roaster</groupId>
+ <artifactId>roaster-api</artifactId>
+ <version>2.18.3.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.forge.roaster</groupId>
+ <artifactId>roaster-jdt</artifactId>
+ <version>2.18.3.Final</version>
+ </dependency>
+
<!-- add some logging to the classpath -->
<dependency>
<groupId>log4j</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 8d98571..1a0ff45 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -5,9 +5,9 @@
* 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
- *
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
* 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.
@@ -28,22 +28,25 @@ import java.util.TreeSet;
import org.apache.camel.maven.packaging.model.ComponentModel;
import org.apache.camel.maven.packaging.model.ComponentOptionModel;
import org.apache.camel.maven.packaging.model.EndpointOptionModel;
+import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
-import org.mvel2.templates.TemplateRuntime;
+import org.jboss.forge.roaster.Roaster;
+import org.jboss.forge.roaster.model.source.JavaClassSource;
+import org.jboss.forge.roaster.model.source.PropertySource;
+import org.jboss.forge.roaster.model.util.Strings;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.camel.maven.packaging.JSonSchemaHelper.getSafeValue;
import static org.apache.camel.maven.packaging.PackageHelper.loadText;
-import static org.apache.camel.maven.packaging.PackageHelper.writeText;
/**
* Generate Spring Boot auto configuration files for Camel components.
*
- * @goal generate-spring-boot-auto-configuration
+ * @goal prepare-spring-boot-auto-configuration
*/
public class SpringBootAutoConfigurationMojo extends AbstractMojo {
@@ -64,6 +67,13 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
protected File buildDir;
/**
+ * The source directory
+ *
+ * @parameter default-value="${basedir}/src/main/java"
+ */
+ protected File srcDir;
+
+ /**
* build context to check changed files and mark them for refresh (used for
* m2e compatibility)
*
@@ -80,105 +90,73 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
final Set<File> jsonFiles = new TreeSet<File>();
PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
- // only if there is components we should update the documentation files
+ // create auto configuration for the components
if (!componentNames.isEmpty()) {
getLog().info("Found " + componentNames.size() + " components");
for (String componentName : componentNames) {
String json = loadComponentJson(jsonFiles, componentName);
if (json != null) {
-
- // add as groups
- File file = new File(buildDir + "target/classes/META-INF", "spring-configuration-metadata.json");
ComponentModel model = generateComponentModel(componentName, json);
- boolean exists = file.exists();
- boolean updated = false;
- if (model.getComponentOptions() != null) {
- String options = templateComponentOptions(model);
- updated |= updateComponentOptions(file, options);
- }
- if (model.getEndpointOptions() != null) {
- String options = templateEndpointOptions(model);
- updated |= updateEndpointOptions(file, options);
- }
+ // package name
+ int pos = model.getJavaType().lastIndexOf(".");
+ String pkg = model.getJavaType().substring(0, pos) + ".springboot";
- if (updated) {
- getLog().info("Updated doc file: " + file);
- } else if (exists) {
- getLog().info("No changes to doc file: " + file);
- } else {
- getLog().info("No component doc file: " + file);
- }
+ getLog().info("Creating Java package " + pkg);
+ createAutoConfigurationClass(pkg, model);
}
}
}
}
- private boolean updateComponentOptions(File file, String changed) throws MojoExecutionException {
- if (!file.exists()) {
- return false;
+ private void createAutoConfigurationClass(String packageName, ComponentModel model) throws MojoFailureException {
+ final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
+
+ int pos = model.getJavaType().lastIndexOf(".");
+ String name = model.getJavaType().substring(pos + 1);
+ name = name.replace("Component", "ComponentConfiguration");
+ javaClass.setPackage(packageName).setName(name);
+
+ if (!Strings.isBlank(model.getDescription())) {
+ javaClass.getJavaDoc().setFullText(model.getDescription());
}
- try {
- String text = loadText(new FileInputStream(file));
+ String prefix = "camel.component." + model.getScheme();
+ javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
- String existing = StringHelper.between(text, "// component options: START", "// component options: END");
- if (existing != null) {
- // remove leading line breaks etc
- existing = existing.trim();
- changed = changed.trim();
- if (existing.equals(changed)) {
- return false;
- } else {
- String before = StringHelper.before(text, "// component options: START");
- String after = StringHelper.after(text, "// component options: END");
- text = before + "\n// component options: START\n" + changed + "\n// component options: END\n" + after;
- writeText(file, text);
- return true;
- }
- } else {
- getLog().warn("Cannot find markers in file " + file);
- getLog().warn("Add the following markers");
- getLog().warn("\t// component options: START");
- getLog().warn("\t// component options: END");
- return false;
+ for (ComponentOptionModel option : model.getComponentOptions()) {
+ PropertySource<JavaClassSource> prop = javaClass.addProperty(option.getJavaType(), option.getName());
+ if ("true".equals(option.getDeprecated())) {
+ prop.getField().addAnnotation(Deprecated.class);
+ }
+ if (!Strings.isBlank(option.getDescription())) {
+ prop.getField().getJavaDoc().setFullText(option.getDescription());
}
- } catch (Exception e) {
- throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
}
- }
- private boolean updateEndpointOptions(File file, String changed) throws MojoExecutionException {
- if (!file.exists()) {
- return false;
- }
+ String code = javaClass.toString();
+ getLog().info("Source code generated:\n" + code);
- try {
- String text = loadText(new FileInputStream(file));
+ String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
+ File target = new File(srcDir, fileName);
- String existing = StringHelper.between(text, "// endpoint options: START", "// endpoint options: END");
- if (existing != null) {
- // remove leading line breaks etc
- existing = existing.trim();
- changed = changed.trim();
- if (existing.equals(changed)) {
- return false;
+ try {
+ if (target.exists()) {
+ String existing = FileUtils.readFileToString(target);
+ if (!code.equals(existing)) {
+ // update
+ FileUtils.write(target, code);
+ getLog().info("Updated existing file: " + target);
} else {
- String before = StringHelper.before(text, "// endpoint options: START");
- String after = StringHelper.after(text, "// endpoint options: END");
- text = before + "\n// endpoint options: START\n" + changed + "\n// endpoint options: END\n" + after;
- writeText(file, text);
- return true;
+ getLog().info("No changes to existing file: " + target);
}
} else {
- getLog().warn("Cannot find markers in file " + file);
- getLog().warn("Add the following markers");
- getLog().warn("\t// endpoint options: START");
- getLog().warn("\t// endpoint options: END");
- return false;
+ // write
+ FileUtils.write(target, code);
+ getLog().info("Created file: " + target);
}
} catch (Exception e) {
- throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
+ throw new MojoFailureException("IOError with file " + target, e);
}
}
@@ -244,47 +222,12 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
option.setDeprecated(getSafeValue("deprecated", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
option.setDescription(getSafeValue("description", row));
- // lets put required in the description
- if ("true".equals(option.getRequired())) {
- String desc = "*Required* " + option.getDescription();
- option.setDescription(desc);
- }
component.addEndpointOption(option);
}
return component;
}
- private String templateComponentHeader(ComponentModel model) throws MojoExecutionException {
- try {
- String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("component-header.mvel"));
- String out = (String) TemplateRuntime.eval(template, model);
- return out;
- } catch (Exception e) {
- throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
- }
- }
-
- private String templateComponentOptions(ComponentModel model) throws MojoExecutionException {
- try {
- String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("component-options.mvel"));
- String out = (String) TemplateRuntime.eval(template, model);
- return out;
- } catch (Exception e) {
- throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
- }
- }
-
- private String templateEndpointOptions(ComponentModel model) throws MojoExecutionException {
- try {
- String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("endpoint-options.mvel"));
- String out = (String) TemplateRuntime.eval(template, model);
- return out;
- } catch (Exception e) {
- throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
- }
- }
-
private List<String> findComponentNames() {
List<String> componentNames = new ArrayList<String>();
for (Resource r : project.getBuild().getResources()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/09491459/tooling/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/pom.xml b/tooling/pom.xml
index f230af5..0425218 100644
--- a/tooling/pom.xml
+++ b/tooling/pom.xml
@@ -39,7 +39,6 @@
<module>parent</module>
<module>spi-annotations</module>
<module>apt</module>
- <module>apt-spring-boot</module>
<module>maven</module>
<module>archetypes</module>
<module>camel-manual</module>