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/08/18 14:53:44 UTC

[2/2] camel git commit: CAMEL-9541: Add dataformat to that readme also

CAMEL-9541: Add dataformat to that readme also


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

Branch: refs/heads/master
Commit: 4a9c20af292cbee681e353835145b907136b7e6b
Parents: 4e0423f
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Aug 18 16:53:35 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Aug 18 16:53:35 2016 +0200

----------------------------------------------------------------------
 components/readme.adoc                          |  96 ++++++++++++--
 .../maven/packaging/PrepareReadmeMojo.java      | 132 ++++++++++++++++++-
 .../src/main/resources/readme-dataformats.mvel  |  10 ++
 3 files changed, 221 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4a9c20af/components/readme.adoc
----------------------------------------------------------------------
diff --git a/components/readme.adoc b/components/readme.adoc
index e912e7b..4f51773 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -1,18 +1,6 @@
 Components
 ^^^^^^^^^^
 
-
-
-
-
-
-
-
-
-
-
-
-
 // components: START
 [width="100%",cols="4,6",options="header"]
 |=======================================================================
@@ -553,14 +541,98 @@ Components
 // components: END
 
 
+Data Formats
+^^^^^^^^^^^^
+
+
+
+// dataformats: START
+[width="100%",cols="4,6",options="header"]
+|=======================================================================
+| DataFormat | Description
+
+| link:camel-avro[Avro] (camel-avro) | Camel Avro data format
+
+| link:camel-barcode[Barcode] (camel-barcode) | Camel Barcode (e.g. QRcode, PDF417, DataMatrix) support
+
+| link:camel-base64[Base64] (camel-base64) | Camel Base64 data format support
+
+| link:camel-beanio[BeanIO] (camel-beanio) | Camel BeanIO data format support
+
+| link:camel-bindy[Bindy CSV] (camel-bindy) | Camel Bindy data format support
+
+| link:camel-bindy[Bindy Fixed Length] (camel-bindy) | Camel Bindy data format support
+
+| link:camel-bindy[Bindy Key Value Pair] (camel-bindy) | Camel Bindy data format support
+
+| link:camel-boon[Boon] (camel-boon) | Camel Boon support
 
+| link:camel-castor[Castor] (camel-castor) | Camel Castor data format support
 
+| link:camel-crypto[Crypto (Java Cryptographic Extension)] (camel-crypto) | Camel Cryptographic Support
 
+| link:camel-csv[CSV] (camel-csv) | Camel CSV data format support
 
+| link:camel-flatpack[Flatpack] (camel-flatpack) | Camel FlatPack support
 
+| link:camel-hessian[Hessian] (camel-hessian) | Hessian serialization support
 
+| link:camel-hl7[HL7] (camel-hl7) | Camel HL7 support
 
+| link:camel-ical[iCal] (camel-ical) | Camel iCal component
 
+| link:camel-jacksonxml[JacksonXML] (camel-jacksonxml) | Camel Jackson XML support
 
