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/01/26 19:46:37 UTC

[1/5] camel git commit: First cut of mvn goal to generate/update component readme.md file

Repository: camel
Updated Branches:
  refs/heads/master d5574fdb7 -> b3c02c4cc


First cut of mvn goal to generate/update component readme.md file


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/07bdbad1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/07bdbad1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/07bdbad1

Branch: refs/heads/master
Commit: 07bdbad13c1e36fdfe91a9214be046df3c52d38c
Parents: d5574fd
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 29 12:08:50 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 26 19:45:09 2016 +0100

----------------------------------------------------------------------
 components/camel-ahc/pom.xml                    | 19 ++++
 .../maven/packaging/ReadmeComponentMojo.java    | 97 ++++++++++++++++++++
 2 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/07bdbad1/components/camel-ahc/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-ahc/pom.xml b/components/camel-ahc/pom.xml
index 59fd2f1..610d727 100644
--- a/components/camel-ahc/pom.xml
+++ b/components/camel-ahc/pom.xml
@@ -85,4 +85,23 @@
     </dependency>
   </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-package-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <executions>
+          <execution>
+            <id>readme</id>
+            <goals>
+              <goal>update-readme</goal>
+            </goals>
+            <phase>package</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/07bdbad1/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
new file mode 100644
index 0000000..8ecfe7d
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
@@ -0,0 +1,97 @@
+/**
+ * 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
+ * <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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven.packaging;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.OutputStream;
+
+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.sonatype.plexus.build.incremental.BuildContext;
+
+/**
+ * Generate or updates the component readme.md file in the project root directort.
+ *
+ * @goal update-readme
+ */
+public class ReadmeComponentMojo extends AbstractMojo {
+
+    /**
+     * The maven project.
+     *
+     * @parameter property="project"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The output directory for generated readme file
+     *
+     * @parameter default-value="${project.build.directory}"
+     */
+    protected File buildDir;
+
+    /**
+     * build context to check changed files and mark them for refresh (used for
+     * m2e compatibility)
+     *
+     * @component
+     * @readonly
+     */
+    private BuildContext buildContext;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        File readmeDir = new File(buildDir, "..");
+        File readmeFile = new File(readmeDir, "readme.md");
+
+        // see if a file with name readme.md exists in any kind of case
+        String[] names = readmeDir.list(new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                return "readme.md".equalsIgnoreCase(name);
+            }
+        });
+        if (names != null && names.length == 1) {
+            readmeFile = new File(readmeDir, names[0]);
+        }
+
+        boolean exists = readmeFile.exists();
+        if (exists) {
+            getLog().info("Using existing " + readmeFile.getName() + " file");
+        } else {
+            getLog().info("Creating new readme.md file");
+        }
+
+        try {
+            OutputStream os = buildContext.newFileOutputStream(readmeFile);
+            os.write("Hello World".getBytes());
+            os.close();
+
+        } catch (IOException e) {
+            throw new MojoExecutionException("Failed to write to " + readmeFile + ". Reason: " + e, e);
+        }
+
+    }
+
+
+}


[4/5] camel git commit: First cut of mvn goal to generate/update component readme.md file. Switch to mvel which is easier to use than freemarker.

Posted by da...@apache.org.
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/4b335a18
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4b335a18
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4b335a18

Branch: refs/heads/master
Commit: 4b335a18a6a3dfad5b4a6da4a81a10b714294745
Parents: 973af27
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 26 19:26:07 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 26 19:45:36 2016 +0100

----------------------------------------------------------------------
 .../maven/camel-package-maven-plugin/pom.xml    |  6 +--
 .../maven/packaging/ReadmeComponentMojo.java    | 39 +++++++++++---------
 .../src/main/resources/component-header.ftl     | 22 -----------
 .../src/main/resources/component-header.mvel    | 20 ++++++++++
 .../src/main/resources/component-options.ftl    |  4 --
 .../src/main/resources/component-options.mvel   |  8 ++++
 6 files changed, 52 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/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 68920e9..b07f511 100644
--- a/tooling/maven/camel-package-maven-plugin/pom.xml
+++ b/tooling/maven/camel-package-maven-plugin/pom.xml
@@ -44,9 +44,9 @@
   <dependencies>
 
     <dependency>
