You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/08/02 07:57:57 UTC
[camel-k-runtime] branch master updated: Allow endpoint DSL in
Camel k #122
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push:
new 9558a71 Allow endpoint DSL in Camel k #122
9558a71 is described below
commit 9558a71d96c1da3cc3c5cb70e7e90dc08a64a768
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Aug 1 16:39:44 2019 +0200
Allow endpoint DSL in Camel k #122
---
camel-k-loader-groovy/pom.xml | 5 ++++
.../k/loader/groovy/GroovyRoutesLoader.groovy | 3 ++-
.../groovy/dsl/IntegrationConfiguration.groovy | 24 ++++++++++++-----
.../apache/camel/k/loader/groovy/LoaderTest.groovy | 31 +++++++++++++++++++++-
.../test/resources/routes-with-endpoint-dsl.groovy | 21 +++++++++++++++
camel-k-loader-java/pom.xml | 5 ++++
.../camel/k/loader/java/RoutesLoaderTest.java | 3 ++-
.../test/resources/MyRoutesWithEndpointDsl.java | 23 ++++++++++++++++
camel-k-loader-js/pom.xml | 9 +++++++
.../camel/k/loader/js/JavaScriptRoutesLoader.java | 3 ++-
.../k/loader/js/dsl/IntegrationConfiguration.java | 19 ++++++++-----
.../apache/camel/k/loader/js/RoutesLoaderTest.java | 1 +
.../src/test/resources/routes-with-endpoint-dsl.js | 22 +++++++++++++++
camel-k-loader-kotlin/pom.xml | 7 ++++-
.../camel/k/loader/kotlin/KotlinRoutesLoader.kt | 12 ++++-----
.../loader/kotlin/dsl/IntegrationConfiguration.kt | 10 +++++--
.../org/apache/camel/k/loader/kotlin/LoaderTest.kt | 26 ++++++++++++++++--
.../test/resources/routes-with-endpoint-dsl.kts | 21 +++++++++++++++
.../maven/processors/CatalogProcessor3x.java | 4 +++
19 files changed, 222 insertions(+), 27 deletions(-)
diff --git a/camel-k-loader-groovy/pom.xml b/camel-k-loader-groovy/pom.xml
index fb383f9..bd96dc8 100644
--- a/camel-k-loader-groovy/pom.xml
+++ b/camel-k-loader-groovy/pom.xml
@@ -44,6 +44,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-endpointdsl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-groovy</artifactId>
<exclusions>
<exclusion>
diff --git a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/GroovyRoutesLoader.groovy b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/GroovyRoutesLoader.groovy
index 1321cb9..7af01f7 100644
--- a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/GroovyRoutesLoader.groovy
+++ b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/GroovyRoutesLoader.groovy
@@ -18,6 +18,7 @@ package org.apache.camel.k.loader.groovy
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder
import org.apache.camel.k.RoutesLoader
import org.apache.camel.k.Source
import org.apache.camel.k.loader.groovy.dsl.IntegrationConfiguration
@@ -34,7 +35,7 @@ class GroovyRoutesLoader implements RoutesLoader {
@Override
RouteBuilder load(CamelContext camelContext, Source source) throws Exception {
- return new RouteBuilder() {
+ return new EndpointRouteBuilder() {
@Override
void configure() throws Exception {
def ic = new ImportCustomizer()
diff --git a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationConfiguration.groovy b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationConfiguration.groovy
index 918afea..4eff02d 100644
--- a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationConfiguration.groovy
+++ b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationConfiguration.groovy
@@ -19,16 +19,24 @@ package org.apache.camel.k.loader.groovy.dsl
import org.apache.camel.Exchange
import org.apache.camel.Predicate
import org.apache.camel.Processor
-import org.apache.camel.builder.RouteBuilder
-import org.apache.camel.model.*
+import org.apache.camel.builder.BuilderSupport
+import org.apache.camel.builder.EndpointConsumerBuilder
+import org.apache.camel.builder.endpoint.EndpointBuilderFactory
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder
+import org.apache.camel.model.InterceptDefinition
+import org.apache.camel.model.InterceptFromDefinition
+import org.apache.camel.model.InterceptSendToEndpointDefinition
+import org.apache.camel.model.OnCompletionDefinition
+import org.apache.camel.model.OnExceptionDefinition
+import org.apache.camel.model.RouteDefinition
import org.apache.camel.spi.Registry
-class IntegrationConfiguration extends org.apache.camel.builder.BuilderSupport {
+class IntegrationConfiguration extends BuilderSupport implements EndpointBuilderFactory {
final Registry registry
final Components components
- final RouteBuilder builder
+ final EndpointRouteBuilder builder
- IntegrationConfiguration(RouteBuilder builder) {
+ IntegrationConfiguration(EndpointRouteBuilder builder) {
super(builder.context)
this.registry = this.context.registry
@@ -74,7 +82,11 @@ class IntegrationConfiguration extends org.apache.camel.builder.BuilderSupport {
}
}
- ProcessorDefinition from(String endpoint) {
+ RouteDefinition from(String endpoint) {
+ return builder.from(endpoint)
+ }
+
+ RouteDefinition from(EndpointConsumerBuilder endpoint) {
return builder.from(endpoint)
}
diff --git a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/LoaderTest.groovy b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/LoaderTest.groovy
index e019b03..056b47c 100644
--- a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/LoaderTest.groovy
+++ b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/LoaderTest.groovy
@@ -19,12 +19,13 @@ package org.apache.camel.k.loader.groovy
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.k.Source
import org.apache.camel.k.support.RuntimeSupport
+import org.apache.camel.model.FromDefinition
import org.apache.camel.model.ToDefinition
import spock.lang.Specification
class LoaderTest extends Specification {
- def "load route from classpath"() {
+ def "load routes"() {
given:
def context = new DefaultCamelContext()
def source = Source.create("classpath:routes.groovy")
@@ -46,4 +47,32 @@ class LoaderTest extends Specification {
routes[0].outputs[0] instanceof ToDefinition
routes[0].input.endpointUri == 'timer:tick'
}
+
+ def "load routes with endpoint dsl"() {
+ given:
+ def context = new DefaultCamelContext()
+ def source = Source.create("classpath:routes-with-endpoint-dsl.groovy")
+
+ when:
+ def loader = RuntimeSupport.loaderFor(context, source)
+ def builder = loader.load(context, source)
+
+ then:
+ loader instanceof GroovyRoutesLoader
+ builder != null
+
+ builder.setContext(context)
+ builder.configure()
+
+ def routes = builder.routeCollection.routes
+
+ routes.size() == 1
+
+ with(routes[0].input, FromDefinition) {
+ it.endpointUri == 'timer:tick?period=1s'
+ }
+ with(routes[0].outputs[0], ToDefinition) {
+ it.endpointUri == 'log:info'
+ }
+ }
}
diff --git a/camel-k-loader-groovy/src/test/resources/routes-with-endpoint-dsl.groovy b/camel-k-loader-groovy/src/test/resources/routes-with-endpoint-dsl.groovy
new file mode 100644
index 0000000..1e69931
--- /dev/null
+++ b/camel-k-loader-groovy/src/test/resources/routes-with-endpoint-dsl.groovy
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+def f = timer('tick').period('1s')
+def t = log('info')
+
+from(f)
+ .to(t)
\ No newline at end of file
diff --git a/camel-k-loader-java/pom.xml b/camel-k-loader-java/pom.xml
index e2f3799..80f51ee 100644
--- a/camel-k-loader-java/pom.xml
+++ b/camel-k-loader-java/pom.xml
@@ -38,6 +38,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-endpointdsl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.jooq</groupId>
<artifactId>joor-java-8</artifactId>
<version>${joor.version}</version>
diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java
index a778a07..3db52d4 100644
--- a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java
+++ b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java
@@ -140,7 +140,8 @@ public class RoutesLoaderTest {
Arguments.arguments("classpath:" + MyRoutes.class.getName() + ".class", JavaClassRoutesLoader.class),
Arguments.arguments("classpath:MyRoutes.java", JavaSourceRoutesLoader.class),
Arguments.arguments("classpath:MyRoutesWithNameOverride.java?name=MyRoutes.java", JavaSourceRoutesLoader.class),
- Arguments.arguments("classpath:MyRoutesWithPackage.java", JavaSourceRoutesLoader.class)
+ Arguments.arguments("classpath:MyRoutesWithPackage.java", JavaSourceRoutesLoader.class),
+ Arguments.arguments("classpath:MyRoutesWithEndpointDsl.java", JavaSourceRoutesLoader.class)
);
}
}
diff --git a/camel-k-loader-java/src/test/resources/MyRoutesWithEndpointDsl.java b/camel-k-loader-java/src/test/resources/MyRoutesWithEndpointDsl.java
new file mode 100644
index 0000000..2a60931
--- /dev/null
+++ b/camel-k-loader-java/src/test/resources/MyRoutesWithEndpointDsl.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+public class MyRoutesWithEndpointDsl extends org.apache.camel.builder.endpoint.EndpointRouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ from(timer("tick"))
+ .to(log("info"));
+ }
+}
\ No newline at end of file
diff --git a/camel-k-loader-js/pom.xml b/camel-k-loader-js/pom.xml
index 561c1c2..99d2cb7 100644
--- a/camel-k-loader-js/pom.xml
+++ b/camel-k-loader-js/pom.xml
@@ -38,6 +38,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-endpointdsl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
@@ -127,6 +132,10 @@
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-endpointdsl</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/JavaScriptRoutesLoader.java b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/JavaScriptRoutesLoader.java
index c6ad4d2..e443a45 100644
--- a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/JavaScriptRoutesLoader.java
+++ b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/JavaScriptRoutesLoader.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.k.RoutesLoader;
import org.apache.camel.k.Source;
import org.apache.camel.k.loader.js.dsl.IntegrationConfiguration;
@@ -42,7 +43,7 @@ public class JavaScriptRoutesLoader implements RoutesLoader {
@Override
public RouteBuilder load(CamelContext camelContext, Source source) throws Exception {
- return new RouteBuilder() {
+ return new EndpointRouteBuilder() {
@Override
public void configure() throws Exception {
final Context context = Context.newBuilder("js").allowAllAccess(true).build();
diff --git a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java
index a8782b8..11fee49 100644
--- a/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java
+++ b/camel-k-loader-js/src/main/java/org/apache/camel/k/loader/js/dsl/IntegrationConfiguration.java
@@ -16,23 +16,26 @@
*/
package org.apache.camel.k.loader.js.dsl;
-import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.BuilderSupport;
+import org.apache.camel.builder.EndpointConsumerBuilder;
+import org.apache.camel.builder.endpoint.EndpointBuilderFactory;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.model.InterceptDefinition;
import org.apache.camel.model.InterceptFromDefinition;
import org.apache.camel.model.InterceptSendToEndpointDefinition;
import org.apache.camel.model.OnCompletionDefinition;
import org.apache.camel.model.OnExceptionDefinition;
-import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.Registry;
-public class IntegrationConfiguration extends org.apache.camel.builder.BuilderSupport {
+public class IntegrationConfiguration extends BuilderSupport implements EndpointBuilderFactory {
public final Registry registry;
public final Components components;
- public final RouteBuilder builder;
+ public final EndpointRouteBuilder builder;
- public IntegrationConfiguration(RouteBuilder builder) {
+ public IntegrationConfiguration(EndpointRouteBuilder builder) {
super(builder.getContext());
this.registry = builder.getContext().getRegistry();
@@ -40,7 +43,11 @@ public class IntegrationConfiguration extends org.apache.camel.builder.BuilderSu
this.builder = builder;
}
- public ProcessorDefinition from(String endpoint) {
+ public RouteDefinition from(String endpoint) {
+ return builder.from(endpoint);
+ }
+
+ public RouteDefinition from(EndpointConsumerBuilder endpoint) {
return builder.from(endpoint);
}
diff --git a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java
index 05e417f..8be5e9f 100644
--- a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java
+++ b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java
@@ -55,6 +55,7 @@ public class RoutesLoaderTest {
static Stream<Arguments> parameters() {
return Stream.of(
Arguments.arguments("classpath:routes.js", JavaScriptRoutesLoader.class),
+ Arguments.arguments("classpath:routes-with-endpoint-dsl.js", JavaScriptRoutesLoader.class),
Arguments.arguments("classpath:routes-compressed.js.gz.b64?language=js&compression=true", JavaScriptRoutesLoader.class),
Arguments.arguments("classpath:routes.mytype?language=js", JavaScriptRoutesLoader.class)
);
diff --git a/camel-k-loader-js/src/test/resources/routes-with-endpoint-dsl.js b/camel-k-loader-js/src/test/resources/routes-with-endpoint-dsl.js
new file mode 100644
index 0000000..fc8456d
--- /dev/null
+++ b/camel-k-loader-js/src/test/resources/routes-with-endpoint-dsl.js
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+f = timer("tick");
+t = log("info");
+
+from(f)
+ .to(t);
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/pom.xml b/camel-k-loader-kotlin/pom.xml
index 573c570..f7c3b75 100644
--- a/camel-k-loader-kotlin/pom.xml
+++ b/camel-k-loader-kotlin/pom.xml
@@ -39,7 +39,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-main</artifactId>
+ <artifactId>camel-endpointdsl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@@ -102,6 +102,11 @@
<artifactId>camel-properties</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-main</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- ******************************* -->
<!-- test deps :: misc -->
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/KotlinRoutesLoader.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/KotlinRoutesLoader.kt
index ea1950b..cc8fb22 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/KotlinRoutesLoader.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/KotlinRoutesLoader.kt
@@ -17,7 +17,7 @@
package org.apache.camel.k.loader.kotlin
import org.apache.camel.CamelContext
-import org.apache.camel.builder.RouteBuilder
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder
import org.apache.camel.k.RoutesLoader
import org.apache.camel.k.Source
import org.apache.camel.k.loader.kotlin.dsl.IntegrationConfiguration
@@ -25,11 +25,11 @@ import org.apache.camel.k.support.URIResolver
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.InputStreamReader
-import kotlin.script.experimental.api.*
+import kotlin.script.experimental.api.ScriptDiagnostic
+import kotlin.script.experimental.api.ScriptEvaluationConfiguration
+import kotlin.script.experimental.api.constructorArgs
import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
-import kotlin.script.experimental.jvm.dependenciesFromClassloader
-import kotlin.script.experimental.jvm.jvm
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
import kotlin.script.experimental.jvmhost.JvmScriptCompiler
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
@@ -44,8 +44,8 @@ class KotlinRoutesLoader : RoutesLoader {
}
@Throws(Exception::class)
- override fun load(camelContext: CamelContext, source: Source): RouteBuilder? {
- return object : RouteBuilder() {
+ override fun load(camelContext: CamelContext, source: Source): EndpointRouteBuilder? {
+ return object : EndpointRouteBuilder() {
@Throws(Exception::class)
override fun configure() {
val builder = this
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
index 84dccc2..a6b6b8e 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
@@ -19,7 +19,10 @@ package org.apache.camel.k.loader.kotlin.dsl
import org.apache.camel.Exchange
import org.apache.camel.Predicate
import org.apache.camel.Processor
-import org.apache.camel.builder.RouteBuilder
+import org.apache.camel.builder.BuilderSupport
+import org.apache.camel.builder.EndpointConsumerBuilder
+import org.apache.camel.builder.endpoint.EndpointBuilderFactory
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder
import org.apache.camel.k.loader.kotlin.KotlinCompilationConfiguration
import org.apache.camel.model.*
import org.apache.camel.spi.Registry
@@ -28,7 +31,7 @@ import kotlin.script.experimental.annotations.KotlinScript
@KotlinScript(fileExtension = "kts", compilationConfiguration = KotlinCompilationConfiguration::class)
abstract class IntegrationConfiguration(
private val registry : Registry,
- private val builder : RouteBuilder) : org.apache.camel.builder.BuilderSupport(builder.context) {
+ private val builder : EndpointRouteBuilder) : BuilderSupport(builder.context), EndpointBuilderFactory {
fun rest(block: RestConfiguration.() -> Unit) {
RestConfiguration(builder).block()
@@ -53,6 +56,9 @@ abstract class IntegrationConfiguration(
return builder.from(uri)
}
+ fun from(endpoint: EndpointConsumerBuilder): RouteDefinition {
+ return builder.from(endpoint)
+ }
fun intercept() : InterceptDefinition {
return builder.intercept()
diff --git a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
index 9567b0a..2bde812 100644
--- a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
+++ b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test
class LoaderTest {
@Test
- fun `load route from classpath`() {
+ fun `load routes`() {
var context = DefaultCamelContext()
var source = Source.create("classpath:routes.kts")
val loader = RuntimeSupport.loaderFor(context, source)
@@ -41,8 +41,30 @@ class LoaderTest {
val routes = builder.routeCollection.routes
assertThat(routes).hasSize(1)
- assertThat(routes[0].getInput().endpointUri).isEqualTo("timer:tick")
+ assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick")
assertThat(routes[0].outputs[0]).isInstanceOf(ProcessDefinition::class.java)
assertThat(routes[0].outputs[1]).isInstanceOf(ToDefinition::class.java)
}
+
+ @Test
+ fun `load routes with endpoint dsl`() {
+ var context = DefaultCamelContext()
+ var source = Source.create("classpath:routes-with-endpoint-dsl.kts")
+ val loader = RuntimeSupport.loaderFor(context, source)
+ val builder = loader.load(context, source)
+
+ assertThat(loader).isInstanceOf(KotlinRoutesLoader::class.java)
+ assertThat(builder).isNotNull
+
+ builder.context = context
+ builder.configure()
+
+ val routes = builder.routeCollection.routes
+ assertThat(routes).hasSize(1)
+ assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick?period=1s")
+ assertThat(routes[0].outputs[0]).isInstanceOfSatisfying(ToDefinition::class.java) {
+ assertThat(it.endpointUri).isEqualTo("log:info")
+ }
+
+ }
}
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-endpoint-dsl.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-endpoint-dsl.kts
new file mode 100644
index 0000000..fc04af9
--- /dev/null
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-endpoint-dsl.kts
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+var f = timer("tick").period("1s")
+var t = log("info")
+
+from(f)
+ .to(t)
\ No newline at end of file
diff --git a/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java b/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
index 698850f..962f95c 100644
--- a/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
+++ b/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
@@ -111,6 +111,7 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-loader-groovy");
artifact.setVersion(project.getVersion());
+ artifact.addDependency("org.apache.camel", "camel-endpointdsl");
artifact.addDependency("org.apache.camel", "camel-groovy");
artifacts.put(artifact.getArtifactId(), artifact);
@@ -127,6 +128,7 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-loader-kotlin");
artifact.setVersion(project.getVersion());
+ artifact.addDependency("org.apache.camel", "camel-endpointdsl");
artifacts.put(artifact.getArtifactId(), artifact);
}
@@ -142,6 +144,7 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-loader-js");
artifact.setVersion(project.getVersion());
+ artifact.addDependency("org.apache.camel", "camel-endpointdsl");
artifacts.put(artifact.getArtifactId(), artifact);
}
@@ -172,6 +175,7 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-loader-java");
artifact.setVersion(project.getVersion());
+ artifact.addDependency("org.apache.camel", "camel-endpointdsl");
artifacts.put(artifact.getArtifactId(), artifact);
}