camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/7] camel git commit: CAMEL-9482: Generate json schema model for camel-spring
Date Wed, 10 Aug 2016 17:08:29 GMT
CAMEL-9482: Generate json schema model for camel-spring


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

Branch: refs/heads/master
Commit: 06e3b155bd9607797f62a9f08eb2237d56a15e91
Parents: 3f14b02
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Aug 10 12:58:23 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Aug 10 19:08:13 2016 +0200

----------------------------------------------------------------------
 .../camel/spring/CamelContextFactoryBean.java   |  2 +-
 .../apt/CamelContextAnnotationProcessor.java    | 36 ++++++++++++++++++--
 .../apache/camel/tools/apt/helper/Strings.java  | 15 ++++++++
 .../org/apache/camel/tools/apt/StringsTest.java | 30 ++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/06e3b155/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 60547ee..652b84c 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -122,7 +122,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
     private String useBreadcrumb;
     @XmlAttribute
     private String allowUseOriginalMessage;
-    @XmlAttribute @Metadata(defaultValue = "true")
+    @XmlAttribute
     private String runtimeEndpointRegistryEnabled;
     @XmlAttribute
     private String managementNamePattern;

http://git-wip-us.apache.org/repos/asf/camel/blob/06e3b155/tooling/apt/src/main/java/org/apache/camel/tools/apt/CamelContextAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CamelContextAnnotationProcessor.java
b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CamelContextAnnotationProcessor.java
index 3538ef6..bf0b3b0 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CamelContextAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CamelContextAnnotationProcessor.java
@@ -79,10 +79,11 @@ public class CamelContextAnnotationProcessor extends AbstractAnnotationProcessor
     }
 
     protected void processModelClass(final RoundEnvironment roundEnv, final TypeElement classElement)
{
-        // must be from org.apache.camel.model
+        // must be from camel-spring or camel-core-xml
         final String javaTypeName = canonicalClassName(classElement.getQualifiedName().toString());
         String packageName = javaTypeName.substring(0, javaTypeName.lastIndexOf("."));
-        if (!javaTypeName.startsWith("org.apache.camel.spring")) {
+        boolean valid = javaTypeName.startsWith("org.apache.camel.spring") || javaTypeName.startsWith("org.apache.camel.core.xml");
+        if (!valid) {
             return;
         }
 
@@ -381,9 +382,38 @@ public class CamelContextAnnotationProcessor extends AbstractAnnotationProcessor
                 }
             }
 
+            // is it a definition/factory-bean type then its a oneOf
+            TreeSet oneOfTypes = new TreeSet<String>();
+            if (fieldTypeName.endsWith("Definition") || fieldTypeName.endsWith("FactoryBean"))
{
+                TypeElement definitionClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
+                if (definitionClass != null) {
+                    XmlRootElement rootElement = definitionClass.getAnnotation(XmlRootElement.class);
+                    if (rootElement != null) {
+                        String childName = rootElement.name();
+                        if (childName != null) {
+                            oneOfTypes.add(childName);
+                        }
+                    }
+                }
+            } else if (fieldTypeName.endsWith("Definition>") || fieldTypeName.endsWith("FactoryBean>"))
{
+                // its a list so we need to load the generic type
+                String typeName = Strings.between(fieldTypeName, "<", ">");
+                TypeElement definitionClass = findTypeElement(roundEnv, typeName);
+                if (definitionClass != null) {
+                    XmlRootElement rootElement = definitionClass.getAnnotation(XmlRootElement.class);
+                    if (rootElement != null) {
+                        String childName = rootElement.name();
+                        if (childName != null) {
+                            oneOfTypes.add(childName);
+                        }
+                    }
+                }
+            }
+            boolean oneOf = !oneOfTypes.isEmpty();
+
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue,
docComment, deprecated, isEnum, enums, false, null);
+            EipOption ep = new EipOption(name, kind, fieldTypeName, required, defaultValue,
docComment, deprecated, isEnum, enums, oneOf, oneOfTypes);
             eipOptions.add(ep);
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/06e3b155/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/Strings.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/Strings.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/Strings.java
index 30b826f..7037140 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/Strings.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/helper/Strings.java
@@ -100,4 +100,19 @@ public final class Strings {
         return quote + text + quote;
     }
 
+    /**
+     * Clips the text between the start and end markers
+     */
+    public static String between(String text, String start, String end) {
+        int pos = text.indexOf(start);
+        if (pos > 0) {
+            text = text.substring(pos + 1);
+        }
+        int pos2 = text.lastIndexOf(end);
+        if (pos2 > 0) {
+            text = text.substring(0, pos2);
+        }
+        return text;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/06e3b155/tooling/apt/src/test/java/org/apache/camel/tools/apt/StringsTest.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/test/java/org/apache/camel/tools/apt/StringsTest.java b/tooling/apt/src/test/java/org/apache/camel/tools/apt/StringsTest.java
new file mode 100644
index 0000000..3903d53
--- /dev/null
+++ b/tooling/apt/src/test/java/org/apache/camel/tools/apt/StringsTest.java
@@ -0,0 +1,30 @@
+/**
+ * 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.tools.apt;
+
+import org.junit.Test;
+
+import static org.apache.camel.tools.apt.helper.Strings.between;
+import static org.junit.Assert.assertEquals;
+
+public class StringsTest {
+
+    @Test
+    public void testBetween() {
+        assertEquals("org.apache.camel.model.OnCompletionDefinition", between("java.util.List<org.apache.camel.model.OnCompletionDefinition>",
"<", ">"));
+    }
+}


Mime
View raw message