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 2014/11/10 20:24:55 UTC
[2/2] camel git commit: CAMEL-7999: Lets include more core components
documentation out of the box.
CAMEL-7999: Lets include more core components documentation out of the box.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/91c3dbb3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/91c3dbb3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/91c3dbb3
Branch: refs/heads/master
Commit: 91c3dbb3ef737cab1a9c85a4d7c9e965a0632044
Parents: 799d4a0
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 10 20:19:16 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 10 20:24:40 2014 +0100
----------------------------------------------------------------------
.../camel/component/ref/RefComponent.java | 27 +++----
.../apache/camel/component/ref/RefEndpoint.java | 78 ++++++++++++++++++++
.../tools/apt/EndpointAnnotationProcessor.java | 12 +--
.../camel/tools/apt/JsonSchemaHelper.java | 27 +++++--
4 files changed, 113 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/91c3dbb3/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java b/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
index c0bf0b9..67690fe 100644
--- a/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/ref/RefComponent.java
@@ -19,15 +19,18 @@ package org.apache.camel.component.ref;
import java.util.Map;
import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.impl.UriEndpointComponent;
/**
* Component for lookup of existing endpoints bound in the {@link org.apache.camel.spi.Registry}.
* <p/>
* This component uses the <tt>ref:</tt> notation instead of the mostly common <tt>uri:</tt> notation.
*/
-public class RefComponent extends DefaultComponent {
+public class RefComponent extends UriEndpointComponent {
+
+ public RefComponent() {
+ super(RefEndpoint.class);
+ }
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
// first remove the scheme from the URI
@@ -39,19 +42,11 @@ public class RefComponent extends DefaultComponent {
if (name.startsWith("//")) {
name = name.substring(2);
}
- return lookupEndpoint(name, parameters);
- }
- /**
- * Looks up a mandatory endpoint for a given name.
- * <p/>
- * Derived classes could use this name as a logical name and look it up on some registry.
- * <p/>
- * The default implementation will do a mandatory look up the name in the {@link org.apache.camel.spi.Registry}.
- *
- * @throws org.apache.camel.NoSuchBeanException if not found in the {@link org.apache.camel.spi.Registry}
- */
- protected Endpoint lookupEndpoint(String name, Map<String, Object> parameters) {
- return CamelContextHelper.mandatoryLookup(getCamelContext(), name, Endpoint.class);
+ RefEndpoint answer = new RefEndpoint(uri, this);
+ answer.setName(name);
+ setProperties(answer, parameters);
+ return answer;
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/91c3dbb3/camel-core/src/main/java/org/apache/camel/component/ref/RefEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/ref/RefEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/ref/RefEndpoint.java
new file mode 100644
index 0000000..8ce5ef2
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/ref/RefEndpoint.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.component.ref;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.CamelContextHelper;
+
+@UriEndpoint(scheme = "ref")
+public class RefEndpoint extends DefaultEndpoint {
+
+ private volatile Endpoint endpoint;
+
+ @UriParam
+ private String name;
+
+ public RefEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Name of endpoint to lookup
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return endpoint.createProducer();
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return endpoint.createConsumer(processor);
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ endpoint = CamelContextHelper.mandatoryLookup(getCamelContext(), name, Endpoint.class);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ // noop
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/91c3dbb3/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 c871eea..fb876e3 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
@@ -242,7 +242,7 @@ public class EndpointAnnotationProcessor extends AbstractProcessor {
// need to sanitize the description first
String doc = map.get("projectDescription");
if (doc != null) {
- model.setDescription(sanitizeDescription(doc));
+ model.setDescription(sanitizeDescription(doc, true));
} else {
model.setDescription("");
}
@@ -270,14 +270,8 @@ public class EndpointAnnotationProcessor extends AbstractProcessor {
if (typeElement != null) {
String doc = elementUtils.getDocComment(typeElement);
if (doc != null) {
- // need to sanitize the description first
- doc = sanitizeDescription(doc);
- // grab the first sentence only as this is for short description
- int idx = doc.indexOf('.');
- if (idx != -1) {
- // do not include the dot, so do not use idx + 1
- doc = doc.substring(0, idx);
- }
+ // need to sanitize the description first (we only want a summary)
+ doc = sanitizeDescription(doc, true);
// the javadoc may actually be empty, so only change the doc if we got something
if (!Strings.isNullOrEmpty(doc)) {
model.setDescription(doc);
http://git-wip-us.apache.org/repos/asf/camel/blob/91c3dbb3/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
index 12de1ab..ad1ca8f 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
@@ -60,7 +60,7 @@ final class JsonSchemaHelper {
if (!Strings.isNullOrEmpty(description)) {
sb.append(", \"description\": ");
- String text = sanitizeDescription(description);
+ String text = sanitizeDescription(description, false);
sb.append(Strings.doubleQuote(text));
}
@@ -146,7 +146,7 @@ final class JsonSchemaHelper {
* @param javadoc the javadoc
* @return the text that is valid as json
*/
- public static String sanitizeDescription(String javadoc) {
+ public static String sanitizeDescription(String javadoc, boolean summary) {
// lets just use what java accepts as identifiers
StringBuilder sb = new StringBuilder();
@@ -165,23 +165,38 @@ final class JsonSchemaHelper {
// remove all HTML tags
line = line.replaceAll("<.*?>", "");
- // remove all inlined javadoc links
- line = line.replaceAll("\\{\\@\\w+\\s(\\w+)\\}", "$1");
+ // remove all inlined javadoc links, eg such as {@link org.apache.camel.spi.Registry}
+ line = line.replaceAll("\\{\\@\\w+\\s([\\w.]+)\\}", "$1");
// we are starting from a new line, so add a whitespace
if (!first) {
sb.append(' ');
}
+ // create a new line
+ StringBuilder cb = new StringBuilder();
for (char c : line.toCharArray()) {
if (Character.isJavaIdentifierPart(c) || VALID_CHARS.indexOf(c) != -1) {
- sb.append(c);
+ cb.append(c);
} else if (Character.isWhitespace(c)) {
// always use space as whitespace, also for line feeds etc
- sb.append(' ');
+ cb.append(' ');
}
}
+ // append data
+ String s = cb.toString().trim();
+ sb.append(s);
+
+ boolean empty = Strings.isNullOrEmpty(s);
+ boolean endWithDot = s.endsWith(".");
+ boolean haveText = sb.length() > 0;
+
+ if (haveText && summary && (empty || endWithDot)) {
+ // if we only want a summary, then skip at first empty line we encounter, or if the sentence ends with a dot
+ break;
+ }
+
first = false;
}