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.git


The following commit(s) were added to refs/heads/main by this push:
     new d67042a2c4a CAMEL-19072: camel-yaml-dsl - Remove backwards compatible 
3.15 parser
d67042a2c4a is described below

commit d67042a2c4a1fa59adf2c6cf05664faea97766da
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Feb 17 18:43:30 2023 +0100

    CAMEL-19072: camel-yaml-dsl - Remove backwards compatible 3.15 parser
---
 .../ROOT/pages/camel-4-migration-guide.adoc        |  27 +++
 .../camel/dsl/yaml/YamlRoutesBuilderLoader.java    |  48 +----
 .../camel/dsl/yaml/IntegrationLoaderTest.groovy    |  26 ---
 .../dsl/yaml/RoutesBackwardsCompatibleTest.groovy  | 220 ---------------------
 4 files changed, 28 insertions(+), 293 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
index db0a442ba88..40a31ebe3e8 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
@@ -54,6 +54,32 @@ Camel 4 has upgraded logging facade API `slf4j-api` from 1.7 
to 2.0.
 
 All the `camel-test` modules that were JUnit 4.x based has been removed. All 
test modules now use JUnit 5.
 
+== YAML DSL
+
+The backwards compatible mode Camel 3.14 or older, which allowed to have 
_steps_ as child to _route_ has been removed.
+
+The old syntax:
+
+[source,yaml]
+----
+- route:
+    from:
+      uri: "direct:info"
+    steps:
+    - log: "message"
+----
+
+should be changed to:
+
+[source,yaml]
+----
+- route:
+    from:
+      uri: "direct:info"
+      steps:
+      - log: "message"
+----
+
 == Backlog Tracing
 
 The option `backlogTracing=true` now automatic enabled the tracer on startup. 
The previous behavior
@@ -81,3 +107,4 @@ The `keyType` parameter has been removed. The Key for the 
cache will now be only
 === camel-fhir
 
 The underlying `hapi-fhir` library has been upgraded from 4.2.0 to 6.2.4. Only 
the `Delete` API method has changed and now returns 
`ca.uhn.fhir.rest.api.MethodOutcome` instead of 
`org.hl7.fhir.instance.model.api.IBaseOperationOutcome`. See 
https://hapifhir.io/hapi-fhir/blog/ for a more detailed list of underlying 
changes (only the hapi-fhir client is used in Camel).
+
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
index 4137d1888c2..3f129da0ae2 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
@@ -71,15 +71,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.snakeyaml.engine.v2.api.LoadSettings;
 import org.snakeyaml.engine.v2.api.YamlUnicodeReader;
-import org.snakeyaml.engine.v2.common.ScalarStyle;
 import org.snakeyaml.engine.v2.composer.Composer;
 import org.snakeyaml.engine.v2.nodes.MappingNode;
 import org.snakeyaml.engine.v2.nodes.Node;
 import org.snakeyaml.engine.v2.nodes.NodeTuple;
 import org.snakeyaml.engine.v2.nodes.NodeType;
-import org.snakeyaml.engine.v2.nodes.ScalarNode;
 import org.snakeyaml.engine.v2.nodes.SequenceNode;
-import org.snakeyaml.engine.v2.nodes.Tag;
 import org.snakeyaml.engine.v2.parser.Parser;
 import org.snakeyaml.engine.v2.parser.ParserImpl;
 import org.snakeyaml.engine.v2.scanner.StreamReader;
