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

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


The following commit(s) were added to refs/heads/dum by this push:
     new 326b6c7c9f46 CAMEL-23402: Route structure dump to walk model for 
structure to be accurate
326b6c7c9f46 is described below

commit 326b6c7c9f461da9e1fe6f314680c9fd2db50e79
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun May 3 13:07:35 2026 +0200

    CAMEL-23402: Route structure dump to walk model for structure to be accurate
---
 .../java/org/apache/camel/spi/ModelDumpLine.java   | 14 +++++------
 .../impl/console/RouteStructureDevConsole.java     |  6 +++++
 .../camel/impl/DefaultModelToStructureDumper.java  | 27 ++++++++--------------
 .../management/DumpRouteStructureChoiceTest.java   |  4 ++--
 .../camel/management/DumpRouteStructureTest.java   | 15 ++++++++----
 .../camel-jbang-cmd-route-structure.adoc           |  1 +
 .../META-INF/camel-jbang-commands-metadata.json    |  2 +-
 .../commands/action/CamelRouteStructureAction.java |  9 ++++++++
 8 files changed, 46 insertions(+), 32 deletions(-)

diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java 
b/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
index c0758fcdde5b..81470a3f5a4c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
@@ -19,13 +19,13 @@ package org.apache.camel.spi;
 /**
  * Represents a line in a model dumper of the route structure (not with full 
details such as XML or YAML dump).
  *
- * @param location line source location:line (if present)
- * @param type     the kind of EIP node
- * @param id       the id of the EIP node
- * @param level    indent level of the EIP node
- * @param code     EIP code such as label or short name that is human-readable 
or pseudocode
+ * @param location    line source scheme:location:line (if present)
+ * @param type        the kind of EIP node
+ * @param id          the id of the EIP node
+ * @param level       indent level of the EIP node
+ * @param code        EIP code such as label or short name that is 
human-readable or pseudocode
+ * @param description optional description of the EIP node
  */
