camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [19/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:35 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/0d5a6a6a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0d5a6a6a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0d5a6a6a

Branch: refs/heads/master
Commit: 0d5a6a6ad243ffce417842177fc39b90269b3982
Parents: 02c1e0b
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Dec 28 12:13:29 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 30 10:56:45 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  7 ++
 .../mbean/ManagedCamelContextMBean.java         |  9 +++
 .../apache/camel/impl/DefaultCamelContext.java  | 18 +++++
 .../management/mbean/ManagedCamelContext.java   |  4 +
 .../apache/camel/util/CamelContextHelper.java   |  1 +
 .../apache/camel/impl/EipDocumentationTest.java | 78 ++++++++++++++++++++
 6 files changed, 117 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 90edf00..99eefe4 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1401,6 +1401,13 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration
{
     String getComponentParameterJsonSchema(String componentName) throws IOException;
 
     /**
+     * Returns the JSON schema representation of the EIP parameters for the given EIP name.
+     *
+     * @return the json or <tt>null</tt> if the EIP does not exist
+     */
+    String getEipParameterJsonSchema(String eipName) throws IOException;
+
+    /**
      * Returns a JSON schema representation of the endpoint parameters for the given endpoint
uri.
      *
      * @param uri the endpoint uri

http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index fc892b6..bbe2f3d 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -242,6 +242,15 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     String componentParameterJsonSchema(String componentName) throws Exception;
 
     /**
+     * Returns the JSON schema representation with information about the EIP and the parameters
it supports
+     *
+     * @param eipName the name of the EIP to lookup
+     * @throws Exception is thrown if error occurred
+     */
+    @ManagedOperation(description = "Returns the JSON schema representation of the EIP parameters
for the given EIP name")
+    String eipParameterJsonSchema(String eipName) throws Exception;
+
+    /**
      * Returns a JSON schema representation of the endpoint parameters for the given endpoint
uri
      *
      * @param uri the endpoint uri

http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index eb784b6..d1d5369 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1161,6 +1161,24 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
         return null;
     }
 
+    public String getEipParameterJsonSchema(String eipName) throws IOException {
+        String[] subPackages = new String[]{"", "/config", "/dataformat", "/language", "/loadbalancer",
"/rest"};
+        for (String sub : subPackages) {
+            String path = CamelContextHelper.MODEL_DOCUMENTATION_PREFIX + sub + "/" + eipName
+ ".json";
+            ClassResolver resolver = getClassResolver();
+            InputStream inputStream = resolver.loadResourceAsStream(path);
+            log.debug("Loading component JSON Schema for: {} using class resolver: {} ->
{}", new Object[]{eipName, resolver, inputStream});
+            if (inputStream != null) {
+                try {
+                    return IOHelper.loadText(inputStream);
+                } finally {
+                    IOHelper.close(inputStream);
+                }
+            }
+        }
+        return null;
+    }
+
     /**
      * Sanitizes the component name by removing dash (-) in the name, when using the component
name to load
      * resources from the classpath.

http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index f5cf263..e7230d5 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -569,6 +569,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         return json;
     }
 
+    public String eipParameterJsonSchema(String eipName) throws Exception {
+        return context.getEipParameterJsonSchema(eipName);
+    }
+
     public String explainEndpointJson(String uri, boolean includeAllOptions) throws Exception
{
         return context.explainEndpointJson(uri, includeAllOptions);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
index 097ed29..06e0d6f 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
@@ -54,6 +54,7 @@ public final class CamelContextHelper {
     public static final String COMPONENT_BASE = "META-INF/services/org/apache/camel/component/";
     public static final String COMPONENT_DESCRIPTOR = "META-INF/services/org/apache/camel/component.properties";
     public static final String COMPONENT_DOCUMENTATION_PREFIX = "org/apache/camel/component/";
+    public static final String MODEL_DOCUMENTATION_PREFIX = "org/apache/camel/model/";
 
     private static final Logger LOG = LoggerFactory.getLogger(CamelContextHelper.class);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/0d5a6a6a/camel-core/src/test/java/org/apache/camel/impl/EipDocumentationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/EipDocumentationTest.java b/camel-core/src/test/java/org/apache/camel/impl/EipDocumentationTest.java
new file mode 100644
index 0000000..01e5dab
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/EipDocumentationTest.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+
+public class EipDocumentationTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testDocumentation() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("from");
+        log.info(json);
+        assertNotNull("Should have found json for from", json);
+
+        assertTrue(json.contains("\"name\": \"from\""));
+        assertTrue(json.contains("\"uri\": { \"kind\": \"attribute\""));
+        assertTrue(json.contains("\"ref\": { \"kind\": \"attribute\""));
+    }
+
+    public void testSplitDocumentation() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("split");
+        log.info(json);
+        assertNotNull("Should have found json for split", json);
+
+        assertTrue(json.contains("\"name\": \"split\""));
+        // there should be javadoc included
+        assertTrue(json.contains("Whether to aggregate using a sequential single thread or
allow parallel aggregation"));
+        // and it support outputs
+        assertTrue(json.contains("\"outputs\": { \"kind\": \"element\": \"required\": \"true\",
\"type\": \"array\","));
+    }
+
+    public void testSimpleDocumentation() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("simple");
+        log.info(json);
+        assertNotNull("Should have found json for simple", json);
+
+        assertTrue(json.contains("\"label\": \"language\""));
+        assertTrue(json.contains("\"name\": \"simple\""));
+    }
+
+    public void testFailOverDocumentation() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("failover");
+        log.info(json);
+        assertNotNull("Should have found json for failover", json);
+
+        assertTrue(json.contains("\"name\": \"failover\""));
+        assertTrue(json.contains("\"exception\": { \"kind\": \"element\": \"required\": \"false\",
\"type\": \"array\", \"javaType\": \"java.util.List<java.lang.String>\""));
+    }
+
+    public void testNotFound() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("unknown");
+        assertNull("Should not have found json for unknown", json);
+    }
+}


Mime
View raw message