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

cdeppisch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f321e768a994573db3ee3fac5b99b387c67afdae
Author: Christoph Deppisch <cdeppi...@redhat.com>
AuthorDate: Wed Jul 17 10:36:39 2024 +0200

    chore(camel-yaml-dsl): Support new trait configurations
    
    - Generic configuration node is deprecated in traits (e.g. 
traits/environment/configuration, traits/camel/configuration)
    - Also support new trait configuration layout (e.g. 
traits/environment/vars, traits/camel/properties)
---
 .../camel/dsl/yaml/YamlRoutesBuilderLoader.java    | 26 +++++++++++++++++-----
 .../camel/dsl/yaml/IntegrationLoaderTest.groovy    | 19 +++++++---------
 .../KameletBindingLoaderIntegrationSpecTest.groovy |  6 ++---
 .../dsl/yaml/PipeLoaderIntegrationSpecTest.groovy  |  6 ++---
 4 files changed, 32 insertions(+), 25 deletions(-)

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 e31b5f35a10..9bae448eada 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
@@ -422,7 +422,7 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         // if there are trait configuration then include them early
         configuration = nodeAt(root, "/traits/camel");
         if (configuration != null) {
-            var list = preConfigureTraitConfiguration(ctx.getResource(), 
configuration);
+            var list = preConfigureTraitCamel(ctx.getResource(), 
configuration);
             answer.addAll(list);
         }
         // if there are trait environment then include them early
@@ -513,10 +513,17 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
         return answer;
     }
 
-    private List<CamelContextCustomizer> 
preConfigureTraitConfiguration(Resource resource, Node node) {
+    private List<CamelContextCustomizer> preConfigureTraitCamel(Resource 
resource, Node node) {
         List<CamelContextCustomizer> answer = new ArrayList<>();
 
-        Node target = nodeAt(node, "configuration/properties/");
+        Node target;
+        if (nodeAt(node, "/configuration") != null) {
+            // legacy trait configuration parameters
+            target = nodeAt(node, "/configuration/properties");
+        } else {
+            target = nodeAt(node, "/properties");
+        }
+
         final List<String> lines = asStringList(target);
         if (lines == null || lines.isEmpty()) {
             return answer;
@@ -538,7 +545,7 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
                     }
                     lines.forEach(ps::parseConfigurationValue);
                 } catch (Exception e) {
-                    throw new RuntimeCamelException("Error adding properties 
from spec/traits/camel/configuration", e);
+                    throw new RuntimeCamelException("Error adding properties 
from spec/traits/camel", e);
                 }
             }
         });
@@ -549,7 +556,14 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
     private List<CamelContextCustomizer> preConfigureTraitEnvironment(Resource 
resource, Node node) {
         List<CamelContextCustomizer> answer = new ArrayList<>();
 
-        Node target = nodeAt(node, "configuration/vars/");
+        Node target;
+        if (nodeAt(node, "/configuration") != null) {
+            // legacy trait configuration parameters
+            target = nodeAt(node, "/configuration/vars");
+        } else {
+            target = nodeAt(node, "/vars");
+        }
+
         final List<String> lines = asStringList(target);
         if (lines == null || lines.isEmpty()) {
             return answer;
@@ -571,7 +585,7 @@ public class YamlRoutesBuilderLoader extends 
YamlRoutesBuilderLoaderSupport {
                     }
                     lines.forEach(ps::parseConfigurationValue);
                 } catch (Exception e) {
-                    throw new RuntimeCamelException("Error adding properties 
from spec/traits/environment/configuration", e);
+                    throw new RuntimeCamelException("Error adding properties 
from spec/traits/environment", e);
                 }
             }
         });
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 ff4ef00521f..d6560894a2f 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
@@ -64,10 +64,9 @@ class IntegrationLoaderTest extends YamlTestSupport {
                 spec:
                   traits:
                     camel:
-                      configuration:
-                        properties:
-                          - camel.component.seda.queueSize = 456
-                          - camel.component.seda.default-block-when-full = true
+                      properties:
+                        - camel.component.seda.queueSize = 456
+                        - camel.component.seda.default-block-when-full = true
                   flows:
                     - from:
                         uri: "seda:foo"
@@ -96,14 +95,12 @@ class IntegrationLoaderTest extends YamlTestSupport {
                 spec:
                   traits:
                     camel:
-                      configuration:
-                        properties:
-                          - camel.component.seda.queueSize = 456
-                          - camel.component.seda.default-block-when-full = true
+                      properties:
+                        - camel.component.seda.queueSize = 456
+                        - camel.component.seda.default-block-when-full = true
                     environment:
-                      configuration:
-                        vars:
-                          - TEST_MESSAGE = Hello World    
+                      vars:
+                        - TEST_MESSAGE = Hello World    
                   flows:
                     - from:
                         uri: "seda:foo"
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
index 886060e24ad..9675683884b 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
@@ -48,13 +48,11 @@ class KameletBindingLoaderIntegrationSpecTest extends 
YamlTestSupport {
                     - "camel:cloudevents"
                     traits:
                       camel:
-                        configuration:
-                          properties:
+                        properties:
                           - "foo=howdy"
                           - "bar=123"
                       environment:
-                        configuration:
-                          vars:
+                        vars:
                           - "MY_ENV=cheese"   
                   source:
                     ref:
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
index 327f43cfbb3..8b0110f0767 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
@@ -48,13 +48,11 @@ class PipeLoaderIntegrationSpecTest extends YamlTestSupport 
{
                     - "camel:cloudevents"
                     traits:
                       camel:
-                        configuration:
-                          properties:
+                        properties:
                           - "foo=howdy"
                           - "bar=123"
                       environment:
-                        configuration:
-                          vars:
+                        vars:
                           - "MY_ENV=cheese"   
                   source:
                     ref:

Reply via email to