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

fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-upgrade-recipes.git


The following commit(s) were added to refs/heads/main by this push:
     new 41cd695  Upgrade to Camel 4.12.0
41cd695 is described below

commit 41cd695b9ce9d86ef3661349b70137e5f2472e63
Author: Jiri Ondrusek <ondrusek.j...@gmail.com>
AuthorDate: Tue May 20 14:27:58 2025 +0200

    Upgrade to Camel 4.12.0
---
 .../camel/upgrade/camel412/Java412Recipes.java     |  63 +++++
 .../src/main/resources/META-INF/rewrite/4.12.yaml  | 117 ++++++++
 .../org/apache/camel/upgrade/CamelTestUtil.java    |   3 +-
 .../apache/camel/upgrade/CamelUpdate412Test.java   | 308 +++++++++++++++++++++
 4 files changed, 490 insertions(+), 1 deletion(-)

diff --git 
a/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel412/Java412Recipes.java
 
b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel412/Java412Recipes.java
new file mode 100644
index 0000000..5f27bcc
--- /dev/null
+++ 
b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel412/Java412Recipes.java
@@ -0,0 +1,63 @@
+/*
+ * 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.upgrade.camel412;
+
+import lombok.EqualsAndHashCode;
+import lombok.RequiredArgsConstructor;
+import org.apache.camel.upgrade.AbstractCamelJavaVisitor;
+import org.apache.camel.upgrade.RecipesUtil;
+import org.openrewrite.ExecutionContext;
+import org.openrewrite.Recipe;
+import org.openrewrite.TreeVisitor;
+import org.openrewrite.java.tree.J;
+
+/**
+ * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_java_dsl";>Java
 DSL</a>
+ */
+@EqualsAndHashCode(callSuper = false)
+@RequiredArgsConstructor
+public class Java412Recipes extends Recipe {
+
+    private static final String M_END_CHOICE = 
"org.apache.camel.model.ChoiceDefinition endChoice()";
+
+    @Override
+    public String getDisplayName() {
+        return "Camel Java DSL change for camel 4.12";
+    }
+
+    @Override
+    public String getDescription() {
+        return "Apache Camel Java DSL migration from version 4.11 to 4.12.";
+    }
+
+    @Override
+    public TreeVisitor<?, ExecutionContext> getVisitor() {
+
+        return RecipesUtil.newVisitor(new AbstractCamelJavaVisitor() {
+            @Override
+            protected J.MethodInvocation 
doVisitMethodInvocation(J.MethodInvocation method, ExecutionContext context) {
+                J.MethodInvocation mi = super.doVisitMethodInvocation(method, 
context);
+
+                if (getMethodMatcher(M_END_CHOICE).matches(mi, false)) {
+                    return 
mi.withName(mi.getName().withSimpleName("end().endChoice"));
+                }
+
+                return mi;
+            }
+        });
+    }
+}
\ No newline at end of file
diff --git 
a/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.12.yaml 
b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.12.yaml
new file mode 100644
index 0000000..7d48e04
--- /dev/null
+++ b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.12.yaml
@@ -0,0 +1,117 @@
+#
+# 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.
+#
+
+#####
+# Rules coming from 
https://camel.apache.org/manual/camel-4x-upgrade-guide-4_112.html
+#####
+
+#####
+# Update the Camel project from 4.11 to 4.12
+#####
+---
+type: specs.openrewrite.org/v1beta/recipe
+name: org.apache.camel.upgrade.camel412.CamelMigrationRecipe
+displayName: Migrates `camel 4.11` application to `camel 4.12`
+description: Migrates `camel 4.11` application to `camel 4.12`.
+recipeList:
+  - org.apache.camel.upgrade.camel412.scanClassesMoved
+  - org.apache.camel.upgrade.camel412.scanClassesMovedMaven
+  # https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_java_dsl
+  - org.apache.camel.upgrade.camel412.Java412Recipes
+  - org.apache.camel.upgrade.camel412.xmlDslBearer
+  - org.apache.camel.upgrade.camel412.yamlDslBearer
+---
+#https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_camel_core
+type: specs.openrewrite.org/v1beta/recipe
+name: org.apache.camel.upgrade.camel412.scanClassesMoved
+displayName: The package scan classes has moved from camel-base-engine to 
camel-support - java
+description: The package scan classes has moved from camel-base-engine to 
camel-support JAR and moved to a new package - java.
+recipeList:
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.engine.DefaultPackageScanClassResolver
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.DefaultPackageScanClassResolver
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.engine.DefaultPackageScanResourceResolver
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.DefaultPackageScanResourceResolver
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.engine.WebSpherePackageScanClassResolver
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.WebSpherePackageScanClassResolver
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.scan.AnnotatedWithAnyPackageScanFilter
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.AnnotatedWithAnyPackageScanFilter
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.scan.AnnotatedWithPackageScanFilter
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.AnnotatedWithPackageScanFilter
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.scan.AssignableToPackageScanFilter
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.AssignableToPackageScanFilter
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.scan.CompositePackageScanFilter
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.CompositePackageScanFilter
+  - org.openrewrite.java.ChangeType:
+      oldFullyQualifiedTypeName: 
org.apache.camel.impl.scan.InvertingPackageScanFilter
+      newFullyQualifiedTypeName: 
org.apache.camel.support.scan.InvertingPackageScanFilter
+
+---
+#https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_camel_core
+type: specs.openrewrite.org/v1beta/recipe
+name: org.apache.camel.upgrade.camel412.scanClassesMovedMaven
+displayName: The package scan classes has moved from camel-base-engine to 
camel-support - maven
+description: The package scan classes has moved from camel-base-engine to 
camel-support JAR and moved to a new package - maven.
+recipeList:
+  - org.openrewrite.maven.AddDependency:
+      groupId: org.apache.camel
+      artifactId: camel-support
+      version: PLEASE_DEFINE_VERSION #if the version is defined in the pom, 
this value is omitted
+      onlyIfUsing: org.apache.camel.impl.scan.*
+  - org.openrewrite.maven.AddDependency:
+      groupId: org.apache.camel
+      artifactId: camel-support
+      version: PLEASE_DEFINE_VERSION #if the version is defined in the pom, 
this value is omitted
+      onlyIfUsing: org.apache.camel.impl.engine.DefaultPackageScanClassResolver
+  - org.openrewrite.maven.AddDependency:
+      groupId: org.apache.camel
+      artifactId: camel-support
+      version: PLEASE_DEFINE_VERSION #if the version is defined in the pom, 
this value is omitted
+      onlyIfUsing: 
org.apache.camel.impl.engine.DefaultPackageScanResourceResolver
+  - org.openrewrite.maven.AddDependency:
+      groupId: org.apache.camel
+      artifactId: camel-support
+      version: PLEASE_DEFINE_VERSION #if the version is defined in the pom, 
this value is omitted
+      onlyIfUsing: 
org.apache.camel.impl.engine.WebSpherePackageScanClassResolver
+---
+#https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_rest_dsl
+type: specs.openrewrite.org/v1beta/recipe
+name: org.apache.camel.upgrade.camel412.xmlDslBearer
+displayName: XML DSL bearer from rest/securityDefinitions is renamed to 
bearerToken
+description: Rest definition in XML DSL with security constraints, then bearer 
in YAML and XML DSL has been renamed to bearerToken to be aligned with Java DSL.
+recipeList:
+  - org.openrewrite.xml.ChangeTagName:
+      elementName: //rest/securityDefinitions/bearer
+      newName: bearerToken
+---
+#https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_rest_dsl
+type: specs.openrewrite.org/v1beta/recipe
+name: org.apache.camel.upgrade.camel412.yamlDslBearer
+displayName: Yaml DSL bearer from rest/securityDefinitions is renamed to 
bearerToken
+description: Rest definition in Yaml DSL with security constraints, then 
bearer in YAML and XML DSL has been renamed to bearerToken to be aligned with 
Java DSL.
+recipeList:
+  - org.openrewrite.yaml.ChangeKey:
+      oldKeyPath: $.rest.securityDefinitions.bearer
+      newKey: bearerToken
+
+
diff --git 
a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelTestUtil.java
 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelTestUtil.java