-public record ModelDumpLine(String location, String type, String id, int 
level, String code) {
+public record ModelDumpLine(String location, String type, String id, int 
level, String code, String description) {
 
-    // TODO: description
 }
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
index f25b0368980b..3512b33f2a21 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
@@ -114,6 +114,9 @@ public class RouteStructureDevConsole extends 
AbstractDevConsole {
             if (mrb.getSourceLocation() != null) {
                 jo.put("source", mrb.getSourceLocation());
             }
+            if (mrb.getDescription() != null) {
+                jo.put("description", mrb.getDescription());
+            }
 
             try {
                 ModelToStructureDumper dumper = 
PluginHelper.getModelToStructureDumper(getCamelContext());
@@ -184,6 +187,9 @@ public class RouteStructureDevConsole extends 
AbstractDevConsole {
             c.put("type", line.type());
             c.put("id", line.id());
             c.put("level", line.level());
+            if (line.description() != null) {
+                c.put("description", line.description());
+            }
             c.put("code", Jsoner.escape(line.code()));
             code.add(c);
         }
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModelToStructureDumper.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModelToStructureDumper.java
index f868b216d8dd..9b0466ed010b 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModelToStructureDumper.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModelToStructureDumper.java
@@ -21,7 +21,6 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.NamedNode;
-import org.apache.camel.Route;
 import org.apache.camel.model.Model;
 import org.apache.camel.model.OptionalIdentifiedDefinition;
 import org.apache.camel.model.ProcessorDefinitionHelper;
@@ -37,31 +36,24 @@ public class DefaultModelToStructureDumper implements 
ModelToStructureDumper {
 
     @Override
     public List<ModelDumpLine> dumpStructure(CamelContext context, String 
routeId, boolean brief) throws Exception {
+        // dump in text format padded by level
         List<ModelDumpLine> answer = new ArrayList<>();
 
         // lookup model and runtime route
         final Model model = 
context.getCamelContextExtension().getContextPlugin(Model.class);
         final RouteDefinition def = model.getRouteDefinition(routeId);
-        final Route route = context.getRoute(routeId);
-        // dump in text format padded by level
         String scheme = def.getResource() != null ? 
def.getResource().getScheme() : "file";
 
-        String loc
-                = scheme + ":" + (route != null ? 
route.getSourceLocationShort() : LoggerHelper.getLineNumberLoggerName(def));
-        answer.add(new ModelDumpLine(loc, "route", def.getRouteId(), 0, 
"route[" + def.getRouteId() + "]"));
-        String uri;
-        if (route != null) {
-            uri = brief ? route.getEndpoint().getEndpointBaseUri() : 
route.getEndpoint().getEndpointUri();
-        } else {
-            uri = def.getInput().getEndpointUri();
-            if (brief) {
-                uri = StringHelper.before(uri, "?", uri);
-            }
+        String loc = scheme + ":" + LoggerHelper.getLineNumberLoggerName(def);
+        answer.add(
+                new ModelDumpLine(loc, "route", def.getRouteId(), 0, "route[" 
+ def.getRouteId() + "]", def.getDescription()));
+        String uri = def.getInput().getLabel();
+        if (brief) {
+            uri = StringHelper.before(uri, "?", uri);
         }
-        answer.add(new ModelDumpLine(loc, "from", routeId, 1, "from[" + uri + 
"]"));
+        answer.add(new ModelDumpLine(loc, "from", routeId, 1, "from[" + uri + 
"]", def.getDescription()));
 
         var outputs = 
ProcessorDefinitionHelper.filterTypeInOutputs(def.getOutputs(), 
OptionalIdentifiedDefinition.class);
-
         for (var output : outputs) {
             loc = scheme + ":" + output.getLocation();
             if (output.getLineNumber() > 0) {
@@ -72,7 +64,8 @@ public class DefaultModelToStructureDumper implements 
ModelToStructureDumper {
             int level = getLevel(output) + 1;
             boolean choice = "choice".equals(output.getShortName());
             String code = choice || brief ? output.getShortName() : 
output.getLabel();
-            answer.add(new ModelDumpLine(loc, kind, id, level, code));
+            String desc = output.getDescription();
+            answer.add(new ModelDumpLine(loc, kind, id, level, code, desc));
         }
 
         return answer;
diff --git 
a/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureChoiceTest.java
 
b/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureChoiceTest.java
index f5bcd4eb6da1..be0a3d83beb6 100644
--- 
a/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureChoiceTest.java
+++ 
b/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureChoiceTest.java
@@ -63,7 +63,7 @@ public class DumpRouteStructureChoiceTest extends 
ManagementTestSupport {
         assertEquals(1, lines.get(1).level());
         assertEquals("from", lines.get(1).type());
         assertEquals("myChoiceRoute", lines.get(1).id());
-        assertEquals("from[direct://start]", lines.get(1).code());
+        assertEquals("from[direct:start]", lines.get(1).code());
         assertEquals(2, lines.get(2).level());
         assertEquals("choice", lines.get(2).type());
         assertEquals("choice1", lines.get(2).id());
@@ -115,7 +115,7 @@ public class DumpRouteStructureChoiceTest extends 
ManagementTestSupport {
         assertEquals(1, lines.get(1).level());
         assertEquals("from", lines.get(1).type());
         assertEquals("myChoiceRoute", lines.get(1).id());
-        assertEquals("from[direct://start]", lines.get(1).code());
+        assertEquals("from[direct:start]", lines.get(1).code());
         assertEquals(2, lines.get(2).level());
         assertEquals("choice", lines.get(2).type());
         assertEquals("choice1", lines.get(2).id());
diff --git 
a/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureTest.java
 
b/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureTest.java
index 2ae2a65d771e..22786d016619 100644
--- 
a/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureTest.java
+++ 
b/core/camel-management/src/test/java/org/apache/camel/management/DumpRouteStructureTest.java
@@ -52,18 +52,22 @@ public class DumpRouteStructureTest extends 
ManagementTestSupport {
         assertEquals("route", lines.get(0).type());
         assertEquals("myOtherRoute", lines.get(0).id());
         assertEquals("route[myOtherRoute]", lines.get(0).code());
+        assertEquals("my cool route", lines.get(0).description());
         assertEquals(1, lines.get(1).level());
         assertEquals("from", lines.get(1).type());
         assertEquals("myOtherRoute", lines.get(1).id());
-        assertEquals("from[seda://bar?multipleConsumers=true&size=1234]", 
lines.get(1).code());
+        assertEquals("from[seda:bar?size=1234&multipleConsumers=true]", 
lines.get(1).code());
+        assertEquals("my cool route", lines.get(1).description());
         assertEquals(2, lines.get(2).level());
         assertEquals("filter", lines.get(2).type());
         assertEquals("myfilter", lines.get(2).id());
         assertEquals("filter[header{bar}]", lines.get(2).code());
+        assertEquals("my special filter", lines.get(2).description());
         assertEquals(3, lines.get(3).level());
         assertEquals("to", lines.get(3).type());
         assertEquals("mybar", lines.get(3).id());
         assertEquals("to[mock:bar]", lines.get(3).code());
+        assertEquals("my great bar", lines.get(3).description());
         assertEquals(2, lines.get(4).level());
         assertEquals("to", lines.get(4).type());
         assertEquals("myend", lines.get(4).id());
@@ -84,7 +88,7 @@ public class DumpRouteStructureTest extends 
ManagementTestSupport {
         assertEquals(1, lines.get(1).level());
         assertEquals("from", lines.get(1).type());
         assertEquals("myOtherRoute", lines.get(1).id());
-        assertEquals("from[seda://bar]", lines.get(1).code());
+        assertEquals("from[seda:bar]", lines.get(1).code());
         assertEquals(2, lines.get(2).level());
         assertEquals("filter", lines.get(2).type());
         assertEquals("myfilter", lines.get(2).id());
@@ -93,6 +97,7 @@ public class DumpRouteStructureTest extends 
ManagementTestSupport {
         assertEquals("to", lines.get(3).type());
         assertEquals("mybar", lines.get(3).id());
         assertEquals("to", lines.get(3).code());
+        assertEquals("my great bar", lines.get(3).description());
         assertEquals(2, lines.get(4).level());
         assertEquals("to", lines.get(4).type());
         assertEquals("myend", lines.get(4).id());
@@ -105,9 +110,9 @@ public class DumpRouteStructureTest extends 
ManagementTestSupport {
             public void configure() {
                 context.setDebugging(true);
 
-                
from("seda:bar?size=1234&multipleConsumers=true").routeId("myOtherRoute")
-                        .filter().header("bar").id("myfilter")
-                        .to("mock:bar").id("mybar")
+                
from("seda:bar?size=1234&multipleConsumers=true").routeId("myOtherRoute").routeDescription("my
 cool route")
+                        .filter().header("bar").id("myfilter").description("my 
special filter")
+                        .to("mock:bar").id("mybar").description("my great bar")
                         .end()
                         .to("log:end").id("myend");
             }
diff --git 
a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-cmd-route-structure.adoc
 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-cmd-route-structure.adoc
index df29ba23c0ca..8ce1fdceb2b5 100644
--- 
a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-cmd-route-structure.adoc
+++ 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-cmd-route-structure.adoc
@@ -20,6 +20,7 @@ camel cmd route-structure [options]
 |===
 | Option | Description | Default | Type
 | `--brief` | To show less detailed route structure |  | boolean
+| `--description` | To show description instead of code |  | boolean
 | `--filter` | Filter route by filename or route id (multiple names can be 
separated by comma) |  | String
 | `--ignore-loading-error` | Whether to ignore route loading and compilation 
errors (use this with care!) | false | boolean
 | `--json` | Output in JSON Format |  | boolean
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
index f8ee79c83aa9..377232871720 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
@@ -2,7 +2,7 @@
   "commands": [
     { "name": "bind", "fullName": "bind", "description": "DEPRECATED: Bind 
source and sink Kamelets as a new Camel integration", "deprecated": true, 
"sourceClass": "org.apache.camel.dsl.jbang.core.commands.bind.Bind", "options": 
[ { "names": "--error-handler", "description": "Add error handler 
(none|log|sink:<endpoint>). Sink endpoints are expected in the format 
[[apigroup\/]version:]kind:[namespace\/]name, plain Camel URIs or Kamelet 
name.", "javaType": "java.lang.String", "type": "stri [...]
     { "name": "catalog", "fullName": "catalog", "description": "List artifacts 
from Camel Catalog", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.catalog.CatalogCommand", "options": [ 
{ "names": "-h,--help", "description": "Display the help and sub-commands", 
"javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": 
"component", "fullName": "catalog component", "description": "List components 
from the Camel Catalog", "sourceClass": "org.apache.camel.dsl.jbang.co [...]
-    { "name": "cmd", "fullName": "cmd", "description": "Performs commands in 
the running Camel integrations, such as start\/stop route, or change logging 
levels.", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.action.CamelAction", "options": [ { 
"names": "-h,--help", "description": "Display the help and sub-commands", 
"javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": 
"browse", "fullName": "cmd browse", "description": "Browse pending messages on 
endpoints [...]
+    { "name": "cmd", "fullName": "cmd", "description": "Performs commands in 
the running Camel integrations, such as start\/stop route, or change logging 
levels.", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.action.CamelAction", "options": [ { 
"names": "-h,--help", "description": "Display the help and sub-commands", 
"javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": 
"browse", "fullName": "cmd browse", "description": "Browse pending messages on 
endpoints [...]
     { "name": "completion", "fullName": "completion", "description": "Generate 
completion script for bash\/zsh", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.Complete", "options": [ { "names": 
"-h,--help", "description": "Display the help and sub-commands", "javaType": 
"boolean", "type": "boolean" } ] },
     { "name": "config", "fullName": "config", "description": "Get and set user 
configuration values", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.config.ConfigCommand", "options": [ { 
"names": "-h,--help", "description": "Display the help and sub-commands", 
"javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "get", 
"fullName": "config get", "description": "Display user configuration value", 
"sourceClass": "org.apache.camel.dsl.jbang.core.commands.config. [...]
     { "name": "debug", "fullName": "debug", "description": "Debug local Camel 
integration", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Debug", 
"options": [ { "names": "--ago", "description": "Use ago instead of yyyy-MM-dd 
HH:mm:ss in timestamp.", "javaType": "boolean", "type": "boolean" }, { "names": 
"--background", "description": "Run in the background", "defaultValue": 
"false", "javaType": "boolean", "type": "boolean" }, { "names": 
"--background-wait", "description": "To  [...]
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelRouteStructureAction.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelRouteStructureAction.java
index 64ffb17a02af..44f3c5f63338 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelRouteStructureAction.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelRouteStructureAction.java
@@ -68,6 +68,10 @@ public class CamelRouteStructureAction extends 
ActionBaseCommand {
                         description = "To show less detailed route structure")
     boolean brief;
 
+    @CommandLine.Option(names = { "--description" },
+            description = "To show description instead of code")
+    boolean description;
+
     @CommandLine.Option(names = { "--filter" },
                         description = "Filter route by filename or route id 
(multiple names can be separated by comma)")
     String filter;
@@ -139,9 +143,13 @@ public class CamelRouteStructureAction extends 
ActionBaseCommand {
                                 code.id = line.getString("id");
                                 code.level = line.getInteger("level");
                                 code.code = line.getString("code");
+                                code.description = 
line.getString("description");
                                 if (brief) {
                                     // make code brief
                                     code.code = StringHelper.before(code.code, 
"[", code.code);
+                                } else if (description) {
+                                    // show description
+                                    code.code = code.type + (code.description 
!= null ? "[" + code.description + "]" : "");
                                 }
                                 row.code.add(code);
                             }
@@ -324,6 +332,7 @@ public class CamelRouteStructureAction extends 
ActionBaseCommand {
         String id;
         int level;
         String code;
+        String description;
     }
 
 }

Reply via email to