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 2020/10/02 15:15:30 UTC
[camel] branch master updated: [CAMEL-15621] Support partial routes
containing only the "from" for (#4350)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new b48f995 [CAMEL-15621] Support partial routes containing only the "from" for (#4350)
b48f995 is described below
commit b48f995f98e1b429097eaefdb95dc4f97fc171bd
Author: Aurélien Pupier <ap...@redhat.com>
AuthorDate: Fri Oct 2 17:11:10 2020 +0200
[CAMEL-15621] Support partial routes containing only the "from" for (#4350)
RouteBuilderParser.parseRouteBuilderTree
Signed-off-by: Aurélien Pupier <ap...@redhat.com>
---
.../parser/helper/CamelJavaTreeParserHelper.java | 3 +-
.../apache/camel/parser/java/MyPartialRoute.java | 27 ++++++++++
.../java/RoasterJavaPartialRouteDslTest.java | 58 ++++++++++++++++++++++
3 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
index 8337b07..64e251b 100644
--- a/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
+++ b/catalog/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
@@ -182,8 +182,9 @@ public final class CamelJavaTreeParserHelper {
rootMethodName = ((MethodInvocation) sub).getName().getIdentifier();
} else if (sub instanceof SimpleName) {
rootMethodName = ((SimpleName) sub).getIdentifier();
+ } else if (sub == null && exp instanceof MethodInvocation) {
+ rootMethodName = ((MethodInvocation) exp).getName().getIdentifier();
}
-
// a route starts either via from or route
return "from".equals(rootMethodName) || "route".equals(rootMethodName);
}
diff --git a/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyPartialRoute.java b/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyPartialRoute.java
new file mode 100644
index 0000000..5648024
--- /dev/null
+++ b/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyPartialRoute.java
@@ -0,0 +1,27 @@
+/*
+ * 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.parser.java;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyPartialRoute extends RouteBuilder {
+
+ @Override
+ public void configure() {
+ from("timer:foo");
+ }
+}
diff --git a/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaPartialRouteDslTest.java b/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaPartialRouteDslTest.java
new file mode 100644
index 0000000..5be33e6
--- /dev/null
+++ b/catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaPartialRouteDslTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.parser.java;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.camel.parser.RouteBuilderParser;
+import org.apache.camel.parser.model.CamelNodeDetails;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.jboss.forge.roaster.Roaster;
+import org.jboss.forge.roaster.model.source.JavaClassSource;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class RoasterJavaPartialRouteDslTest extends CamelTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RoasterJavaPartialRouteDslTest.class);
+
+ @Test
+ void parseTree() throws Exception {
+ String pathToFile = "src/test/java/org/apache/camel/parser/java/MyPartialRoute.java";
+ JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File(pathToFile));
+
+ List<CamelNodeDetails> list = RouteBuilderParser.parseRouteBuilderTree(clazz, ".", pathToFile, true);
+ assertEquals(1, list.size());
+ CamelNodeDetails details = list.get(0);
+ assertEquals(pathToFile, details.getFileName());
+ assertEquals("configure", details.getMethodName());
+ assertEquals("org.apache.camel.parser.java.MyPartialRoute", details.getClassName());
+ assertEquals("25", list.get(0).getLineNumber());
+ assertEquals("25", list.get(0).getLineNumberEnd());
+
+ String tree = details.dump(0);
+ LOG.info("\n" + tree);
+
+ assertTrue(tree.contains("25\tfrom"));
+ }
+
+}