@@ -292,7 +289,7 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
 
     private Object preConfigureNode(Node root, YamlDeserializationContext ctx, 
boolean preParse) {
         // backwards compatible fixes
-        Object target = routeBackwardsCompatible(root, ctx, preParse);
+        Object target = root;
 
         // check if the yaml is a camel-k yaml with embedded binding/routes 
(called flow(s))
         if (Objects.equals(root.getNodeType(), NodeType.MAPPING)) {
@@ -314,48 +311,6 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         return target;
     }
 
-    private Object routeBackwardsCompatible(Node root, 
YamlDeserializationContext ctx, boolean preParse) {
-        Object target = root;
-
-        // look for every route (the root must be a sequence)
-        if (!isSequenceNode(root)) {
-            return target;
-        }
-
-        SequenceNode seq = asSequenceNode(root);
-        for (Node node : seq.getValue()) {
-            Node route = nodeAt(node, "/route");
-            if (route != null) {
-                // backwards compatible steps are under route, but should be 
under from
-                Node steps = nodeAt(route, "/steps");
-                if (steps != null) {
-                    int line = -1;
-                    if (steps.getStartMark().isPresent()) {
-                        line = steps.getStartMark().get().getLine();
-                    }
-                    String file = ctx.getResource().getLocation();
-                    LOG.warn("Deprecated route/steps detected in {}:{}", file, 
line
-                                                                               
+ ". To migrate move route/steps to route/from/steps");
-                    // move steps from route to from
-                    Node from = nodeAt(route, "/from");
-                    MappingNode mn = asMappingNode(from);
-                    if (mn != null && mn.getValue() != null) {
-                        ScalarNode sn = new ScalarNode(Tag.STR, "steps", 
ScalarStyle.PLAIN);
-                        NodeTuple nt = new NodeTuple(sn, steps);
-                        mn.getValue().add(nt);
-                        mn = asMappingNode(route);
-                        mn.getValue().removeIf(t -> {
-                            String k = asText(t.getKeyNode());
-                            return "steps".equals(k);
-                        });
-                    }
-                }
-            }
-        }
-
-        return target;
-    }
-
     /**
      * Camel K Integration file
      */
@@ -407,7 +362,6 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
                 if (routes.getNodeType() != NodeType.SEQUENCE) {
                     throw new InvalidNodeTypeException(routes, 
NodeType.SEQUENCE);
                 }
-                routes = (Node) routeBackwardsCompatible(routes, ctx, 
preParse);
                 answer.add(routes);
             }
         }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/IntegrationLoaderTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/IntegrationLoaderTest.groovy
index f714804f2ee..ff4ef00521f 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/IntegrationLoaderTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/IntegrationLoaderTest.groovy
@@ -206,30 +206,4 @@ class IntegrationLoaderTest extends YamlTestSupport {
         }
     }
 