-      <groupId>org.freemarker</groupId>
-      <artifactId>freemarker</artifactId>
-      <version>${freemarker-version}</version>
+      <groupId>org.mvel</groupId>
+      <artifactId>mvel2</artifactId>
+      <version>${mvel-version}</version>
     </dependency>
 
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/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 59c5f6d..f6032b3 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
@@ -20,15 +20,12 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
-import freemarker.template.Configuration;
-import freemarker.template.Template;
 import org.apache.camel.maven.packaging.model.ComponentModel;
 import org.apache.camel.maven.packaging.model.ComponentOptionModel;
 import org.apache.maven.model.Resource;
@@ -36,6 +33,7 @@ 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;
@@ -90,8 +88,10 @@ public class ReadmeComponentMojo extends AbstractMojo {
                 String json = loadComponentJson(jsonFiles, componentName);
                 if (json != null) {
                     ComponentModel model = generateComponentModel(componentName, json);
-                    String component = templateComponent(model);
-                    getLog().info(component);
+                    String header = templateComponentHeader(model);
+                    String options = templateComponentOptions(model);
+                    getLog().info(header);
+                    getLog().info(options);
                 }
             }
         }
@@ -134,9 +134,9 @@ public class ReadmeComponentMojo extends AbstractMojo {
         rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
 
         List<ComponentOptionModel> options = new ArrayList<ComponentOptionModel>();
-        ComponentOptionModel option = new ComponentOptionModel();
         for (Map<String, String> row : rows) {
-            option.setKey(getValue("key", row));
+            ComponentOptionModel option = new ComponentOptionModel();
+            option.setKey(getValue("name", row));
             option.setKind(getValue("kind", row));
             option.setType(getValue("type", row));
             option.setJavaType(getValue("javaType", row));
@@ -144,25 +144,28 @@ public class ReadmeComponentMojo extends AbstractMojo {
             option.setDescription(getValue("description", row));
             options.add(option);
         }
-
         component.setOptions(options);
 
         return component;
     }
 
-    private String templateComponent(ComponentModel model) throws MojoExecutionException {
-
+    private String templateComponentHeader(ComponentModel model) throws MojoExecutionException {
         try {
-            String ftl = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("component-header.ftl"));
-            Template template = new Template("header", ftl, new Configuration());
-
-            StringWriter buffer = new StringWriter();
-            template.process(model, buffer);
-            buffer.flush();
+            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);
+        }
+    }
 
-            return buffer.toString();
+    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 freemarker template. Readon: " + e, e);
+            throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
deleted file mode 100644
index 4d7d47c..0000000
--- a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
+++ /dev/null
@@ -1,22 +0,0 @@
-Welcome to ${title}
-
-${description}
-
-The syntax:
-
-    ${syntax}
-
-Maven users would need to add dependency:
-
-```xml
-    <dependency>
-      <groupId>${groupId}</groupId>
-      <artifactId>${artifactId}</artifactId>
-      <version>${version}</version>
-    </dependency>
-```
-
-Some more bla bla
-
-There are ${this.options} options which are listed below
-

http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.mvel
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.mvel
new file mode 100644
index 0000000..e191135
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.mvel
@@ -0,0 +1,20 @@
+Welcome to @{title}
+
+@{description}
+
+The syntax:
+
+    @{syntax}
+
+Maven users would need to add dependency:
+
+```xml
+    <dependency>
+      <groupId>${groupId}</groupId>
+      <artifactId>${artifactId}</artifactId>
+      <version>${version}</version>
+    </dependency>
+```
+
+Some more bla bla
+

http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
deleted file mode 100644
index 615c2ad..0000000
--- a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
+++ /dev/null
@@ -1,4 +0,0 @@
-Component Options
-
-Generate a table of options
-

http://git-wip-us.apache.org/repos/asf/camel/blob/4b335a18/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
new file mode 100644
index 0000000..cd895c5
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
@@ -0,0 +1,8 @@
+### Component options
+
+The @{title} component supports @{options.size()} options which are listed below:
+
+| Key | Description |
+| --- | ----------- |
+@foreach{row : options}| @{row.key} | @{row.description} |
+@end{}


[3/5] camel git commit: First cut of mvn goal to generate/update component readme.md file

