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 2017/02/03 19:31:43 UTC

[5/7] camel git commit: CAMEL-10774: Add api to camel-catalog to load other kind of component details.

CAMEL-10774: Add api to camel-catalog to load other kind of component details.


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

Branch: refs/heads/master
Commit: 794e382ef97dc29f5e6ba83098a52e8d41b68873
Parents: 490d49e
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 3 18:23:45 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 3 20:31:28 2017 +0100

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  46 +++++
 .../camel/catalog/DefaultCamelCatalog.java      | 198 +++++++++++++++++++
 .../camel/catalog/DefaultRuntimeProvider.java   |  21 ++
 .../apache/camel/catalog/RuntimeProvider.java   |  10 +
 .../apache/camel/catalog/CamelCatalogTest.java  |  40 ++++
 5 files changed, 315 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/794e382e/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 6c23016..0a06efc 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -150,6 +150,11 @@ public interface CamelCatalog {
     List<String> findModelNames();
 
     /**
+     * Find all the other (miscellaneous) names from the Camel catalog
+     */
+    List<String> findOtherNames();
+
+    /**
      * Find all the component names from the Camel catalog that matches the label
      */
     List<String> findComponentNames(String filter);
@@ -170,6 +175,11 @@ public interface CamelCatalog {
     List<String> findModelNames(String filter);
 
     /**
+     * Find all the other (miscellaneous) names from the Camel catalog that matches the label
+     */
+    List<String> findOtherNames(String filter);
+
+    /**
      * Returns the component information as JSon format.
      *
      * @param name the component name
@@ -194,6 +204,14 @@ public interface CamelCatalog {
     String languageJSonSchema(String name);
 
     /**
+     * Returns the other (miscellaneous) information as JSon format.
+     *
+     * @param name the other (miscellaneous) name
+     * @return other (miscellaneous) details in JSon
+     */
+    String otherJSonSchema(String name);
+
+    /**
      * Returns the model information as JSon format.
      *
      * @param name the model name
@@ -250,6 +268,22 @@ public interface CamelCatalog {
     String languageHtmlDoc(String name);
 
     /**
+     * Returns the other (miscellaneous) documentation as Ascii doc format.
+     *
+     * @param name the other (miscellaneous) name
+     * @return other (miscellaneous) documentation in ascii doc format.
+     */
+    String otherAsciiDoc(String name);
+
+    /**
+     * Returns the other (miscellaneous) documentation as HTML format.
+     *
+     * @param name the other (miscellaneous) name
+     * @return other (miscellaneous) documentation in HTML format.
+     */
+    String otherHtmlDoc(String name);
+
+    /**
      * Find all the unique label names all the components are using.
      *
      * @return a set of all the labels.
@@ -278,6 +312,13 @@ public interface CamelCatalog {
     Set<String> findModelLabels();
 
     /**
+     * Find all the unique label names all the other (miscellaneous) are using.
+     *
+     * @return a set of all the labels.
+     */
+    Set<String> findOtherLabels();
+
+    /**
      * Returns the Apache Camel Maven Archetype catalog in XML format.
      *
      * @return the catalog in XML
@@ -505,6 +546,11 @@ public interface CamelCatalog {
     String listModelsAsJson();
 
     /**
+     * Lists all the others (miscellaneous) summary details in JSon
+     */
+    String listOthersAsJson();
+
+    /**
      * Reports a summary what the catalog contains in JSon
      */
     String summaryAsJson();

http://git-wip-us.apache.org/repos/asf/camel/blob/794e382e/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 8d49810..f6509f8 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -316,6 +316,24 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    @SuppressWarnings("unchecked")
+    public List<String> findOtherNames() {
+        List<String> names = null;
+        if (caching) {
+            names = (List<String>) cache.get("findOtherNames");
+        }
+
+        if (names == null) {
+            names = runtimeProvider.findOtherNames();
+
+            if (caching) {
+                cache.put("findOtherNames", names);
+            }
+        }
+        return names;
+    }
+
+    @Override
     public List<String> findModelNames(String filter) {
         // should not cache when filter parameter can by any kind of value
         List<String> answer = new ArrayList<String>();
@@ -440,6 +458,37 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public List<String> findOtherNames(String filter) {
+        // should not cache when filter parameter can by any kind of value
+        List<String> answer = new ArrayList<String>();
+
+        List<String> names = findOtherNames();
+        for (String name : names) {
+            String json = otherJSonSchema(name);
+            if (json != null) {
+                List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", json, false);
+                for (Map<String, String> row : rows) {
+                    if (row.containsKey("label")) {
+                        String label = row.get("label");
+                        String[] parts = label.split(",");
+                        for (String part : parts) {
+                            try {
+                                if (part.equalsIgnoreCase(filter) || CatalogHelper.matchWildcard(part, filter) || part.matches(filter)) {
+                                    answer.add(name);
+                                }
+                            } catch (PatternSyntaxException e) {
+                                // ignore as filter is maybe not a pattern
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     public String modelJSonSchema(String name) {
         String file = MODEL_DIR + "/" + name + ".json";
 
@@ -589,6 +638,32 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public String otherJSonSchema(String name) {
+        String file = runtimeProvider.getOtherJSonSchemaDirectory() + "/" + name + ".json";
+
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("other-" + file);
+        }
+
+        if (answer == null) {
+            InputStream is = versionManager.getResourceAsStream(file);
+            if (is != null) {
+                try {
+                    answer = CatalogHelper.loadText(is);
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            if (caching) {
+                cache.put("other-" + file, answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     public String componentAsciiDoc(String name) {
         String answer = doComponentAsciiDoc(name);
         if (answer == null) {
@@ -890,6 +965,58 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public String otherAsciiDoc(String name) {
+        String file = DOC_DIR + "/" + name + ".adoc";
+
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("other-" + file);
+        }
+
+        if (answer == null) {
+            InputStream is = versionManager.getResourceAsStream(file);
+            if (is != null) {
+                try {
+                    answer = CatalogHelper.loadText(is);
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            if (caching) {
+                cache.put("other-" + file, answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
+    public String otherHtmlDoc(String name) {
+        String file = DOC_DIR + "/" + name + "-other.html";
+
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("language-" + file);
+        }
+
+        if (answer == null) {
+            InputStream is = versionManager.getResourceAsStream(file);
+            if (is != null) {
+                try {
+                    answer = CatalogHelper.loadText(is);
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            if (caching) {
+                cache.put("language-" + file, answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     @SuppressWarnings("unchecked")
     public Set<String> findModelLabels() {
         SortedSet<String> answer = null;
@@ -1026,6 +1153,40 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    @SuppressWarnings("unchecked")
+    public Set<String> findOtherLabels() {
+        SortedSet<String> answer = null;
+        if (caching) {
+            answer = (TreeSet<String>) cache.get("findOtherLabels");
+        }
+
+        if (answer == null) {
+            answer = new TreeSet<String>();
+            List<String> names = findOtherNames();
+            for (String name : names) {
+                String json = otherJSonSchema(name);
+                if (json != null) {
+                    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", json, false);
+                    for (Map<String, String> row : rows) {
+                        if (row.containsKey("label")) {
+                            String label = row.get("label");
+                            String[] parts = label.split(",");
+                            for (String part : parts) {
+                                answer.add(part);
+                            }
+                        }
+                    }
+                }
+            }
+            if (caching) {
+                cache.put("findOtherLabels", answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     public String archetypeCatalogAsXml() {
         String file = ARCHETYPES_CATALOG;
 
@@ -2203,6 +2364,43 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public String listOthersAsJson() {
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("listOthersAsJson");
+        }
+
+        if (answer == null) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("[");
+            List<String> names = findOtherNames();
+            for (int i = 0; i < names.size(); i++) {
+                String scheme = names.get(i);
+                String json = otherJSonSchema(scheme);
+                // skip first line
+                json = CatalogHelper.between(json, "\"other\": {", "  }");
+                json = json != null ? json.trim() : "";
+                json = json + "\n  },";
+                // skip last comma if not the last
+                if (i == names.size() - 1) {
+                    json = json.substring(0, json.length() - 1);
+                }
+                sb.append("\n");
+                sb.append("  {\n");
+                sb.append("    ");
+                sb.append(json);
+            }
+            sb.append("\n]");
+            answer = sb.toString();
+            if (caching) {
+                cache.put("listOthersAsJson", answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
     public String summaryAsJson() {
         String answer = null;
         if (caching) {

http://git-wip-us.apache.org/repos/asf/camel/blob/794e382e/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
index d022954..3e93370 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
@@ -26,9 +26,11 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
     private static final String COMPONENT_DIR = "org/apache/camel/catalog/components";
     private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/dataformats";
     private static final String LANGUAGE_DIR = "org/apache/camel/catalog/languages";
+    private static final String OTHER_DIR = "org/apache/camel/catalog/others";
     private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
     private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
     private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
+    private static final String OTHER_CATALOG = "org/apache/camel/catalog/others.properties";
 
     private CamelCatalog camelCatalog;
 
@@ -70,6 +72,11 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getOtherJSonSchemaDirectory() {
+        return OTHER_DIR;
+    }
+
+    @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();
         InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);
@@ -110,4 +117,18 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
         }
         return names;
     }
+
+    @Override
+    public List<String> findOtherNames() {
+        List<String> names = new ArrayList<String>();
+        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(OTHER_CATALOG);
+        if (is != null) {
+            try {
+                CatalogHelper.loadLines(is, names);
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        return names;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/794e382e/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
index 7539fab..60d76ec 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
@@ -56,6 +56,11 @@ public interface RuntimeProvider {
     String getLanguageJSonSchemaDirectory();
 
     /**
+     * Gets the directory where the other (miscellaneous) json files are stored in the catalog JAR file
+     */
+    String getOtherJSonSchemaDirectory();
+
+    /**
      * Find all the component names from the Camel catalog supported by the provider
      */
     List<String> findComponentNames();
@@ -70,4 +75,9 @@ public interface RuntimeProvider {
      */
     List<String> findLanguageNames();
 
+    /**
+     * Find all the other (miscellaneous) names from the Camel catalog supported by the provider
+     */
+    List<String> findOtherNames();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/794e382e/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 300b2a1..72ab4d9 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -79,6 +79,25 @@ public class CamelCatalogTest {
     }
 
     @Test
+    public void testFindOtherNames() throws Exception {
+        List<String> names = catalog.findOtherNames();
+
+        assertTrue(names.contains("eclipse"));
+        assertTrue(names.contains("hystrix"));
+        assertTrue(names.contains("leveldb"));
+        assertTrue(names.contains("kura"));
+        assertTrue(names.contains("servletlistener"));
+        assertTrue(names.contains("swagger-java"));
+        assertTrue(names.contains("test-spring"));
+
+        assertFalse(names.contains("http-common"));
+        assertFalse(names.contains("core-osgi"));
+        assertFalse(names.contains("file"));
+        assertFalse(names.contains("ftp"));
+        assertFalse(names.contains("jetty"));
+    }
+
+    @Test
     public void testFindNames() throws Exception {
         List<String> names = catalog.findComponentNames();
         assertNotNull(names);
@@ -124,6 +143,9 @@ public class CamelCatalogTest {
         schema = catalog.modelJSonSchema("aggregate");
         assertNotNull(schema);
 
+        schema = catalog.otherJSonSchema("swagger-java");
+        assertNotNull(schema);
+
         // lets make it possible to find bean/method using both names
         schema = catalog.modelJSonSchema("method");
         assertNotNull(schema);
@@ -791,6 +813,17 @@ public class CamelCatalogTest {
     }
 
     @Test
+    public void testListOthersAsJson() throws Exception {
+        String json = catalog.listOthersAsJson();
+        assertNotNull(json);
+
+        // validate we can parse the json
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode tree = mapper.readTree(json);
+        assertNotNull(tree);
+    }
+
+    @Test
     public void testSummaryAsJson() throws Exception {
         String json = catalog.summaryAsJson();
         assertNotNull(json);
@@ -984,6 +1017,13 @@ public class CamelCatalogTest {
     }
 
     @Test
+    public void testOtherAsciiDoc() throws Exception {
+        String doc = catalog.otherAsciiDoc("swagger-java");
+        assertNotNull(doc);
+        assertTrue(doc.contains("Swagger"));
+    }
+
+    @Test
     public void testValidateEndpointTwitterSpecial() throws Exception {
         String uri = "twitter://search?{{%s}}&keywords=java";