camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [17/29] camel git commit: CAMEL-7999: apt compiler to generate json schema documentation for the model, whcih we later use to enrich the xml xsd to include documentation. Work in progress.
Date Tue, 30 Dec 2014 10:42:33 GMT
CAMEL-7999: apt compiler to generate json schema documentation for the model, whcih we later
use to enrich the xml xsd to include documentation. Work in progress.


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

Branch: refs/heads/master
Commit: 81890fad896224712fa1831bad6eecebbc5bd594
Parents: e2d5d52
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Dec 27 14:31:31 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 30 10:56:44 2014 +0100

----------------------------------------------------------------------
 platforms/catalog/pom.xml                       |   1 +
 .../maven/packaging/PrepareCatalogMojo.java     | 153 +++++++++++++++++--
 2 files changed, 140 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/81890fad/platforms/catalog/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog/pom.xml b/platforms/catalog/pom.xml
index fd22cde..4a9d484 100644
--- a/platforms/catalog/pom.xml
+++ b/platforms/catalog/pom.xml
@@ -33,6 +33,7 @@
   <properties>
     <camel.osgi.export.pkg>
       org.apache.camel.catalog,
+      org.apache.camel.catalog.models,
       org.apache.camel.catalog.components
     </camel.osgi.export.pkg>
   </properties>