-    def "integration with route backward"() {
-        when:
-        loadIntegrations('''
-                apiVersion: camel.apache.org/v1
-                kind: Integration
-                metadata:
-                  name: foobar3
-                spec:
-                  flows:
-                    - route:
-                        id: myRoute2
-                        from:
-                          uri: "seda:foo"
-                        steps:    
-                          - to: "mock:result"   
-                          ''')
-        then:
-        context.routeDefinitions.size() == 1
-
-        context.routeDefinitions[0].id == "myRoute2"
-
-        with(context.routeDefinitions[0].outputs[0], ToDefinition) {
-            uri == "mock:result"
-        }
-    }
-
 }
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RoutesBackwardsCompatibleTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RoutesBackwardsCompatibleTest.groovy
deleted file mode 100644
index f7d7789c7c8..00000000000
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RoutesBackwardsCompatibleTest.groovy
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * 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.yaml
-
-import org.apache.camel.dsl.yaml.support.YamlTestSupport
-import org.apache.camel.model.LogDefinition
-import org.apache.camel.model.RouteDefinition
-
-class RoutesBackwardsCompatibleTest extends YamlTestSupport {
-
-    def "load from"() {
-        when:
-            loadRoutes '''
-                - from:
-                    uri: "direct:info"
-                    steps:
-                    - log: "message"
-            '''
-        then:
-            context.routeDefinitions.size() == 1
-
-            with(context.routeDefinitions[0], RouteDefinition) {
-                input.endpointUri == 'direct:info'
-
-                with (outputs[0], LogDefinition) {
-                    message == 'message'
-                }
-            }
-    }
-
-    def "load from with parameters"() {
-        when:
-            loadRoutes '''
-                - from:
-                    uri: "direct:info"
-                    parameters:
-                      timeout: 1234    
-                    steps:
-                    - log: "message"
-            '''
-        then:
-            context.routeDefinitions.size() == 1
-
-            with(context.routeDefinitions[0], RouteDefinition) {
-                input.endpointUri == 'direct:info?timeout=1234'
-
-                with (outputs[0], LogDefinition) {
-                    message == 'message'
-                }
-            }
-    }
-
-    def "load multi from "() {
-        when:
-            loadRoutes '''
-                - from:
-                    uri: "direct:1"
-                    steps:
-                    - log: "1"
-                - from:
-                    uri: "direct:2"
-                    steps:
-                    - log: "2"
-            '''
-        then:
-            context.routeDefinitions.size() == 2
-
-            with(context.routeDefinitions[0], RouteDefinition) {
-                input.endpointUri == 'direct:1'
-
-                with (outputs[0], LogDefinition) {
-                    message == '1'
-                }
-            }
-            with(context.routeDefinitions[1], RouteDefinition) {
-                input.endpointUri == 'direct:2'
-
-                with (outputs[0], LogDefinition) {
-                    message == '2'
-                }
-            }
-    }
-
-    def "load route"() {
-        when:
-            loadRoutesNoValidate '''
-                - route:
-                    from:
-                      uri: "direct:info"
-                    steps:
-                      - log: "message"
-            '''
-        then:
-            context.routeDefinitions.size() == 1
-
-            with(context.routeDefinitions[0], RouteDefinition) {
-                input.endpointUri == 'direct:info'
-
-                with (outputs[0], LogDefinition) {
-                    message == 'message'
-                }
-            }
-    }
-
-    def "load route with parameters"() {
-        when:
-            loadRoutesNoValidate '''
-                - route:
-                    from:
-                      uri: "direct:info"
-                      parameters:
-                        timeout: 1234
-                    steps:
-                      - log: "message"
-            '''
-        then:
-            context.routeDefinitions.size() == 1
-
-            with(context.routeDefinitions[0], RouteDefinition) {
-                input.endpointUri == 'direct:info?timeout=1234'
-
-                with (outputs[0], LogDefinition) {
-                    message == 'message'
-                }
-            }
-    }
-
-    def "load route inlined"() {
-        when:
-            loadRoutesNoValidate '''
-                - route:
-                    id: demo-route
-                    stream-caching: true
-                    auto-startup: false
-                    from:
-                      uri: "direct:info"
-                    steps:
-                      - log: "message"
-            '''
-        then:
-        context.routeDefinitions.size() == 1
-
-        with(context.routeDefinitions[0], RouteDefinition) {
-            routeId == 'demo-route'
-            streamCache == 'true'
-            autoStartup == 'false'
-            input.endpointUri == 'direct:info'
-
-            with (outputs[0], LogDefinition) {
-                message == 'message'
-            }
-        }
-    }
-
-    def "load route description"() {
-        when:
-            loadRoutesNoValidate '''
-                - route:
-                    id: demo-route
-                    description: something cool
-                    from:
-                      uri: "direct:info"
-                    steps:
-                      - log: "message"
-            '''
-        then:
-        context.routeDefinitions.size() == 1
-
-        with(context.routeDefinitions[0], RouteDefinition) {
-            routeId == 'demo-route'
-            description.text == 'something cool'
-            input.endpointUri == 'direct:info'
-
-            with (outputs[0], LogDefinition) {
-                message == 'message'
-            }
-        }
-    }
-
-    def "load route description with precondition"() {
-        when:
-            loadRoutesNoValidate '''
-                - route:
-                    id: demo-route
-                    description: something cool
-                    precondition: "{{?red}}"
-                    from:
-                      uri: "direct:info"
-                    steps:
-                      - log: "message"
-            '''
-        then:
-        context.routeDefinitions.size() == 1
-
-        with(context.routeDefinitions[0], RouteDefinition) {
-            routeId == 'demo-route'
-            description.text == 'something cool'
-            input.endpointUri == 'direct:info'
-            precondition == '{{?red}}'
-
-            with (outputs[0], LogDefinition) {
-                message == 'message'
-            }
-        }
-    }
-}

Reply via email to