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 2019/10/10 07:07:49 UTC

[camel-quarkus] 02/06: Reorder

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch fix245
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit b264232bd83693ddf9171d86bc6468ea68fc95d5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Oct 9 12:24:12 2019 +0200

    Reorder
---
 .../quarkus/maven/UpdateDocExtensionsListMojo.java | 237 +++++++++++----------
 1 file changed, 122 insertions(+), 115 deletions(-)

diff --git a/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java
index 0cf24b4..b9d1148 100644
--- a/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java
+++ b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java
@@ -89,10 +89,16 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
     protected File othersDir;
 
     /**
-     * The directory for components
+     * The directory for extensions
      */
     @Parameter(defaultValue = "${project.directory}/../../../extensions")
-    protected File readmeComponentsDir;
+    protected File readmeExtensionsDir;
+
+    /**
+     * The website doc for extensions
+     */
+    @Parameter(defaultValue = "${project.directory}/../../../docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc")
+    protected File websiteDocFile;
 
     /**
      * Maven ProjectHelper.
@@ -109,65 +115,12 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
      */
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
-        // update readme file in extensions
         executeComponentsReadme();
-        executeLanguagesReadme();
         executeDataFormatsReadme();
+        executeLanguagesReadme();
         executeOthersReadme();
     }
 
