davsclaus commented on code in PR #27516:
URL: https://github.com/apache/camel/pull/27516#discussion_r4212579932


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java:
##########
@@ -414,6 +509,49 @@ private void notify(String msg, boolean error) {
      */
     static final long WATCH_MS = 5 * 60_000;
 
+    // how the latest launch of each name went, for an agent that asks 
(tui_run_example waits for it)
+    private final Map<String, LaunchOutcome> outcomes = new 
ConcurrentHashMap<>();
+
+    /**
+     * How a launch went: started (Camel said so), or failed with the end of 
its output; null while it is starting.
+     */
+    record LaunchOutcome(boolean ok, String log) {
+
+        private static final Pattern ANSI = 
Pattern.compile("\u001B\\[[0-9;]*m");
+
+        static LaunchOutcome started() {
+            return new LaunchOutcome(true, null);
+        }
+
+        static LaunchOutcome failed(Path outputFile) {
+            String tail = null;
+            try {
+                // without colors and stack frames: the messages and their 
causes are what tell why
+                List<String> lines = Files.readAllLines(outputFile, 
StandardCharsets.UTF_8).stream()
+                        .map(l -> ANSI.matcher(l).replaceAll(""))
+                        .filter(l -> !l.stripLeading().startsWith("at ") && 
!l.stripLeading().startsWith("... "))
+                        .toList();
+                tail = String.join("\n", lines.subList(Math.max(0, 
lines.size() - 30), lines.size()));
+            } catch (Exception e) {
+                // no output to show
+            }
+            return new LaunchOutcome(false, tail);
+        }

Review Comment:
   The suggested version collects every line into a list as well, so it holds 
the same in memory. The file is read once, when a start has failed, and it is 
the output of one start. Keeping it as is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to