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/08 09:34:23 UTC
[34/34] 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/4b784473
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4b784473
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4b784473
Branch: refs/heads/boot-generate
Commit: 4b7844732b19bc49ddddf485995e3847a0551ef1
Parents: d8951be
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jun 8 11:33:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jun 8 11:33:28 2016 +0200
----------------------------------------------------------------------
.../main/resources/META-INF/spring.factories | 2 +
.../main/resources/META-INF/spring.factories | 2 +
.../main/resources/META-INF/spring.factories | 2 +
.../main/resources/META-INF/spring.factories | 2 +
.../SpringBootAutoConfigurationMojo.java | 104 ++++++++++++-------
5 files changed, 77 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4b784473/components/camel-cxf/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/resources/META-INF/spring.factories b/components/camel-cxf/src/main/resources/META-INF/spring.factories
index e72480d..9ddb944 100644
--- a/components/camel-cxf/src/main/resources/META-INF/spring.factories
+++ b/components/camel-cxf/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,6 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.cxf.springboot.CxfComponentAutoConfiguration,\
org.apache.camel.component.cxf.jaxrs.springboot.CxfRsComponentAutoConfiguration
+
http://git-wip-us.apache.org/repos/asf/camel/blob/4b784473/components/camel-disruptor/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/components/camel-disruptor/src/main/resources/META-INF/spring.factories b/components/camel-disruptor/src/main/resources/META-INF/spring.factories
index 6797e8a..7ab3ca3 100644
--- a/components/camel-disruptor/src/main/resources/META-INF/spring.factories
+++ b/components/camel-disruptor/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,6 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.disruptor.springboot.DisruptorComponentAutoConfiguration,\
org.apache.camel.component.disruptor.vm.springboot.DisruptorVmComponentAutoConfiguration
+
http://git-wip-us.apache.org/repos/asf/camel/blob/4b784473/components/camel-sjms/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/resources/META-INF/spring.factories b/components/camel-sjms/src/main/resources/META-INF/spring.factories
index a65a16e..7fe9139 100644
--- a/components/camel-sjms/src/main/resources/META-INF/spring.factories
+++ b/components/camel-sjms/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,6 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.sjms.springboot.SjmsComponentAutoConfiguration,\
org.apache.camel.component.sjms.batch.springboot.SjmsBatchComponentAutoConfiguration
+
http://git-wip-us.apache.org/repos/asf/camel/blob/4b784473/components/camel-sql/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/resources/META-INF/spring.factories b/components/camel-sql/src/main/resources/META-INF/spring.factories
index 881053b..1412326 100644
--- a/components/camel-sql/src/main/resources/META-INF/spring.factories
+++ b/components/camel-sql/src/main/resources/META-INF/spring.factories
@@ -16,4 +16,6 @@
#
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.sql.springboot.SqlComponentAutoConfiguration,\
org.apache.camel.component.sql.stored.springboot.SqlStoredComponentAutoConfiguration
+
http://git-wip-us.apache.org/repos/asf/camel/blob/4b784473/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 dc77360..f87660f 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
@@ -219,11 +219,11 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String body = createBody(model.getShortJavaType());
MethodSource<JavaClassSource> method = javaClass.addMethod()
- .setName("configureComponent")
- .setPublic()
- .setBody(body)
- .setReturnType(model.getShortJavaType())
- .addThrows(Exception.class);
+ .setName("configureComponent")
+ .setPublic()
+ .setBody(body)
+ .setReturnType(model.getShortJavaType())
+ .addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
@@ -268,34 +268,68 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Component", "ComponentAutoConfiguration");
- sb.append(packageName).append(".").append(name).append("\n");
+ String lineToAdd = packageName + "." + name + "\n";
+ sb.append(lineToAdd);
String fileName = "META-INF/spring.factories";
File target = new File(resourcesDir, fileName);
- try {
- InputStream is = getClass().getClassLoader().getResourceAsStream("license-header.txt");
- String header = loadText(is);
- String code = sb.toString();
- // add empty new line after header
- code = header + "\n" + code;
- getLog().debug("Source code generated:\n" + code);
+ if (target.exists()) {
+ try {
+ // is the auto configuration already in the file
+ boolean found = false;
+ List<String> lines = FileUtils.readLines(target);
+ for (String line : lines) {
+ if (line.contains(name)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found) {
+ getLog().info("No changes to existing file: " + target);
+ } else {
+ // find last non empty line, so we can add our new line after that
+ int lastLine = 0;
+ for (int i = lines.size() - 1; i >= 0; i--) {
+ String line = lines.get(i);
+ if (!line.trim().isEmpty()) {
+ // adjust existing line so its being continued
+ line = line + ",\\";
+ lines.set(i, line);
+ lastLine = i;
+ break;
+ }
+ }
+ lines.add(lastLine + 1, lineToAdd);
+
+ StringBuilder code = new StringBuilder();
+ for (String line : lines) {
+ code.append(line).append("\n");
+ }
- if (target.exists()) {
- String existing = FileUtils.readFileToString(target);
- if (!code.equals(existing)) {
// update
- FileUtils.write(target, code, false);
+ FileUtils.write(target, code.toString(), false);
getLog().info("Updated existing file: " + target);
- } else {
- getLog().info("No changes to existing file: " + target);
}
- } else {
+ } catch (Exception e) {
+ throw new MojoFailureException("IOError with file " + target, e);
+ }
+ } else {
+ // create new file
+ try {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("license-header.txt");
+ String header = loadText(is);
+ String code = sb.toString();
+ // add empty new line after header
+ code = header + "\n" + code;
+ getLog().debug("Source code generated:\n" + code);
+
FileUtils.write(target, code);
getLog().info("Created file: " + target);
+ } catch (Exception e) {
+ throw new MojoFailureException("IOError with file " + target, e);
}
- } catch (Exception e) {
- throw new MojoFailureException("IOError with file " + target, e);
}
}
@@ -386,19 +420,19 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
ComponentModel component = new ComponentModel();
- component.setScheme(JSonSchemaHelper.getSafeValue("scheme", rows));
- component.setSyntax(JSonSchemaHelper.getSafeValue("syntax", rows));
- component.setAlternativeSyntax(JSonSchemaHelper.getSafeValue("alternativeSyntax", rows));
- component.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
- component.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
- component.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
- component.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
- component.setConsumerOnly(JSonSchemaHelper.getSafeValue("consumerOnly", rows));
- component.setProducerOnly(JSonSchemaHelper.getSafeValue("producerOnly", rows));
- component.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
- component.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
- component.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
- component.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
+ component.setScheme(getSafeValue("scheme", rows));
+ component.setSyntax(getSafeValue("syntax", rows));
+ component.setAlternativeSyntax(getSafeValue("alternativeSyntax", rows));
+ component.setTitle(getSafeValue("title", rows));
+ component.setDescription(getSafeValue("description", rows));
+ component.setLabel(getSafeValue("label", rows));
+ component.setDeprecated(getSafeValue("deprecated", rows));
+ component.setConsumerOnly(getSafeValue("consumerOnly", rows));
+ component.setProducerOnly(getSafeValue("producerOnly", rows));
+ component.setJavaType(getSafeValue("javaType", rows));
+ component.setGroupId(getSafeValue("groupId", rows));
+ component.setArtifactId(getSafeValue("artifactId", rows));
+ component.setVersion(getSafeValue("version", rows));
rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
for (Map<String, String> row : rows) {