Posted by da...@apache.org.
First cut of mvn goal to generate/update component readme.md file


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/973af27e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/973af27e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/973af27e

Branch: refs/heads/master
Commit: 973af27e3d4d366c57f15202f6f5f5199f3babd9
Parents: 1001f1a
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 30 09:03:23 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 26 19:45:24 2016 +0100

----------------------------------------------------------------------
 .../maven/camel-package-maven-plugin/pom.xml    |   6 +
 .../camel/maven/packaging/JSonSchemaHelper.java |   8 +
 .../maven/packaging/ReadmeComponentMojo.java    |  76 +++++++---
 .../maven/packaging/model/ComponentModel.java   | 149 +++++++++++++++++++
 .../packaging/model/ComponentOptionModel.java   |  75 ++++++++++
 .../src/main/resources/component-header.ftl     |  22 +++
 .../src/main/resources/component-options.ftl    |   4 +
 7 files changed, 318 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/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 1129663..68920e9 100644
--- a/tooling/maven/camel-package-maven-plugin/pom.xml
+++ b/tooling/maven/camel-package-maven-plugin/pom.xml
@@ -44,6 +44,12 @@
   <dependencies>
 
     <dependency>
+      <groupId>org.freemarker</groupId>
+      <artifactId>freemarker</artifactId>
+      <version>${freemarker-version}</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/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 9b1c1a2..ea17772 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
@@ -122,4 +122,12 @@ public final class JSonSchemaHelper {
         return null;
     }
 
+    public static String getValue(String key, Map<String, String> rows) {
+        String value = rows.get(key);
+        if (value != null) {
+            return value;
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/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 e1c2f23..59c5f6d 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
@@ -20,13 +20,17 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.OutputStream;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.camel.maven.packaging.model.ComponentModel;
+import org.apache.camel.maven.packaging.model.ComponentOptionModel;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -85,7 +89,9 @@ public class ReadmeComponentMojo extends AbstractMojo {
             for (String componentName : componentNames) {
                 String json = loadComponentJson(jsonFiles, componentName);
                 if (json != null) {
-                    updateReadMeFile(readmeFile, componentName, json);
+                    ComponentModel model = generateComponentModel(componentName, json);
+                    String component = templateComponent(model);
+                    getLog().info(component);
                 }
             }
         }
@@ -108,29 +114,55 @@ public class ReadmeComponentMojo extends AbstractMojo {
         return null;
     }
 
-    private void updateReadMeFile(File readmeFile, String componentName, String json) throws MojoExecutionException {
-        // TODO: use some template like velocity or freemarker
-
+    private ComponentModel generateComponentModel(String componentName, String json) {
         List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
-        String scheme = getValue("scheme", rows);
-        String syntax = getValue("syntax", rows);
-        String title = getValue("title", rows);
-        String description = getValue("description", rows);
-        String label = getValue("label", rows);
-        String groupId = getValue("groupId", rows);
-        String artifactId = getValue("artifactId", rows);
-        String version = getValue("version", rows);
+
+        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));
+
+        rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
+
+        List<ComponentOptionModel> options = new ArrayList<ComponentOptionModel>();
+        ComponentOptionModel option = new ComponentOptionModel();
+        for (Map<String, String> row : rows) {
+            option.setKey(getValue("key", 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);
+        }
+
+        component.setOptions(options);
+
+        return component;
+    }
+
+    private String templateComponent(ComponentModel model) throws MojoExecutionException {
 
         try {
-            OutputStream os = buildContext.newFileOutputStream(readmeFile);
-            os.write("##".getBytes());
-            os.write(title.getBytes());
-            os.write("\n\n".getBytes());
-            os.write(description.getBytes());
-            os.write("\n\n".getBytes());
-            os.close();
-        } catch (IOException e) {
-            throw new MojoExecutionException("Failed to update " + readmeFile + " file. Reason: " + e, e);
+            String ftl = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("component-header.ftl"));
+            Template template = new Template("header", ftl, new Configuration());
+
+            StringWriter buffer = new StringWriter();
+            template.process(model, buffer);
+            buffer.flush();
+
+            return buffer.toString();
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error processing freemarker template. Readon: " + e, e);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/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
new file mode 100644
index 0000000..7e689dd
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
@@ -0,0 +1,149 @@
+/**
+ * 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
+ * <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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven.packaging.model;
+
+import java.util.List;
+
+public class ComponentModel {
+
+    private String kind;
+    private String scheme;
+    private String syntax;
+    private String title;
+    private String description;
+    private String label;
+    private String deprecated;
+    private String consumerOnly;
+    private String producerOnly;
+    private String javaType;
+    private String groupId;
+    private String artifactId;
+    private String version;
+    private List<ComponentOptionModel> options;
+
+    public String getKind() {
+        return kind;
+    }
+
+    public void setKind(String kind) {
+        this.kind = kind;
+    }
+
+    public String getScheme() {
+        return scheme;
+    }
+
+    public void setScheme(String scheme) {
+        this.scheme = scheme;
+    }
+
+    public String getSyntax() {
+        return syntax;
+    }
+
+    public void setSyntax(String syntax) {
+        this.syntax = syntax;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public String getDeprecated() {
+        return deprecated;
+    }
+
+    public void setDeprecated(String deprecated) {
+        this.deprecated = deprecated;
+    }
+
+    public String getConsumerOnly() {
+        return consumerOnly;
+    }
+
+    public void setConsumerOnly(String consumerOnly) {
+        this.consumerOnly = consumerOnly;
+    }
+
+    public String getProducerOnly() {
+        return producerOnly;
+    }
+
+    public void setProducerOnly(String producerOnly) {
+        this.producerOnly = producerOnly;
+    }
+
+    public String getJavaType() {
+        return javaType;
+    }
+
+    public void setJavaType(String javaType) {
+        this.javaType = javaType;
+    }
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public List<ComponentOptionModel> getOptions() {
+        return options;
+    }
+
+    public void setOptions(List<ComponentOptionModel> options) {
+        this.options = options;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/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
new file mode 100644
index 0000000..31df0dd
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java
@@ -0,0 +1,75 @@
+/**
+ * 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
+ * <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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven.packaging.model;
+
+public class ComponentOptionModel {
+
+    private String key;
+    private String kind;
+    private String type;
+    private String javaType;
+    private String deprecated;
+    private String description;
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getKind() {
+        return kind;
+    }
+
+    public void setKind(String kind) {
+        this.kind = kind;
+    }
+
+    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 getDeprecated() {
+        return deprecated;
+    }
+
+    public void setDeprecated(String deprecated) {
+        this.deprecated = deprecated;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
new file mode 100644
index 0000000..4d7d47c
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-header.ftl
@@ -0,0 +1,22 @@
+Welcome to ${title}
+
+${description}
+
+The syntax:
+
+    ${syntax}
+
+Maven users would need to add dependency:
+
+```xml
+    <dependency>
+      <groupId>${groupId}</groupId>
+      <artifactId>${artifactId}</artifactId>
+      <version>${version}</version>
+    </dependency>
+```
+
+Some more bla bla
+
+There are ${this.options} options which are listed below
+

http://git-wip-us.apache.org/repos/asf/camel/blob/973af27e/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
new file mode 100644
index 0000000..615c2ad
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.ftl
@@ -0,0 +1,4 @@
+Component Options
+
+Generate a table of options
+


[5/5] camel git commit: First cut of mvn goal to generate/update component readme.md file. Switch to mvel which is easier to use than freemarker.

Posted by da...@apache.org.
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 <da...@apache.org>
Authored: Tue Jan 26 19:44:09 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
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{}


[2/5] camel git commit: First cut of mvn goal to generate/update component readme.md file

Posted by da...@apache.org.
First cut of mvn goal to generate/update component readme.md file


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1001f1ae
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1001f1ae
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1001f1ae

Branch: refs/heads/master
Commit: 1001f1aeec52702e16c6a957480a2c06748bde03
Parents: 07bdbad
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Dec 29 12:37:20 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 26 19:45:16 2016 +0100

----------------------------------------------------------------------
 .../camel/maven/packaging/JSonSchemaHelper.java |  10 ++
 .../maven/packaging/ReadmeComponentMojo.java    | 113 +++++++++++++++++--
 2 files changed, 113 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1001f1ae/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 9b6732e..9b1c1a2 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,4 +112,14 @@ public final class JSonSchemaHelper {
         return value;
     }
 
+    public static String getValue(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;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1001f1ae/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 8ecfe7d..e1c2f23 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
@@ -17,16 +17,26 @@
 package org.apache.camel.maven.packaging;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
+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.sonatype.plexus.build.incremental.BuildContext;
 
+import static org.apache.camel.maven.packaging.JSonSchemaHelper.getValue;
+import static org.apache.camel.maven.packaging.PackageHelper.loadText;
+
 /**
  * Generate or updates the component readme.md file in the project root directort.
  *
@@ -61,6 +71,98 @@ public class ReadmeComponentMojo extends AbstractMojo {
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
+        // find the component names
+        List<String> componentNames = findComponentNames();
+
+        final Set<File> jsonFiles = new TreeSet<File>();
+        PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
+
+        // only if there is components we should create/update the readme file
+        if (!componentNames.isEmpty()) {
+            getLog().info("Found " + componentNames.size() + " components");
+            File readmeFile = initReadMeFile();
+
+            for (String componentName : componentNames) {
+                String json = loadComponentJson(jsonFiles, componentName);
+                if (json != null) {
+                    updateReadMeFile(readmeFile, componentName, json);
+                }
+            }
+        }
+    }
+
+    private String loadComponentJson(Set<File> jsonFiles, String componentName) {
+        try {
+            for (File file : jsonFiles) {
+                if (file.getName().equals(componentName + ".json")) {
+                    String json = loadText(new FileInputStream(file));
+                    boolean isComponent = json.contains("\"kind\": \"component\"");
+                    if (isComponent) {
+                        return json;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            // ignore
+        }
+        return null;
+    }
+
+    private void updateReadMeFile(File readmeFile, String componentName, String json) throws MojoExecutionException {
+        // TODO: use some template like velocity or freemarker
+
+        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
+        String scheme = getValue("scheme", rows);
+        String syntax = getValue("syntax", rows);
+        String title = getValue("title", rows);
+        String description = getValue("description", rows);
+        String label = getValue("label", rows);
+        String groupId = getValue("groupId", rows);
+        String artifactId = getValue("artifactId", rows);
+        String version = getValue("version", rows);
+
+        try {
+            OutputStream os = buildContext.newFileOutputStream(readmeFile);
+            os.write("##".getBytes());
+            os.write(title.getBytes());
+            os.write("\n\n".getBytes());
+            os.write(description.getBytes());
+            os.write("\n\n".getBytes());
+            os.close();
+        } catch (IOException e) {
+            throw new MojoExecutionException("Failed to update " + readmeFile + " file. Reason: " + e, e);
+        }
+    }
+
+    private List<String> findComponentNames() {
+        List<String> componentNames = new ArrayList<String>();
+        for (Resource r : project.getBuild().getResources()) {
+            File f = new File(r.getDirectory());
+            if (!f.exists()) {
+                f = new File(project.getBasedir(), r.getDirectory());
+            }
+            f = new File(f, "META-INF/services/org/apache/camel/component");
+
+            if (f.exists() && f.isDirectory()) {
+                File[] files = f.listFiles();
+                if (files != null) {
+                    for (File file : files) {
+                        // skip directories as there may be a sub .resolver directory
+                        if (file.isDirectory()) {
+                            continue;
+                        }
+                        String name = file.getName();
+                        if (name.charAt(0) != '.') {
+                            componentNames.add(name);
+                        }
+                    }
+                }
+            }
+        }
+        return componentNames;
+    }
+
+    private File initReadMeFile() throws MojoExecutionException {
         File readmeDir = new File(buildDir, "..");
         File readmeFile = new File(readmeDir, "readme.md");
 
@@ -82,16 +184,7 @@ public class ReadmeComponentMojo extends AbstractMojo {
             getLog().info("Creating new readme.md file");
         }
 
-        try {
-            OutputStream os = buildContext.newFileOutputStream(readmeFile);
-            os.write("Hello World".getBytes());
-            os.close();
-
-        } catch (IOException e) {
-            throw new MojoExecutionException("Failed to write to " + readmeFile + ". Reason: " + e, e);
-        }
-
+        return readmeFile;
     }
 
-
 }