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 2022/06/04 19:13:09 UTC

[camel-spring-boot] branch main updated (0be08a09d47 -> c8f7d977cd1)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


    from 0be08a09d47 CAMEL-18153: Upgrade to spring boot 2.7.0 then upgrade other dependencies
     new 2cb91cd5b70 CAMEL-18166: camel-spring-boot - Make the route collector reuse as much from core.
     new c8f7d977cd1 CAMEL-18166: camel-spring-boot - Add support for endpoint-dsl route collector using @Bean style.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/spring/boot/CamelAutoConfiguration.java  |  2 +
 .../spring/boot/SpringBootRoutesCollector.java     | 90 ++--------------------
 .../src/main/resources/META-INF/spring.factories   | 16 ----
 dsl-starter/camel-endpointdsl-starter/pom.xml      |  5 ++
 .../endpointdsl/EndpointDslAutoConfiguration.java  | 20 ++---
 .../endpointdsl/EndpointDslRouteCollector.java     | 58 ++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  4 +-
 7 files changed, 80 insertions(+), 115 deletions(-)
 copy core/camel-spring-boot-xml/src/main/java/org/apache/camel/spring/boot/xml/CamelXmlAutoConfiguration.java => dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java (64%)
 create mode 100644 dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
 copy {components-starter/camel-cm-sms-starter => dsl-starter/camel-endpointdsl-starter}/src/main/resources/META-INF/spring.factories (93%)


[camel-spring-boot] 01/02: CAMEL-18166: camel-spring-boot - Make the route collector reuse as much from core.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit 2cb91cd5b709f7c6ef91f6f27368fdf00eeba8d1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Jun 4 18:19:55 2022 +0200

    CAMEL-18166: camel-spring-boot - Make the route collector reuse as much from core.
---
 .../spring/boot/SpringBootRoutesCollector.java     | 90 ++--------------------
 1 file changed, 5 insertions(+), 85 deletions(-)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