+| link:camel-jaxb[JAXB] (camel-jaxb) | Camel JAXB support
+
+| link:camel-jibx[JiBX] (camel-jibx) | Camel Jibx support
+
+| link:camel-gson[JSon GSon] (camel-gson) | Camel Gson support
+
+| link:camel-jackson[JSon Jackson] (camel-jackson) | Camel Jackson support
+
+| link:camel-johnzon[JSon Johnzon] (camel-johnzon) | Camel Johnzon support
+
+| link:camel-xstream[JSon XStream] (camel-xstream) | Camel XStream support
+
+| link:camel-lzf[LZF Deflate Compression] (camel-lzf) | Camel LZF support
+
+| link:camel-mail[MIME Multipart] (camel-mail) | Camel Mail support
+
+| link:camel-crypto[PGP] (camel-crypto) | Camel Cryptographic Support
+
+| link:camel-protobuf[Protobuf] (camel-protobuf) | Camel Components
+
+| link:camel-rss[RSS] (camel-rss) | Camel RSS support
+
+| link:camel-soap[SOAP] (camel-soap) | Camel SOAP support
+
+| link:camel-syslog[Syslog] (camel-syslog) | Camel Syslog support
+
+| link:camel-tarfile[Tar File] (camel-tarfile) | Camel Tar file support
+
+| link:camel-tagsoup[TidyMarkup] (camel-tagsoup) | Camel TagSoup support
+
+| link:camel-univocity-parsers[uniVocity CSV] (camel-univocity-parsers) | Camel UniVocity parsers data format support
+
+| link:camel-univocity-parsers[uniVocity Fixed Length] (camel-univocity-parsers) | Camel UniVocity parsers data format support
+
+| link:camel-univocity-parsers[uniVocity TSV] (camel-univocity-parsers) | Camel UniVocity parsers data format support
+
+| link:camel-xmlbeans[XML Beans] (camel-xmlbeans) | Camel XMLBeans support
+
+| link:camel-xmljson[XML JSon] (camel-xmljson) | Camel XML JSON Data Format
+
+| link:camel-xmlrpc[XML RPC] (camel-xmlrpc) | Camel XML RPC support
+
+| link:camel-xmlsecurity[XML Security] (camel-xmlsecurity) | Camel Partial XML Encryption/Decryption and XML Signature support
+
+| link:camel-xstream[XStream] (camel-xstream) | Camel XStream support
+
+| link:camel-snakeyaml[YAML SnakeYAML] (camel-snakeyaml) | Camel SnakeYAML support
+
+| link:camel-zipfile[Zip File] (camel-zipfile) | Camel Zip file support
+|=======================================================================
+// dataformats: END
 
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4a9c20af/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java
index 1b08dea..1d86364 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java
@@ -31,13 +31,11 @@ import java.util.TreeSet;
 import edu.emory.mathcs.backport.java.util.Collections;
 import org.apache.camel.maven.packaging.model.ComponentModel;
 import org.apache.camel.maven.packaging.model.DataFormatModel;
-import org.apache.camel.maven.packaging.model.LanguageModel;
 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.apache.maven.project.MavenProjectHelper;
-import org.mvel2.conversion.ObjectCH;
 import org.mvel2.templates.TemplateRuntime;
 
 import static org.apache.camel.maven.packaging.PackageHelper.loadText;
