camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-10774: Update summary automatic
Date Fri, 03 Feb 2017 20:05:15 GMT
CAMEL-10774: Update summary automatic


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

Branch: refs/heads/master
Commit: 5f566e09663eda5471fd488cb2c5ea20b20a151f
Parents: 705f02d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Feb 3 20:51:10 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Feb 3 20:51:10 2017 +0100

----------------------------------------------------------------------
 docs/user-manual/en/SUMMARY.md                  |  53 ++++++---
 .../maven/packaging/PrepareUserGuideMojo.java   | 117 +++++++++++++++++++
 2 files changed, 152 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5f566e09/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 1aca332..0637b36 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -321,25 +321,42 @@
 
 
 
-
+<!-- others: START -->
 * Other Components
-  * [BAM (Business Activity Monitoring)](bam.adoc)
-  * [CDI](cdi.adoc)
-  * [Eclipse](eclipse.adoc)
-  * [Grape](grape.adoc)
-  * [Guice](guice.adoc)
-  * [HawtDB](hawtdb.adoc)
-  * [Hystrix](hystrix.adoc)
-  * [LevelDB](leveldb.adoc)
-  * [Jasypt](jasypt.adoc)
-  * [Kura](kura.adoc)
-  * [Ribbon](ribbon.adoc)
-  * [RX](rx.adoc)
-  * [SCR](scr.adoc)
-  * [Shiro](shiro.adoc)
-  * [Swagger Java](swagger-java.adoc)
-  * [Zipkin](zipkin.adoc)
-
+	* [Bam](bam.adoc)
+	* [Blueprint](blueprint.adoc)
+	* [Cdi](cdi.adoc)
+	* [Cxf Transport](cxf-transport.adoc)
+	* [Eclipse](eclipse.adoc)
+	* [Guice](guice.adoc)
+	* [Hawtdb](hawtdb.adoc)
+	* [Hystrix](hystrix.adoc)
+	* [Jasypt](jasypt.adoc)
+	* [Kura](kura.adoc)
+	* [Leveldb](leveldb.adoc)
+	* [Ribbon](ribbon.adoc)
+	* [Ruby](ruby.adoc)
+	* [Rx](rx.adoc)
+	* [Scala](scala.adoc)
+	* [Scr](scr.adoc)
+	* [Servletlistener](servletlistener.adoc)
+	* [Shiro](shiro.adoc)
+	* [Spring Boot](spring-boot.adoc)
+	* [Spring Cloud](spring-cloud.adoc)
+	* [Spring Dm](spring-dm.adoc)
+	* [Spring Javaconfig](spring-javaconfig.adoc)
+	* [Spring Security](spring-security.adoc)
+	* [Swagger](swagger.adoc)
+	* [Swagger Java](swagger-java.adoc)
+	* [Test](test.adoc)
+	* [Test Blueprint](test-blueprint.adoc)
+	* [Test Cdi](test-cdi.adoc)
+	* [Test Karaf](test-karaf.adoc)
+	* [Test Spring](test-spring.adoc)
+	* [Testng](testng.adoc)
+	* [Urlrewrite](urlrewrite.adoc)
+	* [Zipkin](zipkin.adoc)
+<!-- others: END -->
 
 
 <!-- dataformats: START -->

http://git-wip-us.apache.org/repos/asf/camel/blob/5f566e09/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 a7f9d96..1dc1f68 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
@@ -31,6 +31,7 @@ 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.camel.maven.packaging.model.OtherModel;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -78,6 +79,13 @@ public class PrepareUserGuideMojo extends AbstractMojo {
     protected File languagesDir;
 
     /**
+     * The directory for others catalog
+     *
+     * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/others"
+     */
+    protected File othersDir;
+
+    /**
      * The directory for the user guide
      *
      * @parameter default-value="${project.directory}/../../../docs/user-manual/en"
@@ -101,6 +109,7 @@ public class PrepareUserGuideMojo extends AbstractMojo {
      */
     public void execute() throws MojoExecutionException, MojoFailureException {
         executeComponents();
+        executeOthers();
         executeDataFormats();
         executeLanguages();
     }
@@ -173,6 +182,50 @@ public class PrepareUserGuideMojo extends AbstractMojo {
         }
     }
 
+    protected void executeOthers() 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> models = new ArrayList<>();
+            for (File file : otherFiles) {
+                String json = loadText(new FileInputStream(file));
+                OtherModel model = generateOtherModel(json);
+                models.add(model);
+            }
+
+            // sor the models
+            Collections.sort(models, new OtherComparator());
+
+            // the summary file has the TOC
+            File file = new File(userGuideDir, "SUMMARY.md");
+
+            // update core components
+            StringBuilder other = new StringBuilder();
+            other.append("* Other Components\n");
+            for (OtherModel model : models) {
+                String line = "\t* " + link(model) + "\n";
+                other.append(line);
+            }
+            boolean updated = updateOthers(file, other.toString());
+
+            if (updated) {
+                getLog().info("Updated user guide file: " + file);
+            } else {
+                getLog().debug("No changes to user guide file: " + file);
+            }
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error due " + e.getMessage(), e);
+        }
+    }
+
     protected void executeDataFormats() throws MojoExecutionException, MojoFailureException
{
         Set<File> dataFormatFiles = new TreeSet<>();
 
@@ -329,6 +382,40 @@ public class PrepareUserGuideMojo extends AbstractMojo {
         }
     }
 
+    private boolean updateOthers(File file, String changed) throws MojoExecutionException
{
+        if (!file.exists()) {
+            return false;
+        }
+
+        try {
+            String text = loadText(new FileInputStream(file));
+
+            String existing = StringHelper.between(text, "<!-- others: START -->",
"<!-- others: 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, "<!-- 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<!-- others: START -->");
+                getLog().warn("\t<!-- others: END -->");
+                return false;
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error reading file " + file + " Reason: " +
e, e);
+        }
+    }
+
     private boolean updateDataFormats(File file, String changed) throws MojoExecutionException
{
         if (!file.exists()) {
             return false;
@@ -401,6 +488,10 @@ public class PrepareUserGuideMojo extends AbstractMojo {
         return "[" + model.getTitle() + "](" + model.getScheme() + "-component.adoc)";
     }
 
+    private static String link(OtherModel model) {
+        return "[" + model.getTitle() + "](" + model.getName() + ".adoc)";
+    }
+
     private static String link(DataFormatModel model) {
         // special for some data formats
         String name = asDataFormatName(model.getName());
@@ -429,6 +520,15 @@ public class PrepareUserGuideMojo extends AbstractMojo {
         }
     }
 
+    private static class OtherComparator implements Comparator<OtherModel> {
+
+        @Override
+        public int compare(OtherModel o1, OtherModel o2) {
+            // lets sort by title
+            return o1.getTitle().compareToIgnoreCase(o2.getTitle());
+        }
+    }
+
     private static class DataFormatComparator implements Comparator<DataFormatModel>
{
 
         @Override
@@ -470,6 +570,23 @@ public class PrepareUserGuideMojo 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.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);
 


Mime
View raw message