http://git-wip-us.apache.org/repos/asf/camel/blob/81890fad/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
index ec6c4c7..92c0ed3 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
@@ -69,7 +69,14 @@ public class PrepareCatalogMojo extends AbstractMojo {
      *
      * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/components"
      */
-    protected File outDir;
+    protected File componentsOutDir;
+
+    /**
+     * The output directory for models catalog
+     *
+     * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/models"
+     */
+    protected File modelsOutDir;
 
     /**
      * The components directory where all the Apache Camel components are
@@ -101,6 +108,99 @@ public class PrepareCatalogMojo extends AbstractMojo {
      * @throws org.apache.maven.plugin.MojoFailureException   something bad happened...
      */
     public void execute() throws MojoExecutionException, MojoFailureException {
+        executeModel();
+        executeComponents();
+    }
+
+    protected void executeModel() throws MojoExecutionException, MojoFailureException {
+        getLog().info("Copying all Camel model json descriptors");
+
+        // lets use sorted set/maps
+        Set<File> jsonFiles = new TreeSet<File>();
+        Set<File> duplicateJsonFiles = new TreeSet<File>();
+        Set<File> missingLabels = new TreeSet<File>();
+        Map<String, Set<String>> usedLabels = new TreeMap<String, Set<String>>();
+
+        // find all json files in camel-core
+        if (coreDir != null && coreDir.isDirectory()) {
+            File target = new File(coreDir, "target/classes/org/apache/camel/model");
+            findModelFilesRecursive(target, jsonFiles, new CamelComponentsModelFilter());
+        }
+
+        getLog().info("Found " + jsonFiles.size() + " model json files");
+
+        // make sure to create out dir
+        modelsOutDir.mkdirs();
+
+        for (File file : jsonFiles) {
+            File to = new File(modelsOutDir, file.getName());
+            if (to.exists()) {
+                duplicateJsonFiles.add(to);
+                getLog().warn("Duplicate model name detected: " + to);
+            }
+            try {
+                copyFile(file, to);
+            } catch (IOException e) {
+                throw new MojoFailureException("Cannot copy file from " + file + " ->
" + to, e);
+            }
+
+            // check if we have a label as we want the eip to include labels
+            try {
+                String text = loadText(new FileInputStream(file));
+                // just do a basic label check
+                if (text.contains("\"label\": \"\"")) {
+                    missingLabels.add(file);
+                } else {
+                    String name = asComponentName(file);
+                    Matcher matcher = LABEL_PATTERN.matcher(text);
+                    // grab the label, and remember it in the used labels
+                    if (matcher.find()) {
+                        String label = matcher.group(1);
+                        String[] labels = label.split(",");
+                        for (String s : labels) {
+                            Set<String> models = usedLabels.get(s);
+                            if (models == null) {
+                                models = new TreeSet<String>();
+                                usedLabels.put(s, models);
+                            }
+                            models.add(name);
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+
+        File all = new File(modelsOutDir, "../models.properties");
+        try {
+            FileOutputStream fos = new FileOutputStream(all, false);
+
+            String[] names = modelsOutDir.list();
+            List<String> models = new ArrayList<String>();
+            // sort the names
+            for (String name : names) {
+                if (name.endsWith(".json")) {
+                    // strip out .json from the name
+                    String modelName = name.substring(0, name.length() - 5);
+                    models.add(modelName);
+                }
+            }
+
+            Collections.sort(models);
+            for (String name : models) {
+                fos.write(name.getBytes());
+                fos.write("\n".getBytes());
+            }
+
+            fos.close();
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error writing to file " + all);
+        }
+    }
+
+    protected void executeComponents() throws MojoExecutionException, MojoFailureException
{
         getLog().info("Copying all Camel component json descriptors");
 
         // lets use sorted set/maps
@@ -123,7 +223,7 @@ public class PrepareCatalogMojo extends AbstractMojo {
                         int before = componentFiles.size();
                         int before2 = jsonFiles.size();
 
-                        findFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
+                        findComponentFilesRecursive(target, jsonFiles, componentFiles, new
CamelComponentsFileFilter());
 
                         int after = componentFiles.size();
                         int after2 = jsonFiles.size();
@@ -141,7 +241,7 @@ public class PrepareCatalogMojo extends AbstractMojo {
             int before = componentFiles.size();
             int before2 = jsonFiles.size();
 
-            findFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
+            findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
 
             int after = componentFiles.size();
             int after2 = jsonFiles.size();
@@ -153,10 +253,10 @@ public class PrepareCatalogMojo extends AbstractMojo {
         getLog().info("Found " + jsonFiles.size() + " component json files");
 
         // make sure to create out dir
-        outDir.mkdirs();
+        componentsOutDir.mkdirs();
 
         for (File file : jsonFiles) {
-            File to = new File(outDir, file.getName());
+            File to = new File(componentsOutDir, file.getName());
             if (to.exists()) {
                 duplicateJsonFiles.add(to);
                 getLog().warn("Duplicate component name detected: " + to);
@@ -196,15 +296,13 @@ public class PrepareCatalogMojo extends AbstractMojo {
             } catch (IOException e) {
                 // ignore
             }
-
-
         }
 
-        File all = new File(outDir, "../components.properties");
+        File all = new File(componentsOutDir, "../components.properties");
         try {
             FileOutputStream fos = new FileOutputStream(all, false);
 
-            String[] names = outDir.list();
+            String[] names = componentsOutDir.list();
             List<String> components = new ArrayList<String>();
             // sort the names
             for (String name : names) {
@@ -227,11 +325,11 @@ public class PrepareCatalogMojo extends AbstractMojo {
             throw new MojoFailureException("Error writing to file " + all);
         }
 
-        printReport(jsonFiles, duplicateJsonFiles, missingComponents, missingUriPaths, missingLabels,
usedLabels);
+        printComponentsReport(jsonFiles, duplicateJsonFiles, missingComponents, missingUriPaths,
missingLabels, usedLabels);
     }
 
-    private void printReport(Set<File> json, Set<File> duplicate, Set<File>
missing, Set<File> missingUriPaths,
-                             Set<File> missingLabels, Map<String, Set<String>>
usedLabels) {
+    private void printComponentsReport(Set<File> json, Set<File> duplicate, Set<File>
missing, Set<File> missingUriPaths,
+                                       Set<File> missingLabels, Map<String, Set<String>>
usedLabels) {
         getLog().info("================================================================================");
         getLog().info("");
         getLog().info("Camel component catalog report");
@@ -290,7 +388,22 @@ public class PrepareCatalogMojo extends AbstractMojo {
         return name;
     }
 
-    private void findFilesRecursive(File dir, Set<File> found, Set<File> components,
FileFilter filter) {
+    private void findModelFilesRecursive(File dir, Set<File> found, FileFilter filter)
{
+        File[] files = dir.listFiles(filter);
+        if (files != null) {
+            for (File file : files) {
+                // skip files in root dirs as Camel does not store information there but
others may do
+                boolean jsonFile = file.isFile() && file.getName().endsWith(".json");
+                if (jsonFile) {
+                    found.add(file);
+                } else if (file.isDirectory()) {
+                    findModelFilesRecursive(file, found, filter);
+                }
+            }
+        }
+    }
+
+    private void findComponentFilesRecursive(File dir, Set<File> found, Set<File>
components, FileFilter filter) {
         File[] files = dir.listFiles(filter);
         if (files != null) {
             for (File file : files) {
@@ -303,16 +416,28 @@ public class PrepareCatalogMojo extends AbstractMojo {
                 } else if (componentFile) {
                     components.add(file);
                 } else if (file.isDirectory()) {
-                    findFilesRecursive(file, found, components, filter);
+                    findComponentFilesRecursive(file, found, components, filter);
                 }
             }
         }
     }
 
+    private class CamelComponentsModelFilter implements FileFilter {
+
+        @Override
+        public boolean accept(File pathname) {
+            return pathname.isDirectory() || pathname.getName().endsWith(".json");
+        }
+    }
+
     private class CamelComponentsFileFilter implements FileFilter {
 
         @Override
         public boolean accept(File pathname) {
+            if (pathname.isDirectory() && pathname.getName().equals("model")) {
+                // do not check the camel-core model packages as there is no components there
+                return false;
+            }
             return pathname.isDirectory() || pathname.getName().endsWith(".json")
                     || (pathname.isFile() && pathname.getName().equals("component.properties"));
         }


Mime
View raw message