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 2016/01/06 11:36:55 UTC

[05/11] camel git commit: Component docs - Allow to exclude inherited properties

Component docs - Allow to exclude inherited properties


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

Branch: refs/heads/master
Commit: 420fd08446a02759d14cc7c2f67b079137eeb0e8
Parents: 1189692
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jan 6 09:47:30 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jan 6 11:36:27 2016 +0100

----------------------------------------------------------------------
 .../atmosphere/websocket/WebsocketEndpoint.java |  3 +-
 .../tools/apt/EndpointAnnotationProcessor.java  | 36 +++++++++++++++-----
 .../java/org/apache/camel/spi/UriEndpoint.java  |  8 +++++
 3 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/420fd084/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java
index 1feabef..8790443 100644
--- a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java
+++ b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketEndpoint.java
@@ -32,7 +32,8 @@ import org.apache.camel.spi.UriPath;
  * To exchange data with external Websocket clients using Atmosphere.
  */
 @UriEndpoint(scheme = "atmosphere-websocket", extendsScheme = "servlet", title = "Atmosphere Websocket",
-        syntax = "atmosphere-websocket:servicePath", consumerClass = WebsocketConsumer.class, label = "websocket")
+        syntax = "atmosphere-websocket:servicePath", consumerClass = WebsocketConsumer.class, label = "websocket",
+        excludeProperties = "httpUri,contextPath")
 public class WebsocketEndpoint extends ServletEndpoint {
 
     private WebSocketStore store;

http://git-wip-us.apache.org/repos/asf/camel/blob/420fd084/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
index b35512b..9c7a65d 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
@@ -149,7 +149,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
         writer.println("<b>Deprecated:</b>" + componentModel.isDeprecated() + "<br/>");
         writer.println("<b>Maven:</b> " + componentModel.getGroupId() + "/" + componentModel.getArtifactId() + "/" + componentModel.getVersionId() + "<br/>");
 
-        writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, classElement, "");
+        writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, classElement, "", uriEndpoint.excludeProperties());
 
         // This code is not my fault, it seems to honestly be the hacky way to find a class name in APT :)
         TypeMirror consumerType = null;
@@ -167,7 +167,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
             TypeElement consumerElement = findTypeElement(roundEnv, consumerClassName);
             if (consumerElement != null) {
                 writer.println("<h2>" + scheme + " consumer" + "</h2>");
-                writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, consumerElement, consumerPrefix);
+                writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, consumerElement, consumerPrefix, uriEndpoint.excludeProperties());
                 found = true;
             }
         }
@@ -193,7 +193,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
             findComponentClassProperties(writer, roundEnv, componentModel, componentOptions, componentClassElement, "");
         }
 
-        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, "");
+        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, "", uriEndpoint.excludeProperties());
 
         String json = createParameterJsonSchema(componentModel, componentOptions, endpointPaths, endpointOptions);
         writer.println(json);
@@ -364,7 +364,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
     }
 
     protected void writeHtmlDocumentationAndFieldInjections(PrintWriter writer, RoundEnvironment roundEnv, ComponentModel componentModel,
-                                                            TypeElement classElement, String prefix) {
+                                                            TypeElement classElement, String prefix, String excludeProperties) {
         String classDoc = processingEnv.getElementUtils().getDocComment(classElement);
         if (!isNullOrEmpty(classDoc)) {
             // remove dodgy @version that we may have in class javadoc
@@ -375,7 +375,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
 
         Set<EndpointPath> endpointPaths = new LinkedHashSet<EndpointPath>();
         Set<EndpointOption> endpointOptions = new LinkedHashSet<EndpointOption>();
-        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, prefix);
+        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, prefix, excludeProperties);
 
         // sort the endpoint options in the standard order we prefer
         List<EndpointPath> paths = new ArrayList<EndpointPath>();
@@ -603,7 +603,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
 
     protected void findClassProperties(PrintWriter writer, RoundEnvironment roundEnv, ComponentModel componentModel,
                                        Set<EndpointPath> endpointPaths, Set<EndpointOption> endpointOptions,
-                                       TypeElement classElement, String prefix) {
+                                       TypeElement classElement, String prefix, String excludeProperties) {
         Elements elementUtils = processingEnv.getElementUtils();
         while (true) {
             List<VariableElement> fieldElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
@@ -621,6 +621,11 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
                     }
                     name = prefix + name;
 
+                    // should we exclude the name?
+                    if (excludeProperty(excludeProperties, name)) {
+                        continue;
+                    }
+
                     String defaultValue = path.defaultValue();
                     if (defaultValue == null && metadata != null) {
                         defaultValue = metadata.defaultValue();
@@ -685,6 +690,11 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
                     }
                     name = prefix + name;
 
+                    // should we exclude the name?
+                    if (excludeProperty(excludeProperties, name)) {
+                        continue;
+                    }
+
                     String paramOptionalPrefix = param.optionalPrefix();
                     String paramPrefix = param.prefix();
                     boolean multiValue = param.multiValue();
@@ -713,7 +723,7 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
                         if (!isNullOrEmpty(extraPrefix)) {
                             nestedPrefix += extraPrefix;
                         }
-                        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, fieldTypeElement, nestedPrefix);
+                        findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, fieldTypeElement, nestedPrefix, excludeProperties);
                     } else {
                         String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name, classElement, false);
                         if (isNullOrEmpty(docComment)) {
@@ -773,7 +783,17 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
         }
     }
 
-    protected Map<String, String> parseAsMap(String data) {
+    private static boolean excludeProperty(String excludeProperties, String name) {
+        String[] excludes = excludeProperties.split(",");
+        for (String exclude : excludes) {
+            if (name.equals(exclude)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    protected static Map<String, String> parseAsMap(String data) {
         Map<String, String> answer = new HashMap<String, String>();
         String[] lines = data.split("\n");
         for (String line : lines) {

http://git-wip-us.apache.org/repos/asf/camel/blob/420fd084/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriEndpoint.java
----------------------------------------------------------------------
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriEndpoint.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriEndpoint.java
index e989ce9..b557d51 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriEndpoint.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriEndpoint.java
@@ -130,4 +130,12 @@ public @interface UriEndpoint {
      */
     boolean lenientProperties() default false;
 
+    /**
+     * To exclude one or more properties in this endpoint.
+     * <p/>
+     * This is used when a Camel component extend another component, and then may need to not use some of the properties from
+     * the parent component. Multiple properties can be separated by comma.
+     */
+    String excludeProperties() default "";
+
 }
\ No newline at end of file