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

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


The following commit(s) were added to refs/heads/it by this push:
     new 775c62234a36 CAMEL-22758: camel-jbang - Debug inside choice may not 
correlate to source location
775c62234a36 is described below

commit 775c62234a367bf86c9fdbe9a9e5f86d8f68df3e
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Dec 7 11:47:37 2025 +0100

    CAMEL-22758: camel-jbang - Debug inside choice may not correlate to source 
location
---
 .../org/apache/camel/model/ChoiceDefinition.java   | 31 ++++++++++++++++++++++
 .../apache/camel/model/OnFallbackDefinition.java   | 20 ++++++++++++++
 .../apache/camel/model/ProcessorDefinition.java    |  3 +--
 .../camel/model/ProcessorDefinitionHelper.java     | 27 +++++++++++++++++++
 .../camel/dsl/jbang/core/commands/Debug.java       |  5 ++--
 .../core/commands/action/CamelHistoryAction.java   | 20 ++++++++------
 6 files changed, 94 insertions(+), 12 deletions(-)

diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
index e26e5b5227de..5a7ff7d86121 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ChoiceDefinition.java
@@ -27,12 +27,15 @@ import jakarta.xml.bind.annotation.XmlElementRef;
 import jakarta.xml.bind.annotation.XmlRootElement;
 import jakarta.xml.bind.annotation.XmlType;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ExpressionFactory;
+import org.apache.camel.NamedNode;
 import org.apache.camel.Predicate;
 import org.apache.camel.builder.ExpressionClause;
 import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.spi.AsPredicate;
 import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.Resource;
 
 /**
  * Route messages based on a series of predicates
@@ -91,10 +94,12 @@ public class ChoiceDefinition extends 
NoOutputDefinition<ChoiceDefinition> {
         if (otherwise != null) {
             output.setParent(this);
             otherwise.addOutput(output);
+            prepareOutput(output);
         } else if (!whenClauses.isEmpty()) {
             output.setParent(this);
             WhenDefinition last = whenClauses.get(whenClauses.size() - 1);
             last.addOutput(output);
+            prepareOutput(output);
         } else {
             super.addOutput(output);
         }
@@ -103,11 +108,37 @@ public class ChoiceDefinition extends 
NoOutputDefinition<ChoiceDefinition> {
     public void addOutput(WhenDefinition when) {
         when.setParent(this);
         whenClauses.add(when);
+        prepareOutput(when);
     }
 
     public void addOutput(OtherwiseDefinition other) {
         other.setParent(this);
         this.otherwise = other;
+        prepareOutput(other);
+    }
+
+    protected void prepareOutput(NamedNode output) {
+        // grab camel context depends on if this is a regular route or a route 
configuration
+        CamelContext context = this.getCamelContext();
+        if (context == null) {
+            RouteDefinition route = ProcessorDefinitionHelper.getRoute(this);
+            if (route != null) {
+                context = route.getCamelContext();
+            } else {
+                RouteConfigurationDefinition rc = this.getRouteConfiguration();
+                if (rc != null) {
+                    context = rc.getCamelContext();
+                }
+            }
+        }
+
+        if (context != null && (context.isSourceLocationEnabled()
+                || context.isDebugging() || context.isDebugStandby()
+                || context.isTracing() || context.isTracingStandby())) {
+            // we want to capture source location:line for every output (also 
when debugging or tracing enabled/standby)
+            Resource resource = ProcessorDefinitionHelper.getResource(this);
+            ProcessorDefinitionHelper.prepareSourceLocation(resource, output);
+        }
     }
 
     /**
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java
index 5a1c550b866f..a2fef56a0352 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/OnFallbackDefinition.java
@@ -27,7 +27,9 @@ import jakarta.xml.bind.annotation.XmlElementRef;
 import jakarta.xml.bind.annotation.XmlRootElement;
 import jakarta.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.Resource;
 
 /**
  * Route to be executed when Circuit Breaker EIP executes fallback
@@ -125,7 +127,25 @@ public class OnFallbackDefinition extends 
OptionalIdentifiedDefinition<OnFallbac
 
     @Override
     public void addOutput(ProcessorDefinition<?> output) {
+        output.setParent(getParent());
         outputs.add(output);
+
+        // grab camel context depends on if this is a regular route or a route 
configuration
+        CamelContext context = this.getCamelContext();
+        if (context == null) {
+            RouteDefinition route = ProcessorDefinitionHelper.getRoute(this);
+            if (route != null) {
+                context = route.getCamelContext();
+            }
+        }
+
+        if (context != null && (context.isSourceLocationEnabled()
+                || context.isDebugging() || context.isDebugStandby()
+                || context.isTracing() || context.isTracingStandby())) {
+            // we want to capture source location:line for every output (also 
when debugging or tracing enabled/standby)
+            Resource resource = ProcessorDefinitionHelper.getResource(this);
+            ProcessorDefinitionHelper.prepareSourceLocation(resource, output);
+        }
     }
 
 }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index f6a6ad706b16..8cd6f8271c31 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -69,7 +69,6 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.Policy;
 import org.apache.camel.spi.PredicateExceptionFactory;
 import org.apache.camel.spi.Resource;
-import org.apache.camel.spi.ResourceAware;
 import org.apache.camel.support.ExpressionAdapter;
 import org.slf4j.Logger;
 
@@ -227,7 +226,7 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
                 || context.isDebugging() || context.isDebugStandby()
                 || context.isTracing() || context.isTracingStandby())) {
             // we want to capture source location:line for every output (also 
when debugging or tracing enabled/standby)
-            Resource resource = this instanceof ResourceAware ? 
((ResourceAware) this).getResource() : null;
+            Resource resource = ProcessorDefinitionHelper.getResource(this);
             ProcessorDefinitionHelper.prepareSourceLocation(resource, output);
         }
     }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 98d9c3e50a51..74b50756febe 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.apache.camel.CamelContext;
 import org.apache.camel.NamedNode;
 import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.ResourceAware;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.ResourceHelper;
 import org.apache.camel.util.FileUtil;
@@ -524,4 +525,30 @@ public final class ProcessorDefinitionHelper {
         return wrap;
     }
 
+    /**
+     * Gets the resource the given node belongs to.
+     *
+     * @param  node the node
+     * @return      the resource, or <tt>null</tt> if not possible to find
+     */
+    public static Resource getResource(NamedNode node) {
+        if (node == null) {
+            return null;
+        }
+        if (node instanceof ResourceAware ra) {
+            return ra.getResource();
+        }
+
+        NamedNode def = node;
+        while (def != null && def.getParent() != null) {
+            def = def.getParent();
+            if (def instanceof ResourceAware ra) {
+                return ra.getResource();
+            }
+        }
+
+        // not found
+        return null;
+    }
+
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
index 45b3bed57c55..87b5d71c2fee 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
@@ -45,6 +45,7 @@ import org.apache.camel.dsl.jbang.core.common.PathUtils;
 import org.apache.camel.dsl.jbang.core.common.ProcessHelper;
 import org.apache.camel.dsl.jbang.core.common.VersionHelper;
 import org.apache.camel.main.KameletMain;
