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 2021/04/08 21:40:22 UTC
[camel] 02/04: dsl: add common dsl module
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.git
commit 5e1d9c11bb9edd268d613d4d3168377432063ba1
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Thu Apr 8 15:45:30 2021 +0200
dsl: add common dsl module
---
bom/camel-bom/pom.xml | 5 ++
dsl/camel-dsl-support/pom.xml | 68 +++++++++++++++++++
.../support/EndpointRouteBuilderLoaderSupport.java | 42 ++++++++++++
.../dsl/support/RouteBuilderLoaderSupport.java | 79 ++++++++++++++++++++++
dsl/pom.xml | 1 +
parent/pom.xml | 5 ++
6 files changed, 200 insertions(+)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 5dadc0e..9ea693d 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -644,6 +644,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-dsl-support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-ehcache</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/dsl/camel-dsl-support/pom.xml b/dsl/camel-dsl-support/pom.xml
new file mode 100644
index 0000000..47e2a82
--- /dev/null
+++ b/dsl/camel-dsl-support/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>dsl</artifactId>
+ <version>3.10.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-dsl-support</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: DSL :: Support</name>
+ <description>Camel DSL (Support))</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-endpointdsl</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-package-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-spi</id>
+ <goals>
+ <goal>generate-spi</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/EndpointRouteBuilderLoaderSupport.java b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/EndpointRouteBuilderLoaderSupport.java
new file mode 100644
index 0000000..863e82e
--- /dev/null
+++ b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/EndpointRouteBuilderLoaderSupport.java
@@ -0,0 +1,42 @@
+/*
+ * 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.dsl.support;
+
+import java.io.Reader;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+
+import static org.apache.camel.builder.endpoint.EndpointRouteBuilder.loadEndpointRoutesBuilder;
+
+/**
+ * Base class for {@link RoutesBuilderLoader} implementations.
+ */
+public abstract class EndpointRouteBuilderLoaderSupport extends RouteBuilderLoaderSupport {
+ protected EndpointRouteBuilderLoaderSupport(String extension) {
+ super(extension);
+ }
+
+ @Override
+ public RouteBuilder doLoadRouteBuilder(Resource resource) throws Exception {
+ return loadEndpointRoutesBuilder(resource, this::doLoadEndpointRouteBuilder);
+ }
+
+ protected abstract void doLoadEndpointRouteBuilder(Reader reader, EndpointRouteBuilder builder) throws Exception;
+}
diff --git a/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/RouteBuilderLoaderSupport.java b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/RouteBuilderLoaderSupport.java
new file mode 100644
index 0000000..021d007
--- /dev/null
+++ b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/RouteBuilderLoaderSupport.java
@@ -0,0 +1,79 @@
+/*
+ * 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.dsl.support;
+
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.StartupStep;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.RouteBuilderLifecycleStrategy;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+import org.apache.camel.spi.StartupStepRecorder;
+import org.apache.camel.support.RoutesBuilderLoaderSupport;
+
+/**
+ * Base class for {@link RoutesBuilderLoader} implementations.
+ */
+public abstract class RouteBuilderLoaderSupport extends RoutesBuilderLoaderSupport {
+ private final String extension;
+
+ private StartupStepRecorder recorder;
+
+ protected RouteBuilderLoaderSupport(String extension) {
+ this.extension = extension;
+ }
+
+ @ManagedAttribute(description = "Supported file extension")
+ @Override
+ public String getSupportedExtension() {
+ return extension;
+ }
+
+ @Override
+ protected void doBuild() throws Exception {
+ super.doBuild();
+
+ if (getCamelContext() != null) {
+ this.recorder = getCamelContext().adapt(ExtendedCamelContext.class).getStartupStepRecorder();
+ }
+ }
+
+ @Override
+ public RoutesBuilder loadRoutesBuilder(Resource resource) throws Exception {
+ final RouteBuilder builder = doLoadRouteBuilder(resource);
+
+ if (recorder != null) {
+ StartupStep step = recorder.beginStep(
+ getClass(),
+ resource.getLocation(),
+ "Loading route from: " + resource.getLocation());
+
+ builder.addLifecycleInterceptor(new RouteBuilderLifecycleStrategy() {
+ @Override
+ public void afterConfigure(RouteBuilder builder) {
+ step.endStep();
+ }
+ });
+ }
+
+ return builder;
+ }
+
+ protected abstract RouteBuilder doLoadRouteBuilder(Resource resource) throws Exception;
+}
diff --git a/dsl/pom.xml b/dsl/pom.xml
index 5e4457c..9ae56e6 100644
--- a/dsl/pom.xml
+++ b/dsl/pom.xml
@@ -34,6 +34,7 @@
<description>Camel DSLs Modules</description>
<modules>
+ <module>camel-dsl-support</module>
<module>camel-groovy-dsl</module>
<module>camel-java-joor-dsl</module>
<module>camel-xml-io-dsl</module>
diff --git a/parent/pom.xml b/parent/pom.xml
index 0373a3f..810b5c5 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1290,6 +1290,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-dsl-support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-ehcache</artifactId>
<version>${project.version}</version>
</dependency>