index 6775a539984..594bf1087b1 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
@@ -16,19 +16,10 @@
  */
 package org.apache.camel.spring.boot;
 
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.Collection;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.ExtendedCamelContext;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.LambdaRouteBuilder;
-import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.main.DefaultRoutesCollector;
-import org.apache.camel.util.AntPathMatcher;
-import org.apache.camel.util.ObjectHelper;
 import org.springframework.context.ApplicationContext;
 
 /**
@@ -43,80 +34,9 @@ public class SpringBootRoutesCollector extends DefaultRoutesCollector {
     }
 
     @Override
-    public List<RoutesBuilder> collectRoutesFromRegistry(final CamelContext camelContext, final String excludePattern, final String includePattern) {
-        final List<RoutesBuilder> routes = new ArrayList<>();
-
-        Set<LambdaRouteBuilder> lrbs = camelContext.getRegistry().findByType(LambdaRouteBuilder.class);
-        for (LambdaRouteBuilder lrb : lrbs) {
-            RouteBuilder rb = new RouteBuilder() {
-                @Override
-                public void configure() throws Exception {
-                    lrb.accept(this);
-                }
-            };
-            routes.add(rb);
-        }
-
-        final AntPathMatcher matcher = new AntPathMatcher();
-        for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class, true, true).values()) {
-            // filter out abstract classes
-            boolean abs = Modifier.isAbstract(routesBuilder.getClass().getModifiers());
-            if (!abs) {
-                String name = routesBuilder.getClass().getName();
-                // make name as path so we can use ant path matcher
-                name = name.replace('.', '/');
-
-                boolean match = !"false".equals(includePattern);
-
-                // special support for testing with @ExcludeRoutes annotation with camel-test modules
-                String exclude = camelContext.adapt(ExtendedCamelContext.class).getTestExcludeRoutes();
-                // exclude take precedence over include
-                if (match && ObjectHelper.isNotEmpty(exclude)) {
-                    // this property is a comma separated list of FQN class names, so we need to make
-                    // name as path so we can use ant patch matcher
-                    exclude = exclude.replace('.', '/');
-                    // there may be multiple separated by comma
-                    String[] parts = exclude.split(",");
-                    for (String part : parts) {
-                        // must negate when excluding, and hence !
-                        match = !matcher.match(part, name);
-                        log.trace("Java RoutesBuilder: {} exclude filter: {} -> {}", name, part, match);
-                        if (!match) {
-                            break;
-                        }
-                    }
-                }
-                // exclude take precedence over include
-                if (match && ObjectHelper.isNotEmpty(excludePattern)) {
-                    // there may be multiple separated by comma
-                    String[] parts = excludePattern.split(",");
-                    for (String part : parts) {
-                        // must negate when excluding, and hence !
-                        match = !matcher.match(part, name);
-                        log.trace("Java RoutesBuilder: {} exclude filter: {} -> {}", name, part, match);
-                        if (!match) {
-                            break;
-                        }
-                    }
-                }
-                if (match && ObjectHelper.isNotEmpty(includePattern)) {
-                    // there may be multiple separated by comma
-                    String[] parts = includePattern.split(",");
-                    for (String part : parts) {
-                        match = matcher.match(part, name);
-                        log.trace("Java RoutesBuilder: {} include filter: {} -> {}", name, part, match);
-                        if (match) {
-                            break;
-                        }
-                    }
-                }
-                log.debug("Java RoutesBuilder: {} accepted by include/exclude filter: {}", name, match);
-                if (match) {
-                    routes.add(routesBuilder);
-                }
-            }
-        }
-
-        return routes;
+    protected <T> Collection<T> findByType(CamelContext camelContext, Class<T> type) {
+        // lookup in application context
+        return applicationContext.getBeansOfType(type, true, true).values();
     }
+
 }


[camel-spring-boot] 02/02: CAMEL-18166: camel-spring-boot - Add support for endpoint-dsl route collector using @Bean style.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git

commit c8f7d977cd11707c1dbcf4e7cf8feefb7a1bddad
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Jun 4 21:12:59 2022 +0200

    CAMEL-18166: camel-spring-boot - Add support for endpoint-dsl route collector using @Bean style.
---
 .../camel/spring/boot/CamelAutoConfiguration.java  |  2 +
 .../src/main/resources/META-INF/spring.factories   | 16 ------
 dsl-starter/camel-endpointdsl-starter/pom.xml      |  5 ++
 .../endpointdsl/EndpointDslAutoConfiguration.java  | 35 +++++++++++++
 .../endpointdsl/EndpointDslRouteCollector.java     | 58 ++++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   | 20 ++++++++
 6 files changed, 120 insertions(+), 16 deletions(-)

diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index eb22b160277..c2c846edb93 100644
--- a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
@@ -171,6 +172,7 @@ public class CamelAutoConfiguration {
 
     @Bean
     @ConditionalOnMissingBean(RoutesCollector.class)
+    @ConditionalOnMissingClass("org.apache.camel.spring.boot.endpointdsl.EndpointDslRouteCollector")
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         return new SpringBootRoutesCollector(applicationContext);
     }
diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
index 5b32d258ad4..0a29f189e6e 100644
--- a/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
+++ b/core/camel-spring-boot/src/main/resources/META-INF/spring.factories
@@ -14,22 +14,6 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-#
-# 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.
-#
 
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 org.apache.camel.spring.boot.CamelAutoConfiguration,\
diff --git a/dsl-starter/camel-endpointdsl-starter/pom.xml b/dsl-starter/camel-endpointdsl-starter/pom.xml
index b6c3a2e7edc..66a4e399a3a 100644
--- a/dsl-starter/camel-endpointdsl-starter/pom.xml
+++ b/dsl-starter/camel-endpointdsl-starter/pom.xml
@@ -40,6 +40,11 @@
             <artifactId>spring-boot-starter</artifactId>
             <version>${spring-boot-version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.springboot</groupId>
+            <artifactId>camel-spring-boot</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-endpointdsl</artifactId>
diff --git a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
new file mode 100644
index 00000000000..2626428843b
--- /dev/null
+++ b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * 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.spring.boot.endpointdsl;
+
+import org.apache.camel.main.RoutesCollector;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Role;
+
+@Configuration(proxyBeanMethods = false)
+@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
+public class EndpointDslAutoConfiguration {
+
+    @Bean
+    RoutesCollector endpointDslRoutesCollector(ApplicationContext applicationContext) {
+        return new EndpointDslRouteCollector(applicationContext);
+    }
+
+}
diff --git a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
new file mode 100644
index 00000000000..d5d82c7d7b8
--- /dev/null
+++ b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.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.spring.boot.endpointdsl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
+import org.apache.camel.spring.boot.SpringBootRoutesCollector;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Enhanced {@link SpringBootRoutesCollector} that supports Endpoint DSL with the
+ * lambda style {@link LambdaEndpointRouteBuilder}.
+ */
+public class EndpointDslRouteCollector extends SpringBootRoutesCollector {
+
+    public EndpointDslRouteCollector(ApplicationContext applicationContext) {
+        super(applicationContext);
+    }
+
+    @Override
+    protected Collection<RoutesBuilder> collectAdditionalRoutesFromRegistry(CamelContext camelContext, String excludePattern, String includePattern) {
+        final List<RoutesBuilder> routes = new ArrayList<>();
+
+        Collection<LambdaEndpointRouteBuilder> lrbs = findByType(camelContext, LambdaEndpointRouteBuilder.class);
+        for (LambdaEndpointRouteBuilder lrb : lrbs) {
+            EndpointRouteBuilder rb = new EndpointRouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    lrb.accept(this);
+                }
+            };
+            routes.add(rb);
+        }
+
+        return routes;
+    }
+
+}
diff --git a/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories b/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 00000000000..05ef8619b9a
--- /dev/null
+++ b/dsl-starter/camel-endpointdsl-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,20 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.spring.boot.endpointdsl.EndpointDslAutoConfiguration
+