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 98e46b0e848c CAMEL-22626: camel-console - Include all source lines for
a given EIP in the dev consoles
98e46b0e848c is described below
commit 98e46b0e848cd51cda8df49597d04e5b7e80f52d
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Oct 30 08:23:24 2025 +0100
CAMEL-22626: camel-console - Include all source lines for a given EIP in
the dev consoles
---
.../apache/camel/impl/console/ConsoleHelper.java | 17 ++++--
.../camel/impl/console/ProcessorDevConsole.java | 42 ++++++++++---
.../apache/camel/impl/console/RouteDevConsole.java | 70 +---------------------
3 files changed, 47 insertions(+), 82 deletions(-)
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
index 1553ee12241b..2fc2988cca2b 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
@@ -84,10 +84,19 @@ public final class ConsoleHelper {
}
public static String loadSourceLine(CamelContext camelContext, String
location, Integer lineNumber) {
- if (location == null || lineNumber == null) {
+ List<String> lines = loadSourceLines(camelContext, location,
lineNumber, lineNumber + 1);
+ if (lines.size() == 1) {
+ return lines.get(0);
+ }
+ return null;
+ }
+
+ public static List<String> loadSourceLines(CamelContext camelContext,
String location, Integer start, Integer end) {
+ if (location == null || start == null) {
return null;
}
+ List<String> answer = new ArrayList<>();
try {
location = LoggerHelper.stripSourceLocationLineNumber(location);
Resource resource =
PluginHelper.getResourceLoader(camelContext).resolveResource(location);
@@ -99,8 +108,8 @@ public final class ConsoleHelper {
t = reader.readLine();
if (t != null) {
i++;
- if (i == lineNumber) {
- return t;
+ if (i >= start && (end == null || i < end)) {
+ answer.add(t);
}
}
} while (t != null);
@@ -110,7 +119,7 @@ public final class ConsoleHelper {
// ignore
}
- return null;
+ return answer;
}
public static Integer extractSourceLocationLineNumber(String location) {
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDevConsole.java
index 5b33d024bc7f..4a1a9e58b138 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDevConsole.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDevConsole.java
@@ -211,7 +211,13 @@ public class ProcessorDevConsole extends
AbstractDevConsole {
// sort processors by index
mps.sort(Comparator.comparingInt(ManagedProcessorMBean::getIndex));
- for (ManagedProcessorMBean mp : mps) {
+ // include processors into the array
+ includeProcessors(getCamelContext(), arr, max, mps);
+ }
+
+ public static void includeProcessors(CamelContext camelContext, JsonArray
arr, int max, List<ManagedProcessorMBean> mps) {
+ for (int i = 0; i < mps.size(); i++) {
+ ManagedProcessorMBean mp = mps.get(i);
if (arr.size() > max) {
return;
}
@@ -238,17 +244,35 @@ public class ProcessorDevConsole extends
AbstractDevConsole {
}
jo.put("state", mp.getState());
jo.put("disabled", mp.getDisabled());
- String line = ConsoleHelper.loadSourceLine(getCamelContext(),
mp.getSourceLocation(), mp.getSourceLineNumber());
- if (line != null) {
- JsonArray ca = new JsonArray();
- jo.put("code", ca);
- JsonObject c = new JsonObject();
- if (mp.getSourceLineNumber() != null) {
- c.put("line", mp.getSourceLineNumber());
+
+ // calculate end line number
+ ManagedProcessorMBean mp2 = i < mps.size() - 1 ? mps.get(i + 1) :
null;
+ Integer end = mp2 != null ? mp2.getSourceLineNumber() : null;
+ if (mp.getSourceLineNumber() != null) {
+ if (end == null) {
+ end = mp.getSourceLineNumber() + 5;
+ } else {
+ // clip so we do not read ahead to far, as we just want a
snippet of the source code
+ end = Math.min(mp.getSourceLineNumber() + 5, end);
}
+ }
+
+ JsonArray ca = new JsonArray();
+ List<String> lines
+ = ConsoleHelper.loadSourceLines(camelContext,
mp.getSourceLocation(), mp.getSourceLineNumber(), end);
+ int pos = mp.getSourceLineNumber();
+ for (String line : lines) {
+ JsonObject c = new JsonObject();
+ c.put("line", pos);
c.put("code", Jsoner.escape(line));
- c.put("match", true);
+ if (pos == mp.getSourceLineNumber()) {
+ c.put("match", true);
+ }
ca.add(c);
+ pos++;
+ }
+ if (!ca.isEmpty()) {
+ jo.put("code", ca);
}
jo.put("processor", mp.getProcessorName());
jo.put("level", mp.getLevel());
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
index cca060dfafd7..8c5d48289320 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java
@@ -41,7 +41,6 @@ import org.apache.camel.util.StringHelper;
import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
-import org.apache.camel.util.json.Jsoner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -371,74 +370,7 @@ public class RouteDevConsole extends AbstractDevConsole {
.sorted(Comparator.comparingInt(ManagedProcessorMBean::getIndex))
.toList();
- for (ManagedProcessorMBean mp : mps) {
- JsonObject jo = new JsonObject();
- arr.add(jo);
-
- jo.put("id", mp.getProcessorId());
- if (mp.getNodePrefixId() != null) {
- jo.put("nodePrefixId", mp.getNodePrefixId());
- }
- if (mp.getDescription() != null) {
- jo.put("description", mp.getDescription());
- }
- if (mp.getNote() != null) {
- jo.put("note", mp.getNote());
- }
- if (mp.getSourceLocation() != null) {
- String loc = mp.getSourceLocation();
- if (mp.getSourceLineNumber() != null) {
- loc += ":" + mp.getSourceLineNumber();
- }
- jo.put("source", loc);
- }
- jo.put("state", mp.getState());
- jo.put("disabled", mp.getDisabled());
- String line = ConsoleHelper.loadSourceLine(getCamelContext(),
mp.getSourceLocation(), mp.getSourceLineNumber());
- if (line != null) {
- JsonArray ca = new JsonArray();
- jo.put("code", ca);
- JsonObject c = new JsonObject();
- if (mp.getSourceLineNumber() != null) {
- c.put("line", mp.getSourceLineNumber());
- }
- c.put("code", Jsoner.escape(line));
- c.put("match", true);
- ca.add(c);
- }
- jo.put("processor", mp.getProcessorName());
- jo.put("level", mp.getLevel());
- final JsonObject stats = getStatsObject(mp);
- jo.put("statistics", stats);
- }
- }
-
- private static JsonObject getStatsObject(ManagedProcessorMBean mp) {
- JsonObject stats = new JsonObject();
- stats.put("idleSince", mp.getIdleSince());
- stats.put("exchangesTotal", mp.getExchangesTotal());
- stats.put("exchangesFailed", mp.getExchangesFailed());
- stats.put("exchangesInflight", mp.getExchangesInflight());
- stats.put("meanProcessingTime", mp.getMeanProcessingTime());
- stats.put("maxProcessingTime", mp.getMaxProcessingTime());
- stats.put("minProcessingTime", mp.getMinProcessingTime());
- if (mp.getExchangesTotal() > 0) {
- stats.put("lastProcessingTime", mp.getLastProcessingTime());
- stats.put("deltaProcessingTime", mp.getDeltaProcessingTime());
- }
- Date last = mp.getLastExchangeCreatedTimestamp();
- if (last != null) {
- stats.put("lastCreatedExchangeTimestamp", last.getTime());
- }
- last = mp.getLastExchangeCompletedTimestamp();
- if (last != null) {
- stats.put("lastCompletedExchangeTimestamp", last.getTime());
- }
- last = mp.getLastExchangeFailureTimestamp();
- if (last != null) {
- stats.put("lastFailedExchangeTimestamp", last.getTime());
- }
- return stats;
+ ProcessorDevConsole.includeProcessors(getCamelContext(), arr,
Integer.MAX_VALUE, mps);
}
protected void doCall(Map<String, Object> options,
Function<ManagedRouteMBean, Object> task) {