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:34 UTC

[6/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/cac6eb1f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cac6eb1f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cac6eb1f

Branch: refs/heads/boot-generate
Commit: cac6eb1fb876207aca3bd8a7600afd1a2ad57b70
Parents: 73908e9
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jun 7 14:04:30 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jun 7 14:08:29 2016 +0200

----------------------------------------------------------------------
 .../AhcComponentAutoConfiguration.java          | 16 +++++++++
 .../springboot/AhcComponentConfiguration.java   | 16 +++++++++
 .../SpringBootAutoConfigurationMojo.java        | 36 ++++++++++----------
 .../src/main/resources/license-header-java.txt  | 16 +++++++++
 .../src/main/resources/license-header.txt       | 17 +++++++++
 5 files changed, 83 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cac6eb1f/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentAutoConfiguration.java b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentAutoConfiguration.java
index 215f19c..560fa9b 100644
--- a/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentAutoConfiguration.java
+++ b/components/camel-ahc/src/main/java/org/apache/camel/component/ahc/springboot/AhcComponentAutoConfiguration.java
@@ -1,3 +1,19 @@
+/**
+ * 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.ahc.springboot;
 
 import org.springframework.context.annotation.Configuration;

http://git-wip-us.apache.org/repos/asf/camel/blob/cac6eb1f/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
index c032051..1743b48 100644
--- 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
@@ -1,3 +1,19 @@
+/**
+ * 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.ahc.springboot;
 
 import org.springframework.boot.context.properties.ConfigurationProperties;

http://git-wip-us.apache.org/repos/asf/camel/blob/cac6eb1f/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 405d2f0..4f9ead2 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ *      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.
@@ -19,8 +19,8 @@ package org.apache.camel.maven.packaging;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -40,7 +40,6 @@ import org.jboss.forge.roaster.model.source.AnnotationSource;
 import org.jboss.forge.roaster.model.source.JavaClassSource;
 import org.jboss.forge.roaster.model.source.MethodSource;
 import org.jboss.forge.roaster.model.source.PropertySource;
-import org.jboss.forge.roaster.model.util.Assert;
 import org.jboss.forge.roaster.model.util.Strings;
 import org.sonatype.plexus.build.incremental.BuildContext;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -114,17 +113,13 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
                 if (json != null) {
                     ComponentModel model = generateComponentModel(componentName, json);
 
-                    // package name
+                    // use springboot as sub package name so the code is not in normal
+                    // package so the Spring Boot JARs can be optional at runtime
                     int pos = model.getJavaType().lastIndexOf(".");
                     String pkg = model.getJavaType().substring(0, pos) + ".springboot";
 
-                    getLog().info("Creating/Updating ComponentConfiguration source code in package " + pkg);
                     createComponentConfigurationSource(pkg, model);
-
-                    getLog().info("Creating/Updating ComponentAutoConfiguration source code in package " + pkg);
                     createComponentAutoConfigurationSource(pkg, model);
-
-                    getLog().info("Creating/Updating spring.factories source code");
                     createSpringFactorySource(pkg, model);
                 }
             }
@@ -132,7 +127,6 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
     }
 
     private void createSpringFactorySource(String packageName, ComponentModel model) throws MojoFailureException {
-        // TODO: append to any existing file
         StringBuilder sb = new StringBuilder();
         sb.append("org.springframework.boot.autoconfigure.EnableAutoConfiguration=\\\n");
 
@@ -157,8 +151,10 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
                     getLog().info("No changes to existing file: " + target);
                 }
             } else {
-                // write
-                FileUtils.write(target, code);
+                InputStream is = getClass().getClassLoader().getResourceAsStream("license-header.txt");
+                String header = loadText(is);
+                FileUtils.write(target, header);
+                FileUtils.write(target, code, true);
                 getLog().info("Created file: " + target);
             }
         } catch (Exception e) {
@@ -208,8 +204,10 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
                     getLog().info("No changes to existing file: " + target);
                 }
             } else {
-                // write
-                FileUtils.write(target, code);
+                InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
+                String header = loadText(is);
+                FileUtils.write(target, header);
+                FileUtils.write(target, code, true);
                 getLog().info("Created file: " + target);
             }
         } catch (Exception e) {
@@ -272,8 +270,10 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
                     getLog().info("No changes to existing file: " + target);
                 }
             } else {
-                // write
-                FileUtils.write(target, code);
+                InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
+                String header = loadText(is);
+                FileUtils.write(target, header);
+                FileUtils.write(target, code, true);
                 getLog().info("Created file: " + target);
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cac6eb1f/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt
new file mode 100644
index 0000000..366cda7
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header-java.txt
@@ -0,0 +1,16 @@
+/**
+ * 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.
+ */

http://git-wip-us.apache.org/repos/asf/camel/blob/cac6eb1f/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt
new file mode 100644
index 0000000..384def4
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/license-header.txt
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+