index 8126703..11928ee 100644
--- 
a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelTestUtil.java
+++ 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelTestUtil.java
@@ -47,7 +47,8 @@ public class CamelTestUtil {
         v4_8(4, 8, 0),
         v4_9(4, 9, 0),
         v4_10(4, 10, 0),
-        v4_11(4, 11, 0);
+        v4_11(4, 11, 0),
+        v4_12(4, 12, 0);
 
         private int major;
         private int minor;
diff --git 
a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate412Test.java
 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate412Test.java
new file mode 100644
index 0000000..027ee60
--- /dev/null
+++ 
b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate412Test.java
@@ -0,0 +1,308 @@
+/*
+ * 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.upgrade;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+import org.openrewrite.test.TypeValidation;
+import org.openrewrite.yaml.Assertions;
+
+import static org.openrewrite.java.Assertions.*;
+import static org.openrewrite.maven.Assertions.pomXml;
+import static org.openrewrite.xml.Assertions.xml;
+
+public class CamelUpdate412Test implements RewriteTest {
+
+    @Override
+    public void defaults(RecipeSpec spec) {
+        CamelTestUtil.recipe(spec, CamelTestUtil.CamelVersion.v4_12)
+                
.parser(CamelTestUtil.parserFromClasspath(CamelTestUtil.CamelVersion.v4_11, 
"camel-api",
+                        "camel-core-model", "camel-support", 
"camel-base-engine", "camel-base"))
+                .typeValidationOptions(TypeValidation.none());
+    }
+
+
+
+    /**
+     * The package scan classes has moved from camel-base-engine to 
camel-support
+     *
+     * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_camel_core";>Moved
 scan classes</a>
+     */
+    @ParameterizedTest
+    
@CsvSource({"DefaultPackageScanClassResolver,org.apache.camel.impl.engine,org.apache.camel.support.scan",
+                
"DefaultPackageScanResourceResolver,org.apache.camel.impl.engine,org.apache.camel.support.scan",
+                
"WebSpherePackageScanClassResolver,org.apache.camel.impl.engine, 
org.apache.camel.support.scan",
+                "AnnotatedWithAnyPackageScanFilter,org.apache.camel.impl.scan, 
org.apache.camel.support.scan",
+                "AnnotatedWithPackageScanFilter,org.apache.camel.impl.scan, 
org.apache.camel.support.scan",
+                "AssignableToPackageScanFilter,org.apache.camel.impl.scan, 
org.apache.camel.support.scan",
+                "CompositePackageScanFilter,org.apache.camel.impl.scan, 
org.apache.camel.support.scan",
+                "InvertingPackageScanFilter,org.apache.camel.impl.scan, 
org.apache.camel.support.scan"})
+    public void testMovedScanClasses(String className, String originalImport, 
String expectedImport) {
+        rewriteRun(
+                mavenProject("testMovedScanClasses",
+                    sourceSet(java(
+                        String.format("""
+                                     import %s.%s;
+                                     
+                                     public class Test {
+                                         public void test() {
+                                             %s b = null;
+                                         }
+                                     }
+                                """, originalImport, className, className),
+                        String.format("""
+                                     import %s.%s;
+                                     
+                                     public class Test {
+                                         public void test() {
+                                             %s b = null;
+                                         }
+                                     }
+                                """, expectedImport, className, 
className)).iterator().next(), "src/man/java"), pomXml(
+                                """
+                                        <project>
+                                           <modelVersion>4.0.0</modelVersion>
+                
+                                           <artifactId>test</artifactId>
+                                           
<groupId>org.apache.camel.test</groupId>
+                                           <version>1.0.0</version>
+                
+                                           <properties>
+                                               
<camel.version>4.11.0</camel.version>
+                                           </properties>
+                                           
+                                               <dependencyManagement>
+                                                       <dependencies>>
+                                                               <dependency>
+                                                                       
<groupId>io.quarkus.platform</groupId>
+                                                                       
<artifactId>quarkus-camel-bom</artifactId>
+                                                                       
<version>3.2.11.Final</version>
+                                                                       
<type>pom</type>
+                                                                       
<scope>import</scope>
+                                                               </dependency>
+                                                       </dependencies>
+                                               </dependencyManagement>
+                
+                                           <dependencies>
+                                               <dependency>
+                                                   
<groupId>org.apache.camel</groupId>
+                                                   
<artifactId>camel-base</artifactId>
+                                               </dependency>
+                                            </dependencies>
+                
+                                        </project>
+                                        """,
+                                """
+                                        <project>
+                                           <modelVersion>4.0.0</modelVersion>
+                
+                                           <artifactId>test</artifactId>
+                                           
<groupId>org.apache.camel.test</groupId>
+                                           <version>1.0.0</version>
+                
+                                           <properties>
+                                               
<camel.version>4.11.0</camel.version>
+                                           </properties>
+                                           
+                                               <dependencyManagement>
+                                                       <dependencies>>
+                                                               <dependency>
+                                                                       
<groupId>io.quarkus.platform</groupId>
+                                                                       
<artifactId>quarkus-camel-bom</artifactId>
+                                                                       
<version>3.2.11.Final</version>
+                                                                       
<type>pom</type>
+                                                                       
<scope>import</scope>
+                                                               </dependency>
+                                                       </dependencies>
+                                               </dependencyManagement>
+                
+                                           <dependencies>
+                                               <dependency>
+                                                   
<groupId>org.apache.camel</groupId>
+                                                   
<artifactId>camel-base</artifactId>
+                                               </dependency>
+                                              <dependency>
+                                                 
<groupId>org.apache.camel</groupId>
+                                                 
<artifactId>camel-support</artifactId>
+                                              </dependency>
+                                            </dependencies>
+                
+                                        </project>
+                                        """)
+                ));
+    }
+
+    /**
+     * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_java_dsl";>Java
 DSL</a>
+     */
+    @Test
+    void testJavaDslChoice() {
+        //language=java
+        rewriteRun(java("""
+                import org.apache.camel.ExchangePattern;
+                import org.apache.camel.builder.RouteBuilder;
+            
+                public class MySimpleToDRoute extends RouteBuilder {
+            
+                    @Override
+                    public void configure() {
+            
+                        from("direct:start")
+                            .choice()
+                                .when(header("foo").isGreaterThan(1))
+                                    .choice()
+                                        .when(header("foo").isGreaterThan(5))
+                                            .to("mock:big")
+                                        .otherwise()
+                                            .to("mock:med")
+                                    .endChoice()
+                                .otherwise()
+                                    .to("mock:low")
+                                .end();
+                    }
+                }
+                """, """
+                import org.apache.camel.ExchangePattern;
+                import org.apache.camel.builder.RouteBuilder;
+                
+                public class MySimpleToDRoute extends RouteBuilder {
+                
+                    @Override
+                    public void configure() {
+                        
+                        from("direct:start")
+                            .choice()
+                                .when(header("foo").isGreaterThan(1))
+                                    .choice()
+                                        .when(header("foo").isGreaterThan(5))
+                                            .to("mock:big")
+                                        .otherwise()
+                                            .to("mock:med")
+                                    .end().endChoice()
+                                .otherwise()
+                                    .to("mock:low")
+                                .end();
+                    }
+                }
+                """));
+    }
+
+    /**
+     * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_rest_dsl";>Rest
 DSL</a>
+     */
+    @Test
+    public void testXmlDslBearer() {
+        //language=xml
+        rewriteRun(xml("""
+                <camelContext xmlns="http://camel.apache.org/schema/spring";>
+                    <rest path="/user" description="User rest service" 
consumes="application/json" produces="application/json">
+                        <securityDefinitions>
+                            <bearer key="myBearerKey" description="Bearer 
token for security"/>
+                        </securityDefinitions>
+                        <get path="/hello">
+                            <to uri="direct:hello"/>
+                        </get>
+                        <get path="/bye" consumes="application/json">
+                            <to uri="direct:bye"/>
+                        </get>
+                        <post path="/bye">
+                            <to uri="mock:update"/>
+                        </post>
+                    </rest>
+                </camelContext>
+                """, """
+                <camelContext xmlns="http://camel.apache.org/schema/spring";>
+                    <rest path="/user" description="User rest service" 
consumes="application/json" produces="application/json">
+                        <securityDefinitions>
+                            <bearerToken key="myBearerKey" description="Bearer 
token for security"/>
+                        </securityDefinitions>
+                        <get path="/hello">
+                            <to uri="direct:hello"/>
+                        </get>
+                        <get path="/bye" consumes="application/json">
+                            <to uri="direct:bye"/>
+                        </get>
+                        <post path="/bye">
+                            <to uri="mock:update"/>
+                        </post>
+                    </rest>
+                </camelContext>
+                """));    }
+
+    /**
+     * <a 
href="https://camel.apache.org/manual/camel-4x-upgrade-guide-4_12.html#_rest_dsl";>Rest
 DSL</a>
+     */
+    @Test
+    public void testYamlDslBearer() {
+        //language=yaml
+        rewriteRun(Assertions.yaml("""
+                    - rest:
+                        path: "/user"
+                        description: "User rest service"
+                        consumes: "application/json"
+                        produces: "application/json"
+                        securityDefinitions:
+                            bearer:
+                              key: "test"
+                        get:
+                          - path: "/hello"
+                            to: "direct:hello"
+                          - path: "/bye"
+                            consumes: "application/json"
+                            to: "direct:bye"
+                        post:
+                          - path: "/bye"
+                            to: "mock:update"
+                    - route:
+                        id: loadbalance-failover-route
+                        from:
+                          uri: "direct://loadbalance-failover"
+                          steps:
+                            - log:
+                                message: "Processing message start: ${body}"   
                 
+                """, """
+                    - rest:
+                        path: "/user"
+                        description: "User rest service"
+                        consumes: "application/json"
+                        produces: "application/json"
+                        securityDefinitions:
+                            bearerToken:
+                              key: "test"
+                        get:
+                          - path: "/hello"
+                            to: "direct:hello"
+                          - path: "/bye"
+                            consumes: "application/json"
+                            to: "direct:bye"
+                        post:
+                          - path: "/bye"
+                            to: "mock:update"
+                    - route:
+                        id: loadbalance-failover-route
+                        from:
+                          uri: "direct://loadbalance-failover"
+                          steps:
+                            - log:
+                                message: "Processing message start: ${body}"  
+                """));
+    }
+
+}

Reply via email to