@@ -111,6 +109,7 @@ public class PrepareReadmeMojo extends AbstractMojo {
      */
     public void execute() throws MojoExecutionException, MojoFailureException {
         executeComponentsReadme();
+        executeDataFormatsReadme();
     }
 
     protected void executeComponentsReadme() throws MojoExecutionException, MojoFailureException {
@@ -153,12 +152,12 @@ public class PrepareReadmeMojo extends AbstractMojo {
                 }
             }
 
-            // the summary file has the TOC
+            // update the big readme file in the components dir
             File file = new File(readmeComponentsDir, "readme.adoc");
 
             // update regular components
             boolean exists = file.exists();
-            String changed = templateComponentOptions(components);
+            String changed = templateComponents(components);
             boolean updated = updateComponents(file, changed);
 
             if (updated) {
@@ -174,7 +173,57 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
-    private String templateComponentOptions(List<ComponentModel> models) throws MojoExecutionException {
+    protected void executeDataFormatsReadme() throws MojoExecutionException, MojoFailureException {
+        Set<File> dataFormatFiles = new TreeSet<>();
+
+        if (dataFormatsDir != null && dataFormatsDir.isDirectory()) {
+            File[] files = dataFormatsDir.listFiles();
+            if (files != null) {
+                dataFormatFiles.addAll(Arrays.asList(files));
+            }
+        }
+
+        try {
+            List<DataFormatModel> models = new ArrayList<>();
+            for (File file : dataFormatFiles) {
+                String json = loadText(new FileInputStream(file));
+                DataFormatModel model = generateDataFormatModel(json);
+                models.add(model);
+            }
+
+            // sor the models
+            Collections.sort(models, new DataFormatComparator());
+
+            // filter out camel-core
+            List<DataFormatModel> dataFormats = new ArrayList<>();
+            for (DataFormatModel model : models) {
+                if (!"camel-core".equals(model.getArtifactId())) {
+                    dataFormats.add(model);
+                }
+            }
+
+            // update the big readme file in the components dir
+            File file = new File(readmeComponentsDir, "readme.adoc");
+
+            // update regular data formats
+            boolean exists = file.exists();
+            String changed = templateDataFormats(dataFormats);
+            boolean updated = updateDataFormats(file, changed);
+
+            if (updated) {
+                getLog().info("Updated components/readme.adoc file: " + file);
+            } else if (exists) {
+                getLog().debug("No changes to components/readme.adoc file: " + file);
+            } else {
+                getLog().warn("No components/readme.adoc file: " + file);
+            }
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error due " + e.getMessage(), e);
+        }
+    }
+
+    private String templateComponents(List<ComponentModel> models) throws MojoExecutionException {
         try {
             String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("readme-components.mvel"));
             Map<String, Object> map = new HashMap<>();
@@ -186,6 +235,18 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    private String templateDataFormats(List<DataFormatModel> models) throws MojoExecutionException {
+        try {
+            String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("readme-dataformats.mvel"));
+            Map<String, Object> map = new HashMap<>();
+            map.put("dataformats", models);
+            String out = (String) TemplateRuntime.eval(template, map);
+            return out;
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
+        }
+    }
+
     private boolean updateComponents(File file, String changed) throws MojoExecutionException {
         if (!file.exists()) {
             return false;
@@ -220,6 +281,40 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    private boolean updateDataFormats(File file, String changed) throws MojoExecutionException {
+        if (!file.exists()) {
+            return false;
+        }
+
+        try {
+            String text = loadText(new FileInputStream(file));
+
+            String existing = StringHelper.between(text, "// dataformats: START" , "// dataformats: END");
+            if (existing != null) {
+                // remove leading line breaks etc
+                existing = existing.trim();
+                changed = changed.trim();
+                if (existing.equals(changed)) {
+                    return false;
+                } else {
+                    String before = StringHelper.before(text, "// dataformats: START");
+                    String after = StringHelper.after(text, "// dataformats: END");
+                    text = before + "\n// dataformats: START\n" + changed + "\n// dataformats: END\n" + after;
+                    writeText(file, text);
+                    return true;
+                }
+            } else {
+                getLog().warn("Cannot find markers in file " + file);
+                getLog().warn("Add the following markers");
+                getLog().warn("\t// dataformats: START");
+                getLog().warn("\t// dataformats: END");
+                return false;
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
+        }
+    }
+
     private static String link(ComponentModel model) {
 
         return "[" + model.getTitle() + "](" + model.getScheme() + "-component.adoc)";
@@ -234,6 +329,15 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    private static class DataFormatComparator implements Comparator<DataFormatModel> {
+
+        @Override
+        public int compare(DataFormatModel o1, DataFormatModel o2) {
+            // lets sort by title
+            return o1.getTitle().compareToIgnoreCase(o2.getTitle());
+        }
+    }
+
     private ComponentModel generateComponentModel(String json) {
         List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
 
@@ -256,4 +360,22 @@ public class PrepareReadmeMojo extends AbstractMojo {
         return component;
     }
 
+    private DataFormatModel generateDataFormatModel(String json) {
+        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false);
+
+        DataFormatModel dataFormat = new DataFormatModel();
+        dataFormat.setName(JSonSchemaHelper.getSafeValue("name", rows));
+        dataFormat.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
+        dataFormat.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows));
+        dataFormat.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
+        dataFormat.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
+        dataFormat.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
+        dataFormat.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
+        dataFormat.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
+        dataFormat.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
+        dataFormat.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
+
+        return dataFormat;
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/4a9c20af/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel
new file mode 100644
index 0000000..3c5bd58
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel
@@ -0,0 +1,10 @@
+@if{!dataformats.isEmpty()}
+
+[width="100%",cols="4,6",options="header"]
+|=======================================================================
+| DataFormat | Description
+@foreach{row : dataformats}
+| link:@{row.artifactId}[@{row.title}] (@{row.artifactId}) | @{row.description}
+@end{}|=======================================================================
+
+@end{}
\ No newline at end of file