This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0b13d7ca9dcc9fc92d936a183390d976e8237fde Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Jun 21 09:06:23 2019 +0200 CAMEL-13663: camel-main-maven-plugin to generte spring-boot tooling metadata to fool Java editors to have code completions for Camel Main application.properties files. --- .../java/org/apache/camel/maven/AutowireMojo.java | 23 ++++---- .../apache/camel/maven/SpringBootToolingMojo.java | 25 ++++----- .../org/apache/camel/maven/model/AutowireData.java | 44 +++++++++++++++ .../apache/camel/maven/model/SpringBootData.java | 64 ++++++++++++++++++++++ 4 files changed, 132 insertions(+), 24 deletions(-) diff --git a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java index 947c5a7..50a7190 100644 --- a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java +++ b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/AutowireMojo.java @@ -31,7 +31,7 @@ import java.util.stream.Collectors; import org.apache.camel.catalog.CamelCatalog; import org.apache.camel.catalog.JSonSchemaHelper; -import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.maven.model.AutowireData; import org.apache.camel.support.PatternHelper; import org.apache.camel.util.IOHelper; import org.apache.camel.util.OrderedProperties; @@ -116,7 +116,7 @@ public class AutowireMojo extends AbstractMainMojo { } // find the autowire via classpath scanning - List<String> autowires = findAutowireComponentOptionsByClasspath(catalog, camelComponentsOnClasspath, reflections, mappingProperties); + List<AutowireData> autowires = findAutowireComponentOptionsByClasspath(catalog, camelComponentsOnClasspath, reflections, mappingProperties); if (!autowires.isEmpty()) { outFolder.mkdirs(); @@ -124,9 +124,11 @@ public class AutowireMojo extends AbstractMainMojo { try { FileOutputStream fos = new FileOutputStream(file, false); fos.write("# Generated by camel build tools\n".getBytes()); - for (String line : autowires) { - fos.write(line.getBytes()); - fos.write("\n".getBytes()); + for (AutowireData data : autowires) { + fos.write(data.getKey().getBytes()); + fos.write('='); + fos.write(data.getValue().getBytes()); + fos.write('\n'); } IOHelper.close(fos); getLog().info("Created file: " + file + " (autowire by classpath: " + autowires.size() + ")"); @@ -162,9 +164,9 @@ public class AutowireMojo extends AbstractMainMojo { return mappings; } - protected List<String> findAutowireComponentOptionsByClasspath(CamelCatalog catalog, Set<String> components, + protected List<AutowireData> findAutowireComponentOptionsByClasspath(CamelCatalog catalog, Set<String> components, Reflections reflections, Properties mappingProperties) { - List<String> autowires = new ArrayList<>(); + List<AutowireData> autowires = new ArrayList<>(); for (String componentName : components) { getLog().debug("Autowiring Camel component: " + componentName); @@ -200,9 +202,10 @@ public class AutowireMojo extends AbstractMainMojo { .collect(Collectors.toSet()); Class best = chooseBestKnownType(componentName, name, clazz, classes, mappingProperties); if (best != null) { - String line = "camel.component." + componentName + "." + name + "=#class:" + best.getName(); - getLog().debug(line); - autowires.add(line); + String key = "camel.component." + componentName + "." + name; + String value = "#class:" + best.getName(); + getLog().debug(key + "=" + value); + autowires.add(new AutowireData(key, value)); // TODO: get options from best class (getter/setter pairs) // we dont have documentation diff --git a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/SpringBootToolingMojo.java b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/SpringBootToolingMojo.java index a5d8cb0..d331108 100644 --- a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/SpringBootToolingMojo.java +++ b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/SpringBootToolingMojo.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import org.apache.camel.catalog.JSonSchemaHelper; +import org.apache.camel.maven.model.SpringBootData; import org.apache.camel.util.IOHelper; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -61,7 +62,7 @@ public class SpringBootToolingMojo extends AbstractMainMojo { return; } - List<String[]> componentData = new ArrayList<>(); + List<SpringBootData> componentData = new ArrayList<>(); for (String componentName : camelComponentsOnClasspath) { String json = catalog.componentJSonSchema(componentName); if (json == null) { @@ -79,7 +80,7 @@ public class SpringBootToolingMojo extends AbstractMainMojo { // we want to use dash in the name String dash = camelCaseToDash(name); String key = "camel.component." + componentName + "." + dash; - componentData.add(new String[]{key, javaType, desc, defaultValue}); + componentData.add(new SpringBootData(key, javaType, desc, defaultValue)); } } @@ -87,21 +88,17 @@ public class SpringBootToolingMojo extends AbstractMainMojo { StringBuilder sb = new StringBuilder(); for (int i = 0; i < componentData.size(); i++) { - String[] row = componentData.get(i); - String name = row[0]; - String javaType = row[1]; - String desc = row[2]; - String defaultValue = row[3]; + SpringBootData row = componentData.get(i); sb.append(" {\n"); - sb.append(" \"name\": \"" + name + "\",\n"); - sb.append(" \"type\": \"" + javaType + "\",\n"); - sb.append(" \"description\": \"" + desc + "\""); - if (defaultValue != null) { + sb.append(" \"name\": \"" + row.getName() + "\",\n"); + sb.append(" \"type\": \"" + row.getJavaType() + "\",\n"); + sb.append(" \"description\": \"" + row.getDescription() + "\""); + if (row.getDefaultValue() != null) { sb.append(",\n"); - if (springBootDefaultValueQuotes(javaType)) { - sb.append(" \"defaultValue\": \"" + defaultValue + "\"\n"); + if (springBootDefaultValueQuotes(row.getJavaType())) { + sb.append(" \"defaultValue\": \"" + row.getDefaultValue() + "\"\n"); } else { - sb.append(" \"defaultValue\": " + defaultValue + "\n"); + sb.append(" \"defaultValue\": " + row.getDefaultValue() + "\n"); } } else { sb.append("\n"); diff --git a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/AutowireData.java b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/AutowireData.java new file mode 100644 index 0000000..ab7019a --- /dev/null +++ b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/AutowireData.java @@ -0,0 +1,44 @@ +/* + * 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.model; + +public final class AutowireData { + + private String key; + private String value; + + public AutowireData(String key, String value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/SpringBootData.java b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/SpringBootData.java new file mode 100644 index 0000000..e10ae5a --- /dev/null +++ b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/model/SpringBootData.java @@ -0,0 +1,64 @@ +/* + * 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.model; + +public final class SpringBootData { + + private String name; + private String javaType; + private String description; + private String defaultValue; + + public SpringBootData(String name, String javaType, String description, String defaultValue) { + this.name = name; + this.javaType = javaType; + this.description = description; + this.defaultValue = defaultValue; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getJavaType() { + return javaType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } +}