camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [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.
Date Tue, 26 Jan 2016 18:46:40 GMT
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 <davsclaus@apache.org>
Authored: Tue Jan 26 19:26:07 2016 +0100
Committer: Claus Ibsen <davsclaus@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{}


Mime
View raw message