First cut of mvn goal to generate/update component readme.md file. Switch to mvel which is easier to use than freemarker.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b3c02c4c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b3c02c4c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b3c02c4c Branch: refs/heads/master Commit: b3c02c4cc914b487181609fad6242f76f66c6377 Parents: 4b335a1 Author: Claus Ibsen <[email protected]> Authored: Tue Jan 26 19:44:09 2016 +0100 Committer: Claus Ibsen <[email protected]> Committed: Tue Jan 26 19:45:44 2016 +0100 ---------------------------------------------------------------------- .../camel/maven/packaging/JSonSchemaHelper.java | 14 +- .../maven/packaging/ReadmeComponentMojo.java | 87 +++++++++---- .../maven/packaging/model/ComponentModel.java | 25 ++-- .../packaging/model/ComponentOptionModel.java | 16 +-- .../packaging/model/EndpointOptionModel.java | 129 +++++++++++++++++++ .../src/main/resources/component-options.mvel | 4 +- .../src/main/resources/endpoint-options.mvel | 8 ++ 7 files changed, 234 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java index ea17772..1ac0e33 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java @@ -112,22 +112,28 @@ public final class JSonSchemaHelper { return value; } - public static String getValue(String key, List<Map<String, String>> rows) { + /** + * Gets the value with the key in a safe way, eg returning an empty string if there was no value for the key. + */ + public static String getSafeValue(String key, List<Map<String, String>> rows) { for (Map<String, String> row : rows) { String value = row.get(key); if (value != null) { return value; } } - return null; + return ""; } - public static String getValue(String key, Map<String, String> rows) { + /** + * Gets the value with the key in a safe way, eg returning an empty string if there was no value for the key. + */ + public static String getSafeValue(String key, Map<String, String> rows) { String value = rows.get(key); if (value != null) { return value; } - return null; + return ""; } } http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java index f6032b3..ddc512b 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.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. @@ -28,19 +28,21 @@ 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.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.sonatype.plexus.build.incremental.BuildContext; -import static org.apache.camel.maven.packaging.JSonSchemaHelper.getValue; +import static org.apache.camel.maven.packaging.JSonSchemaHelper.getSafeValue; import static org.apache.camel.maven.packaging.PackageHelper.loadText; /** - * Generate or updates the component readme.md file in the project root directort. + * Generate or updates the component readme.md file in the project root directory. * * @goal update-readme */ @@ -90,8 +92,10 @@ public class ReadmeComponentMojo extends AbstractMojo { ComponentModel model = generateComponentModel(componentName, json); String header = templateComponentHeader(model); String options = templateComponentOptions(model); + String options2 = templateEndpointOptions(model); getLog().info(header); getLog().info(options); + getLog().info(options2); } } } @@ -118,33 +122,52 @@ public class ReadmeComponentMojo extends AbstractMojo { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false); ComponentModel component = new ComponentModel(); - component.setScheme(getValue("scheme", rows)); - component.setSyntax(getValue("syntax", rows)); - component.setTitle(getValue("title", rows)); - component.setDescription(getValue("description", rows)); - component.setLabel(getValue("label", rows)); - component.setDeprecated(getValue("deprecated", rows)); - component.setConsumerOnly(getValue("consumerOnly", rows)); - component.setProducerOnly(getValue("producerOnly", rows)); - component.setJavaType(getValue("javaType", rows)); - component.setGroupId(getValue("groupId", rows)); - component.setArtifactId(getValue("artifactId", rows)); - component.setVersion(getValue("version", rows)); + component.setScheme(JSonSchemaHelper.getSafeValue("scheme", rows)); + component.setSyntax(JSonSchemaHelper.getSafeValue("syntax", 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)); rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true); - - List<ComponentOptionModel> options = new ArrayList<ComponentOptionModel>(); + List<ComponentOptionModel> componentOptions = new ArrayList<ComponentOptionModel>(); for (Map<String, String> row : rows) { ComponentOptionModel option = new ComponentOptionModel(); - option.setKey(getValue("name", row)); - option.setKind(getValue("kind", row)); - option.setType(getValue("type", row)); - option.setJavaType(getValue("javaType", row)); - option.setDeprecated(getValue("javaType", row)); - option.setDescription(getValue("description", row)); - options.add(option); + option.setName(getSafeValue("name", row)); + option.setKind(getSafeValue("kind", row)); + option.setType(getSafeValue("type", row)); + option.setJavaType(getSafeValue("javaType", row)); + option.setDeprecated(getSafeValue("deprecated", row)); + option.setDescription(getSafeValue("description", row)); + componentOptions.add(option); } - component.setOptions(options); + component.setComponentOptions(componentOptions); + + rows = JSonSchemaHelper.parseJsonSchema("properties", json, true); + List<EndpointOptionModel> endpointOptions = new ArrayList<EndpointOptionModel>(); + for (Map<String, String> row : rows) { + EndpointOptionModel option = new EndpointOptionModel(); + option.setName(getSafeValue("name", row)); + option.setKind(getSafeValue("kind", row)); + option.setGroup(getSafeValue("group", row)); + option.setRequired(getSafeValue("required", row)); + option.setType(getSafeValue("type", row)); + option.setJavaType(getSafeValue("javaType", row)); + option.setEnums(getSafeValue("enum", row)); + option.setPrefix(getSafeValue("prefix", row)); + option.setMultiValue(getSafeValue("multiValue", row)); + option.setDeprecated(getSafeValue("deprecated", row)); + option.setDefaultValue(getSafeValue("defaultValue", row)); + option.setDescription(getSafeValue("description", row)); + endpointOptions.add(option); + } + component.setEndpointOptions(endpointOptions); return component; } @@ -169,6 +192,16 @@ public class ReadmeComponentMojo extends AbstractMojo { } } + 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/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java index 7e689dd..280f77d 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.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. @@ -33,7 +33,8 @@ public class ComponentModel { private String groupId; private String artifactId; private String version; - private List<ComponentOptionModel> options; + private List<ComponentOptionModel> componentOptions; + private List<EndpointOptionModel> endpointOptions; public String getKind() { return kind; @@ -139,11 +140,19 @@ public class ComponentModel { this.version = version; } - public List<ComponentOptionModel> getOptions() { - return options; + public List<ComponentOptionModel> getComponentOptions() { + return componentOptions; } - public void setOptions(List<ComponentOptionModel> options) { - this.options = options; + public void setComponentOptions(List<ComponentOptionModel> componentOptions) { + this.componentOptions = componentOptions; + } + + public List<EndpointOptionModel> getEndpointOptions() { + return endpointOptions; + } + + public void setEndpointOptions(List<EndpointOptionModel> endpointOptions) { + this.endpointOptions = endpointOptions; } } http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java index 31df0dd..978b166 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.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. @@ -18,19 +18,19 @@ package org.apache.camel.maven.packaging.model; public class ComponentOptionModel { - private String key; + private String name; private String kind; private String type; private String javaType; private String deprecated; private String description; - public String getKey() { - return key; + public String getName() { + return name; } - public void setKey(String key) { - this.key = key; + public void setName(String name) { + this.name = name; } public String getKind() { http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EndpointOptionModel.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EndpointOptionModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EndpointOptionModel.java new file mode 100644 index 0000000..bec4bd5 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EndpointOptionModel.java @@ -0,0 +1,129 @@ +/** + * 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.packaging.model; + +public class EndpointOptionModel { + + private String name; + private String kind; + private String group; + private String required; + private String type; + private String javaType; + private String enums; + private String prefix; + private String multiValue; + private String deprecated; + private String defaultValue; + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getRequired() { + return required; + } + + public void setRequired(String required) { + this.required = required; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getJavaType() { + return javaType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } + + public String getEnums() { + return enums; + } + + public void setEnums(String enums) { + this.enums = enums; + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getMultiValue() { + return multiValue; + } + + public void setMultiValue(String multiValue) { + this.multiValue = multiValue; + } + + public String getDeprecated() { + return deprecated; + } + + public void setDeprecated(String deprecated) { + this.deprecated = deprecated; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel index cd895c5..0ad31a6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel @@ -1,8 +1,8 @@ ### Component options -The @{title} component supports @{options.size()} options which are listed below: +The @{title} component supports @{componentOptions.size()} options which are listed below. | Key | Description | | --- | ----------- | -@foreach{row : options}| @{row.key} | @{row.description} | +@foreach{row : componentOptions}| @{row.name} | @{row.description} | @end{} http://git-wip-us.apache.org/repos/asf/camel/blob/b3c02c4c/tooling/maven/camel-package-maven-plugin/src/main/resources/endpoint-options.mvel ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/endpoint-options.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/endpoint-options.mvel new file mode 100644 index 0000000..98f7be4 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/endpoint-options.mvel @@ -0,0 +1,8 @@ +### Endpoint options + +The @{title} component supports @{endpointOptions.size()} endpoint options which are listed below: + +| Key | Group | Required | Default | Description | +| --- | ----- | -------- | ------- | ----------- | +@foreach{row : endpointOptions}| @{row.name} | @{row.group} | @{row.required} | @{row.defaultValue} | @{row.description} | +@end{}