+import org.apache.camel.support.LoggerHelper;
 import org.apache.camel.support.PatternHelper;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
@@ -1085,8 +1086,8 @@ public class Debug extends Run {
     }
 
     private static String locationAndLine(String loc, int line) {
-        // shorten path as there is no much space
-        loc = FileUtil.stripPath(loc);
+        // shorten path as there is no much space (there are no scheme as add 
fake)
+        loc = LoggerHelper.sourceNameOnly("file:" + FileUtil.stripPath(loc));
         return line == -1 ? loc : loc + ":" + line;
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelHistoryAction.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelHistoryAction.java
index f7eea0727e29..df7e22a85752 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelHistoryAction.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelHistoryAction.java
@@ -38,6 +38,7 @@ import com.github.freva.asciitable.OverflowBehaviour;
 import org.apache.camel.catalog.CamelCatalog;
 import org.apache.camel.catalog.DefaultCamelCatalog;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.support.LoggerHelper;
 import org.apache.camel.tooling.model.ComponentModel;
 import org.apache.camel.tooling.model.EipModel;
 import org.apache.camel.util.FileUtil;
@@ -263,9 +264,7 @@ public class CamelHistoryAction extends ActionWatchCommand {
     }
 
     private String getDataAsTable(Row r) {
-        return tableHelper.getDataAsTable(r.exchangeId, r.exchangePattern, 
null, r.endpoint, r.endpointService,
-                r.message,
-                r.exception);
+        return tableHelper.getDataAsTable(r.exchangeId, r.exchangePattern, 
r.aggregate, r.endpoint, r.endpointService, r.message, r.exception);
     }
 
     private void printSourceAndHistory(Row row) {
@@ -536,8 +535,8 @@ public class CamelHistoryAction extends ActionWatchCommand {
     }
 
     private static String locationAndLine(String loc, int line) {
-        // shorten path as there is no much space
-        loc = FileUtil.stripPath(loc);
+        // shorten path as there is no much space (there are no scheme as add 
fake)
+        loc = LoggerHelper.sourceNameOnly("file:" + FileUtil.stripPath(loc));
         return line == -1 ? loc : loc + ":" + line;
     }
 
@@ -831,9 +830,14 @@ public class CamelHistoryAction extends ActionWatchCommand 
{
                 h.location = r.location;
                 h.elapsed = r.elapsed;
                 h.level = r.nodeLevel;
-                // TODO
-                h.code = "some code here";
-                h.line = 123;
+                if (r.code != null) {
+                    for (var c : r.code) {
+                        if (c.match) {
+                            h.code = c.code;
+                            h.line = c.line;
+                        }
+                    }
+                }
                 cur.history.add(h);
              }
         }

Reply via email to