-    protected void executeOthersReadme() throws MojoExecutionException, MojoFailureException {
-        Set<File> otherFiles = new TreeSet<>();
-
-        if (othersDir != null && othersDir.isDirectory()) {
-            File[] files = othersDir.listFiles();
-            if (files != null) {
-                otherFiles.addAll(Arrays.asList(files));
-            }
-        }
-
-        try {
-            List<OtherModel> others = new ArrayList<>();
-            for (File file : otherFiles) {
-                String json = loadText(new FileInputStream(file));
-                OtherModel model = generateOtherModel(json);
-                others.add(model);
-            }
-
-            // sort the models
-            Collections.sort(others, new OtherComparator());
-
-            // how many different artifacts
-            int count = others.stream()
-                    .map(OtherModel::getArtifactId)
-                    .collect(toSet()).size();
-
-            // how many deprecated
-            long deprecated = others.stream()
-                    .filter(o -> "true".equals(o.getDeprecated()))
-                    .count();
-
-            // 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 = templateOthers(others, count, deprecated);
-            boolean updated = updateOthers(file, changed);
-
-            if (updated) {
-                getLog().info("Updated readme.adoc file: " + file);
-            } else if (exists) {
-                getLog().debug("No changes to readme.adoc file: " + file);
-            } else {
-                getLog().warn("No readme.adoc file: " + file);
-            }
-
-        } catch (IOException e) {
-            throw new MojoFailureException("Error due " + e.getMessage(), e);
-        }
-    }
-
     protected void executeComponentsReadme() throws MojoExecutionException, MojoFailureException {
         Set<File> componentFiles = new TreeSet<>();
 
@@ -224,7 +177,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
 
             // update the big readme file in the core/components dir
             File file;
-            file = new File(readmeComponentsDir, "readme.adoc");
+            file = new File(readmeExtensionsDir, "readme.adoc");
 
             // update regular components
             boolean exists = file.exists();
@@ -273,8 +226,8 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
 
             // how many different artifacts
             int count = models.stream()
-                        .map(DataFormatModel::getArtifactId)
-                        .collect(toSet()).size();
+                    .map(DataFormatModel::getArtifactId)
+                    .collect(toSet()).size();
 
             // how many deprecated
             long deprecated = models.stream()
@@ -289,7 +242,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
 
             // update the big readme file in the core/components dir
             File file;
-            file = new File(readmeComponentsDir, "readme.adoc");
+            file = new File(readmeExtensionsDir, "readme.adoc");
 
             // update regular data formats
             boolean exists = file.exists();
@@ -348,7 +301,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
 
             // update the big readme file in the core/components dir
             File file;
-            file = new File(readmeComponentsDir, "readme.adoc");
+            file = new File(readmeExtensionsDir, "readme.adoc");
 
             // update regular data formats
             boolean exists = file.exists();
@@ -368,6 +321,58 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
+    protected void executeOthersReadme() throws MojoExecutionException, MojoFailureException {
+        Set<File> otherFiles = new TreeSet<>();
+
+        if (othersDir != null && othersDir.isDirectory()) {
+            File[] files = othersDir.listFiles();
+            if (files != null) {
+                otherFiles.addAll(Arrays.asList(files));
+            }
+        }
+
+        try {
+            List<OtherModel> others = new ArrayList<>();
+            for (File file : otherFiles) {
+                String json = loadText(new FileInputStream(file));
+                OtherModel model = generateOtherModel(json);
+                others.add(model);
+            }
+
+            // sort the models
+            Collections.sort(others, new OtherComparator());
+
+            // how many different artifacts
+            int count = others.stream()
+                    .map(OtherModel::getArtifactId)
+                    .collect(toSet()).size();
+
+            // how many deprecated
+            long deprecated = others.stream()
+                    .filter(o -> "true".equals(o.getDeprecated()))
+                    .count();
+
+            // update the big readme file in the components dir
+            File file = new File(readmeExtensionsDir, "readme.adoc");
+
+            // update regular components
+            boolean exists = file.exists();
+            String changed = templateOthers(others, count, deprecated);
+            boolean updated = updateOthers(file, changed);
+
+            if (updated) {
+                getLog().info("Updated readme.adoc file: " + file);
+            } else if (exists) {
+                getLog().debug("No changes to readme.adoc file: " + file);
+            } else {
+                getLog().warn("No readme.adoc file: " + file);
+            }
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error due " + e.getMessage(), e);
+        }
+    }
+
     private String templateComponents(List<ComponentModel> models, int artifacts, long deprecated) throws MojoExecutionException {
         try {
             String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-components.mvel"));
@@ -382,11 +387,11 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private String templateOthers(List<OtherModel> models, int artifacts, long deprecated) throws MojoExecutionException {
+    private String templateDataFormats(List<DataFormatModel> models, int artifacts, long deprecated) throws MojoExecutionException {
         try {
-            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-others.mvel"));
+            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-dataformats.mvel"));
             Map<String, Object> map = new HashMap<>();
-            map.put("others", models);
+            map.put("dataformats", models);
             map.put("numberOfArtifacts", artifacts);
             map.put("numberOfDeprecated", deprecated);
             String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE));
@@ -396,11 +401,11 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private String templateDataFormats(List<DataFormatModel> models, int artifacts, long deprecated) throws MojoExecutionException {
+    private String templateLanguages(List<LanguageModel> models, int artifacts, long deprecated) throws MojoExecutionException {
         try {
-            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-dataformats.mvel"));
+            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-languages.mvel"));
             Map<String, Object> map = new HashMap<>();
-            map.put("dataformats", models);
+            map.put("languages", models);
             map.put("numberOfArtifacts", artifacts);
             map.put("numberOfDeprecated", deprecated);
             String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE));
@@ -410,11 +415,11 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private String templateLanguages(List<LanguageModel> models, int artifacts, long deprecated) throws MojoExecutionException {
+    private String templateOthers(List<OtherModel> models, int artifacts, long deprecated) throws MojoExecutionException {
         try {
-            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-languages.mvel"));
+            String template = loadText(UpdateDocExtensionsListMojo.class.getClassLoader().getResourceAsStream("readme-others.mvel"));
             Map<String, Object> map = new HashMap<>();
-            map.put("languages", models);
+            map.put("others", models);
             map.put("numberOfArtifacts", artifacts);
             map.put("numberOfDeprecated", deprecated);
             String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE));
@@ -458,7 +463,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private boolean updateOthers(File file, String changed) throws MojoExecutionException {
+    private boolean updateDataFormats(File file, String changed) throws MojoExecutionException {
         if (!file.exists()) {
             return false;
         }
@@ -466,7 +471,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         try {
             String text = loadText(new FileInputStream(file));
 
-            String existing = StringHelper.between(text, "// others: START", "// others: END");
+            String existing = StringHelper.between(text, "// dataformats: START", "// dataformats: END");
             if (existing != null) {
                 // remove leading line breaks etc
                 existing = existing.trim();
@@ -474,17 +479,17 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
                 if (existing.equals(changed)) {
                     return false;
                 } else {
-                    String before = StringHelper.before(text, "// others: START");
-                    String after = StringHelper.after(text, "// others: END");
-                    text = before + "// others: START\n" + changed + "\n// others: END" + after;
+                    String before = StringHelper.before(text, "// dataformats: START");
+                    String after = StringHelper.after(text, "// dataformats: END");
+                    text = before + "// dataformats: START\n" + changed + "\n// dataformats: END" + after;
                     writeText(file, text);
                     return true;
                 }
             } else {
                 getLog().warn("Cannot find markers in file " + file);
                 getLog().warn("Add the following markers");
-                getLog().warn("\t// others: START");
-                getLog().warn("\t// others: END");
+                getLog().warn("\t// dataformats: START");
+                getLog().warn("\t// dataformats: END");
                 return false;
             }
         } catch (Exception e) {
@@ -492,7 +497,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private boolean updateDataFormats(File file, String changed) throws MojoExecutionException {
+    private boolean updateLanguages(File file, String changed) throws MojoExecutionException {
         if (!file.exists()) {
             return false;
         }
@@ -500,7 +505,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         try {
             String text = loadText(new FileInputStream(file));
 
-            String existing = StringHelper.between(text, "// dataformats: START", "// dataformats: END");
+            String existing = StringHelper.between(text, "// languages: START", "// languages: END");
             if (existing != null) {
                 // remove leading line breaks etc
                 existing = existing.trim();
@@ -508,17 +513,17 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
                 if (existing.equals(changed)) {
                     return false;
                 } else {
-                    String before = StringHelper.before(text, "// dataformats: START");
-                    String after = StringHelper.after(text, "// dataformats: END");
-                    text = before + "// dataformats: START\n" + changed + "\n// dataformats: END" + after;
+                    String before = StringHelper.before(text, "// languages: START");
+                    String after = StringHelper.after(text, "// languages: END");
+                    text = before + "// languages: START\n" + changed + "\n// languages: END" + 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");
+                getLog().warn("\t// languages: START");
+                getLog().warn("\t// languages: END");
                 return false;
             }
         } catch (Exception e) {
@@ -526,7 +531,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private boolean updateLanguages(File file, String changed) throws MojoExecutionException {
+    private boolean updateOthers(File file, String changed) throws MojoExecutionException {
         if (!file.exists()) {
             return false;
         }
@@ -534,7 +539,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         try {
             String text = loadText(new FileInputStream(file));
 
-            String existing = StringHelper.between(text, "// languages: START", "// languages: END");
+            String existing = StringHelper.between(text, "// others: START", "// others: END");
             if (existing != null) {
                 // remove leading line breaks etc
                 existing = existing.trim();
@@ -542,17 +547,17 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
                 if (existing.equals(changed)) {
                     return false;
                 } else {
-                    String before = StringHelper.before(text, "// languages: START");
-                    String after = StringHelper.after(text, "// languages: END");
-                    text = before + "// languages: START\n" + changed + "\n// languages: END" + after;
+                    String before = StringHelper.before(text, "// others: START");
+                    String after = StringHelper.after(text, "// others: END");
+                    text = before + "// others: START\n" + changed + "\n// others: END" + 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");
+                getLog().warn("\t// others: START");
+                getLog().warn("\t// others: END");
                 return false;
             }
         } catch (Exception e) {
@@ -569,31 +574,33 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         }
     }
 
-    private static class OtherComparator implements Comparator<OtherModel> {
+    private static class DataFormatComparator implements Comparator<DataFormatModel> {
 
         @Override
-        public int compare(OtherModel o1, OtherModel o2) {
+        public int compare(DataFormatModel o1, DataFormatModel o2) {
             // lets sort by title
             return o1.getTitle().compareToIgnoreCase(o2.getTitle());
         }
     }
 
-    private static class DataFormatComparator implements Comparator<DataFormatModel> {
+    private static class LanguageComparator implements Comparator<LanguageModel> {
 
         @Override
-        public int compare(DataFormatModel o1, DataFormatModel o2) {
+        public int compare(LanguageModel o1, LanguageModel o2) {
             // lets sort by title
             return o1.getTitle().compareToIgnoreCase(o2.getTitle());
         }
+
     }
 
-    private static class LanguageComparator implements Comparator<LanguageModel> {
+    private static class OtherComparator implements Comparator<OtherModel> {
 
         @Override
-        public int compare(LanguageModel o1, LanguageModel o2) {
+        public int compare(OtherModel o1, OtherModel o2) {
             // lets sort by title
             return o1.getTitle().compareToIgnoreCase(o2.getTitle());
         }
+
     }
 
     private ComponentModel generateComponentModel(String json) {
@@ -620,24 +627,6 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         return component;
     }
 
-    private OtherModel generateOtherModel(String json) {
-        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", json, false);
-
-        OtherModel other = new OtherModel();
-        other.setName(JSonSchemaHelper.getSafeValue("name", rows));
-        other.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
-        other.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
-        other.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
-        other.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
-        other.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
-        other.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows));
-        other.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
-        other.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
-        other.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
-
-        return other;
-    }
-
     private DataFormatModel generateDataFormatModel(String json) {
         List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false);
 
@@ -678,4 +667,22 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo {
         return language;
     }
 
+    private OtherModel generateOtherModel(String json) {
+        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", json, false);
+
+        OtherModel other = new OtherModel();
+        other.setName(JSonSchemaHelper.getSafeValue("name", rows));
+        other.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
+        other.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
+        other.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
+        other.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
+        other.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
+        other.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows));
+        other.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
+        other.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
+        other.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
+
+        return other;
+    }
+
 }