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 181aae64b85 CAMEL-20078: camel-jbang - Debug command
181aae64b85 is described below

commit 181aae64b850301fe118de3fcade62c2f640ff93
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Nov 4 17:30:50 2023 +0100

    CAMEL-20078: camel-jbang - Debug command
---
 .../apache/camel/impl/engine/DefaultChannel.java   | 79 ++++++++++++++++++----
 .../main/DebuggerConfigurationProperties.java      |  1 -
 .../modules/ROOT/pages/camel-jbang.adoc            | 34 ++++++++++
 3 files changed, 98 insertions(+), 16 deletions(-)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
index 2d4b23985d9..cd593716a05 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
@@ -41,8 +41,10 @@ import org.apache.camel.spi.MessageHistoryFactory;
 import org.apache.camel.spi.Tracer;
 import org.apache.camel.spi.WrapAwareProcessor;
 import org.apache.camel.support.OrderedComparator;
+import org.apache.camel.support.PatternHelper;
 import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.service.ServiceHelper;
+import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -184,21 +186,7 @@ public class DefaultChannel extends CamelInternalProcessor 
implements Channel {
                 if (!camelContext.hasService(debugger)) {
                     camelContext.addService(debugger);
                 }
-                // if starting breakpoint is BREAKPOINT_ALL_ROUTES then 
automatic add first as a breakpoint
-                if (first && debugger.getInitialBreakpoints() != null
-                        && 
debugger.getInitialBreakpoints().contains(BacklogDebugger.BREAKPOINT_ALL_ROUTES))
 {
-                    if (debugger.isSingleStepIncludeStartEnd()) {
-                        // we want route to be breakpoint (use input)
-                        String id = routeDefinition.getInput().getId();
-                        debugger.addBreakpoint(id);
-                        LOG.debug("BacklogDebugger added breakpoint: {}", id);
-                    } else {
-                        // first output should also be breakpoint
-                        String id = targetOutputDef.getId();
-                        debugger.addBreakpoint(id);
-                        LOG.debug("BacklogDebugger added breakpoint: {}", id);
-                    }
-                }
+                backlogDebuggerSetupInitialBreakpoints(definition, 
routeDefinition, first, debugger, targetOutputDef);
                 if (first && debugger.isSingleStepIncludeStartEnd()) {
                     // add breakpoint on route input instead of first node
                     addAdvice(new BacklogDebuggerAdvice(debugger, 
nextProcessor, routeDefinition.getInput()));
@@ -340,6 +328,67 @@ public class DefaultChannel extends CamelInternalProcessor 
implements Channel {
         return debugger;
     }
 
+    private void backlogDebuggerSetupInitialBreakpoints(
+            NamedNode definition, NamedRoute routeDefinition, boolean first,
+            BacklogDebugger debugger, NamedNode targetOutputDef) {
+        // setup initial breakpoints
+        if (debugger.getInitialBreakpoints() != null) {
+            boolean match = false;
+            String id = definition.getId();
+            for (String pattern : debugger.getInitialBreakpoints().split(",")) 
{
+                pattern = pattern.trim();
+                match |= BacklogDebugger.BREAKPOINT_ALL_ROUTES.equals(pattern) 
&& first;
+                if (!match) {
+                    match = PatternHelper.matchPattern(id, pattern);
+                }
+                // eip kind so you can match with (setBody*)
+                if (!match) {
+                    match = 
PatternHelper.matchPattern(definition.getShortName(), pattern);
+                }
+                // location and line number
+                if (!match && pattern.contains(":")) {
+                    // try with line number and location
+                    String pnum = StringHelper.afterLast(pattern, ":");
+                    if (pnum != null) {
+                        String ploc = StringHelper.beforeLast(pattern, ":");
+                        String loc = definition.getLocation();
+                        // strip schema
+                        if (loc != null && loc.contains(":")) {
+                            loc = StringHelper.after(loc, ":");
+                        }
+                        String num = "" + definition.getLineNumber();
+                        if (PatternHelper.matchPattern(loc, ploc) && 
pnum.equals(num)) {
+                            match = true;
+                        }
+                    }
+                }
+                // line number only
+                if (!match) {
+                    Integer pnum = 
camelContext.getTypeConverter().tryConvertTo(Integer.class, pattern);
+                    if (pnum != null) {
+                        int num = definition.getLineNumber();
+                        if (num == pnum) {
+                            match = true;
+                        }
+                    }
+                }
+            }
+            if (match) {
+                if (first && debugger.isSingleStepIncludeStartEnd()) {
+                    // we want route to be breakpoint (use input)
+                    id = routeDefinition.getInput().getId();
+                    debugger.addBreakpoint(id);
+                    LOG.debug("BacklogDebugger added breakpoint: {}", id);
+                } else {
+                    // first output should also be breakpoint
+                    id = targetOutputDef.getId();
+                    debugger.addBreakpoint(id);
+                    LOG.debug("BacklogDebugger added breakpoint: {}", id);
+                }
+            }
+        }
+    }
+
     @Override
     public String toString() {
         // just output the next processor as all the interceptors and error 
handler is just too verbose
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/DebuggerConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/DebuggerConfigurationProperties.java
index c06b602181e..de1113897e8 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/DebuggerConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/DebuggerConfigurationProperties.java
@@ -290,5 +290,4 @@ public class DebuggerConfigurationProperties implements 
BootstrapCloseable {
         return (DebuggerConfigurationProperties) this;
     }
 
-
 }
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index ceb90ad168a..33d49016bcb 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -1941,6 +1941,40 @@ This is _basic_ but yet powerful, as you have this 
debugger always readily avail
 
 TIP: The `camel debug` can debug almost all the DSLs (there is a problem with 
groovy).
 
+===== Configuring breakpoints
+
+When using `camel debug` then breakpoints is by default added to every route. 
However, you can specify which breakpoints to use instead with the 
`--breakpoint` option.
+This parameter is able to match the Camel routes using a pattern style:
+
+1. Exact match by node ids
+2. Match node ids by pattern (wildcard and regular expression)
+3. Match by EIP kind (setHeader, setBody, choice, split, etc.)
+4. Match by source and line number
+5. Match by line number
+
+Multiple breakpoints can be separated by comma.
+
+For example to set a breakpoint at the setHeader EIP you do:
+
+[source,bash]
+----
+camel debug hello.yaml --breakpoint=setHeader
+----
+
+To set a breakpoint at line 18:
+
+[source,bash]
+----
+camel debug hello.yaml --breakpoint=18
+----
+
+To set a breakpoint at line 18 and 34
+
+[source,bash]
+----
+camel debug hello.yaml --breakpoint=18,34
+----
+
 
 ==== Camel route debugging using VSCode or IDEA editors
 

Reply via email to