camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9541: Add language to that readme also
Date Thu, 18 Aug 2016 15:00:35 GMT
Repository: camel
Updated Branches:
  refs/heads/master 4a9c20af2 -> ab299d7db


CAMEL-9541: Add language 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/ab299d7d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ab299d7d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ab299d7d

Branch: refs/heads/master
Commit: ab299d7db54b7cb3cb833687b40467e6c516c6cd
Parents: 4a9c20a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Aug 18 17:00:27 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Aug 18 17:00:27 2016 +0200

----------------------------------------------------------------------
 components/readme.adoc                          |  45 ++++++-
 .../maven/packaging/PrepareReadmeMojo.java      | 124 ++++++++++++++++++-
 .../maven/packaging/PrepareUserGuideMojo.java   |   1 -
 .../src/main/resources/readme-dataformats.mvel  |   2 +-
 .../src/main/resources/readme-languages.mvel    |  10 ++
 5 files changed, 177 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ab299d7d/components/readme.adoc
----------------------------------------------------------------------
diff --git a/components/readme.adoc b/components/readme.adoc
index 4f51773..205ecc9 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -546,10 +546,11 @@ Data Formats
 
 
 
+
 // dataformats: START
 [width="100%",cols="4,6",options="header"]
 |=======================================================================
-| DataFormat | Description
+| Data Format | Description
 
 | link:camel-avro[Avro] (camel-avro) | Camel Avro data format
 
@@ -636,3 +637,45 @@ Data Formats
 // dataformats: END
 
 
+
+Expression Languages
+^^^^^^^^^^^^^^^^^^^^
+
+
+// languages: START
+[width="100%",cols="4,6",options="header"]
+|=======================================================================
+| Language | Description
+
+| link:camel-juel[EL] (camel-juel) | For EL expressions and predicates
+
+| link:camel-groovy[Groovy] (camel-groovy) | For Groovy expressions and predicates
+
+| link:camel-hl7[HL7 Terser] (camel-hl7) | For HL7 terser expressions and predicates
+
+| link:camel-script[JavaScript] (camel-script) | For JavaScript expressions and predicates
+
+| link:camel-jsonpath[JSonPath] (camel-jsonpath) | For JSonPath expressions and predicates
+
+| link:camel-jxpath[JXPath] (camel-jxpath) | For JXPath expressions and predicates
+
+| link:camel-mvel[MVEL] (camel-mvel) | For MVEL expressions and predicates
+
+| link:camel-ognl[OGNL] (camel-ognl) | For OGNL expressions and predicates
+
+| link:camel-script[PHP] (camel-script) | For PHP expressions and predicates
+
+| link:camel-script[Python] (camel-script) | For Python expressions and predicates
+
+| link:camel-script[Ruby] (camel-script) | For Ruby expressions and predicates
+
+| link:camel-spring[SpEL] (camel-spring) | For Spring Expression Language (SpEL) expressions
and predicates
+
+| link:camel-josql[SQL] (camel-josql) | For SQL expressions and predicates
+
+| link:camel-saxon[XQuery] (camel-saxon) | For XQuery expressions and predicates
+|=======================================================================
+// languages: END
+
+
+

http://git-wip-us.apache.org/repos/asf/camel/blob/ab299d7d/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 1d86364..b45ef75 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,6 +31,7 @@ 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;
@@ -110,6 +111,7 @@ public class PrepareReadmeMojo extends AbstractMojo {
     public void execute() throws MojoExecutionException, MojoFailureException {
         executeComponentsReadme();
         executeDataFormatsReadme();
+        executeLanguagesReadme();
     }
 
     protected void executeComponentsReadme() throws MojoExecutionException, MojoFailureException
{
@@ -223,6 +225,56 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    protected void executeLanguagesReadme() throws MojoExecutionException, MojoFailureException
{
+        Set<File> languageFiles = new TreeSet<>();
+
+        if (languagesDir != null && languagesDir.isDirectory()) {
+            File[] files = languagesDir.listFiles();
+            if (files != null) {
+                languageFiles.addAll(Arrays.asList(files));
+            }
+        }
+
+        try {
+            List<LanguageModel> models = new ArrayList<>();
+            for (File file : languageFiles) {
+                String json = loadText(new FileInputStream(file));
+                LanguageModel model = generateLanguageModel(json);
+                models.add(model);
+            }
+
+            // sor the models
+            Collections.sort(models, new LanguageComparator());
+
+            // filter out camel-core
+            List<LanguageModel> languages = new ArrayList<>();
+            for (LanguageModel model : models) {
+                if (!"camel-core".equals(model.getArtifactId())) {
+                    languages.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 = templateLanguages(languages);
+            boolean updated = updateLanguages(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"));
@@ -247,6 +299,18 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    private String templateLanguages(List<LanguageModel> models) throws MojoExecutionException
{
+        try {
+            String template = loadText(ReadmeComponentMojo.class.getClassLoader().getResourceAsStream("readme-languages.mvel"));
+            Map<String, Object> map = new HashMap<>();
+            map.put("languages", 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;
@@ -315,9 +379,38 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
-    private static String link(ComponentModel model) {
+    private boolean updateLanguages(File file, String changed) throws MojoExecutionException
{
+        if (!file.exists()) {
+            return false;
+        }
+
+        try {
+            String text = loadText(new FileInputStream(file));
 
-        return "[" + model.getTitle() + "](" + model.getScheme() + "-component.adoc)";
+            String existing = StringHelper.between(text, "// languages: START" , "// languages:
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, "// languages: START");
+                    String after = StringHelper.after(text, "// languages: END");
+                    text = before + "\n// languages: START\n" + changed + "\n// languages:
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// languages: START");
+                getLog().warn("\t// languages: END");
+                return false;
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error reading file " + file + " Reason: " +
e, e);
+        }
     }
 
     private static class ComponentComparator implements Comparator<ComponentModel>
{
@@ -338,6 +431,15 @@ public class PrepareReadmeMojo extends AbstractMojo {
         }
     }
 
+    private static class LanguageComparator implements Comparator<LanguageModel> {
+
+        @Override
+        public int compare(LanguageModel o1, LanguageModel 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);
 
@@ -378,4 +480,22 @@ public class PrepareReadmeMojo extends AbstractMojo {
         return dataFormat;
     }
 
+    private LanguageModel generateLanguageModel(String json) {
+        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language",
json, false);
+
+        LanguageModel language = new LanguageModel();
+        language.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
+        language.setName(JSonSchemaHelper.getSafeValue("name", rows));
+        language.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows));
+        language.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
+        language.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
+        language.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
+        language.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
+        language.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
+        language.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
+        language.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
+
+        return language;
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ab299d7d/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareUserGuideMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareUserGuideMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareUserGuideMojo.java
index 4c6435e..44c46ce 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareUserGuideMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareUserGuideMojo.java
@@ -505,5 +505,4 @@ public class PrepareUserGuideMojo extends AbstractMojo {
         return language;
     }
 
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ab299d7d/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
index 3c5bd58..9863e25 100644
--- 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
@@ -2,7 +2,7 @@
 
 [width="100%",cols="4,6",options="header"]
 |=======================================================================
-| DataFormat | Description
+| Data Format | Description
 @foreach{row : dataformats}
 | link:@{row.artifactId}[@{row.title}] (@{row.artifactId}) | @{row.description}
 @end{}|=======================================================================

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


Mime
View raw message