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

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

commit c610fe9746fe6c02cf88d798452da5ea541f9fb6
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Feb 28 13:25:02 2024 +0100

    CAMEL-20466: camel-core - Rest DSL to be inlined by default to avoid 
clutter up list of routes
---
 .../java/org/apache/camel/impl/console/SourceDevConsole.java     | 2 ++
 .../src/main/java/org/apache/camel/impl/DefaultModel.java        | 4 ++++
 .../org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java   | 9 +++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/SourceDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/SourceDevConsole.java
index c848030b181..ba7faf6e3d5 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/SourceDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/SourceDevConsole.java
@@ -89,7 +89,9 @@ public class SourceDevConsole extends AbstractDevConsole {
                     sb.append(String.format("\n    Source: %s", 
mrb.getSourceLocation()));
                 }
                 if (!code.isEmpty()) {
+                    sb.append("\n");
                     sb.append(code);
+                    sb.append("\n\n");
                 }
             }
             sb.append("\n");
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index 77cc5c6d5f0..f0a2fc60f02 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -225,6 +225,10 @@ public class DefaultModel implements Model {
                             RouteDefinition toBeInlined = directs.get(toUri);
                             if (toBeInlined != null) {
                                 toBeRemoved.add(toBeInlined);
+                                // inline the source loc:line as starting from 
this direct input
+                                FromDefinition inlinedFrom = 
toBeInlined.getInput();
+                                from.setLocation(inlinedFrom.getLocation());
+                                
from.setLineNumber(inlinedFrom.getLineNumber());
                                 // inline by replacing the outputs
                                 r.getOutputs().clear();
                                 
r.getOutputs().addAll(toBeInlined.getOutputs());
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
index 9135519540e..a1f0dae738d 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerBase.java
@@ -18,6 +18,7 @@ package org.apache.camel.dsl.yaml.common;
 
 import java.util.Locale;
 
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.LineNumberAware;
 import org.apache.camel.dsl.yaml.common.exception.UnsupportedFieldException;
 import org.apache.camel.dsl.yaml.common.exception.UnsupportedNodeTypeException;
@@ -134,19 +135,23 @@ public abstract class YamlDeserializerBase<T> extends 
YamlDeserializerSupport im
     }
 
     protected void onNewTarget(Node node, T target, int line) {
+        YamlDeserializationContext ctx = getDeserializationContext(node);
+        if (ctx != null && target instanceof CamelContextAware) {
+            CamelContextAware.trySetCamelContext(target, 
ctx.getCamelContext());
+        }
+
         // enrich model with source location:line number
         if (target instanceof LineNumberAware && line != -1) {
             LineNumberAware lna = (LineNumberAware) target;
             lna.setLineNumber(line);
 
-            YamlDeserializationContext ctx = getDeserializationContext(node);
+            ctx = getDeserializationContext(node);
             if (ctx != null) {
                 lna.setLocation(ctx.getResource().getLocation());
             }
         }
         if (target instanceof ResourceAware) {
             ResourceAware ra = (ResourceAware) target;
-            YamlDeserializationContext ctx = getDeserializationContext(node);
             if (ctx != null) {
                 ra.setResource(ctx.getResource());
             }

Reply via email to