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-10248: camel-catalog - Include adoc documentation
Date Tue, 16 Aug 2016 13:43:21 GMT
Repository: camel
Updated Branches:
  refs/heads/master ab5f6d988 -> 3da0654ef


CAMEL-10248: camel-catalog - Include adoc documentation


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

Branch: refs/heads/master
Commit: 3da0654ef0e8b6caa9c58ca5ed9c5b172837c3c1
Parents: ab5f6d9
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Aug 16 15:43:10 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Aug 16 15:43:10 2016 +0200

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  24 ++++
 .../catalog/CamelCatalogMBeanExporter.java      |   6 +-
 .../camel/catalog/DefaultCamelCatalog.java      | 132 +++++++++++++++++--
 .../apache/camel/catalog/CamelCatalogTest.java  |  29 ++++
 4 files changed, 180 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3da0654e/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 a207203..7de21c1 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
@@ -158,6 +158,30 @@ public interface CamelCatalog {
     String modelJSonSchema(String name);
 
     /**
+     * Returns the component documentation as Ascii doc format.
+     *
+     * @param name the component name
+     * @return component documentation in ascii doc format.
+     */
+    String componentAsciiDoc(String name);
+
+    /**
+     * Returns the data format documentation as Ascii doc format.
+     *
+     * @param name the data format name
+     * @return data format documentation in ascii doc format.
+     */
+    String dataFormatAsciiDoc(String name);
+
+    /**
+     * Returns the language documentation as Ascii doc format.
+     *
+     * @param name the language name
+     * @return language documentation in ascii doc format.
+     */
+    String languageAsciiDoc(String name);
+
+    /**
      * Find all the unique label names all the components are using.
      *
      * @return a set of all the labels.

http://git-wip-us.apache.org/repos/asf/camel/blob/3da0654e/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java
index c5d64ba..fd95a16 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalogMBeanExporter.java
@@ -37,7 +37,7 @@ public class CamelCatalogMBeanExporter {
      * Initializes and exports the {@link CamelCatalog} in JMX using the domain name,
      * which can be obtained using {@link #getObjectName()}.
      *
-     * @throws Exception
+     * @throws Exception is thrown if error during registration
      */
     public void init() throws Exception {
         catalog = new DefaultCamelCatalog();
@@ -66,9 +66,9 @@ public class CamelCatalogMBeanExporter {
     }
 
     /**
-     * Destroyes and unregisteres the {@link CamelCatalog} from JMX.
+     * Destroys and un-registers the {@link CamelCatalog} from JMX.
      *
-     * @throws Exception is thrown if error during unregistration
+     * @throws Exception is thrown if error during un-registration
      */
     public void destroy() throws Exception {
         if (mBeanServer != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3da0654e/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 b1cfea9..367fdae 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
@@ -76,10 +76,11 @@ public class DefaultCamelCatalog implements CamelCatalog {
     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 MODEL_JSON = "org/apache/camel/catalog/models";
-    private static final String COMPONENTS_JSON = "org/apache/camel/catalog/components";
-    private static final String DATA_FORMATS_JSON = "org/apache/camel/catalog/dataformats";
-    private static final String LANGUAGE_JSON = "org/apache/camel/catalog/languages";
+    private static final String MODEL_DIR = "org/apache/camel/catalog/models";
+    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 DOC_DIR = "org/apache/camel/catalog/docs";
     private static final String ARCHETYPES_CATALOG = "org/apache/camel/catalog/archetypes/archetype-catalog.xml";
     private static final String SCHEMAS_XML = "org/apache/camel/catalog/schemas";
 
@@ -410,7 +411,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String modelJSonSchema(String name) {
-        String file = MODEL_JSON + "/" + name + ".json";
+        String file = MODEL_DIR + "/" + name + ".json";
 
         String answer = null;
         if (caching) {
@@ -436,7 +437,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String componentJSonSchema(String name) {
-        String file = COMPONENTS_JSON + "/" + name + ".json";
+        String file = COMPONENT_DIR + "/" + name + ".json";
 
         String answer = null;
         if (caching) {
@@ -478,7 +479,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String dataFormatJSonSchema(String name) {
-        String file = DATA_FORMATS_JSON + "/" + name + ".json";
+        String file = DATAFORMAT_DIR + "/" + name + ".json";
 
         String answer = null;
         if (caching) {
@@ -525,7 +526,122 @@ public class DefaultCamelCatalog implements CamelCatalog {
             name = "bean";
         }
 
-        String file = LANGUAGE_JSON + "/" + name + ".json";
+        String file = LANGUAGE_DIR + "/" + name + ".json";
+
+        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
+    public String componentAsciiDoc(String name) {
+        String file = DOC_DIR + "/" + name + "-component.adoc";
+
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("component-" + file);
+        }
+
+        if (answer == null) {
+            InputStream is = versionManager.getResourceAsStream(file);
+            if (is != null) {
+                try {
+                    answer = CatalogHelper.loadText(is);
+                } catch (IOException e) {
+                    // ignore
+                }
+            } else {
+                // its maybe a third party so try load it
+                String className = extraComponents.get(name);
+                if (className != null) {
+                    String packageName = className.substring(0, className.lastIndexOf('.'));
+                    packageName = packageName.replace('.', '/');
+                    String path = packageName + "/" + name + "-component.adoc";
+                    is = versionManager.getResourceAsStream(path);
+                    if (is != null) {
+                        try {
+                            answer = CatalogHelper.loadText(is);
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
+                }
+            }
+            if (caching) {
+                cache.put("component-" + file, answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
+    public String dataFormatAsciiDoc(String name) {
+        String file = DOC_DIR + "/" + name + "-dataformat.adoc";
+
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("dataformat-" + file);
+        }
+
+        if (answer == null) {
+            InputStream is = versionManager.getResourceAsStream(file);
+            if (is != null) {
+                try {
+                    answer = CatalogHelper.loadText(is);
+                } catch (IOException e) {
+                    // ignore
+                }
+            } else {
+                // its maybe a third party so try load it
+                String className = extraDataFormats.get(name);
+                if (className != null) {
+                    String packageName = className.substring(0, className.lastIndexOf('.'));
+                    packageName = packageName.replace('.', '/');
+                    String path = packageName + "/" + name + "-dataformat.adoc";
+                    is = versionManager.getResourceAsStream(path);
+                    if (is != null) {
+                        try {
+                            answer = CatalogHelper.loadText(is);
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
+                }
+            }
+            if (caching) {
+                cache.put("dataformat-" + file, answer);
+            }
+        }
+
+        return answer;
+    }
+
+    @Override
+    public String languageAsciiDoc(String name) {
+        // if we try to look method then its in the bean.adoc file
+        if ("method".equals(name)) {
+            name = "bean";
+        }
+
+        String file = DOC_DIR + "/" + name + "-language.adoc";
 
         String answer = null;
         if (caching) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3da0654e/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 3f8a8aa..2a1e941 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
@@ -31,6 +31,7 @@ import static org.apache.camel.catalog.CatalogHelper.loadText;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 public class CamelCatalogTest {
@@ -783,4 +784,32 @@ public class CamelCatalogTest {
         assertTrue(json.contains("CamelContext using XML configuration"));
     }
 
+    @Test
+    public void testComponentAsciiDoc() throws Exception {
+        String doc = catalog.componentAsciiDoc("mock");
+        assertNotNull(doc);
+        assertTrue(doc.contains("mock:someName"));
+
+        doc = catalog.componentAsciiDoc("geocoder");
+        assertNotNull(doc);
+        assertTrue(doc.contains("looking up geocodes"));
+
+        doc = catalog.componentAsciiDoc("unknown");
+        assertNull(doc);
+    }
+
+    @Test
+    public void testDataFormatAsciiDoc() throws Exception {
+        String doc = catalog.dataFormatAsciiDoc("json-jackson");
+        assertNotNull(doc);
+        assertTrue(doc.contains("Jackson dataformat"));
+    }
+
+    @Test
+    public void testLanguageAsciiDoc() throws Exception {
+        String doc = catalog.languageAsciiDoc("jsonpath");
+        assertNotNull(doc);
+        assertTrue(doc.contains("JSonPath language"));
+    }
+
 }


Mime
View raw message