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 6a73ce47493f camel-jbang (tui) - Clean up temp .camel-tui-pom.xml on
process stop
6a73ce47493f is described below
commit 6a73ce47493f6f89f158aac6a4a960a56c8949cd
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Aug 12 20:05:13 2026 +0200
camel-jbang (tui) - Clean up temp .camel-tui-pom.xml on process stop
The temp pom created for CLI connector injection was only cleaned via
deleteOnExit which misses abrupt stops. Now the temp pom is tracked and
deleted when the process exits or is stopped via F10.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../dsl/jbang/core/commands/tui/CamelMonitor.java | 1 +
.../dsl/jbang/core/commands/tui/LaunchManager.java | 53 ++++++++++++++++++----
2 files changed, 46 insertions(+), 8 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
index 5cde61da6931..2aa880d1208b 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
@@ -1862,6 +1862,7 @@ public class CamelMonitor extends CamelCommand {
}
} else {
String pidStr = ctx.selectedPid;
+ actionsPopup.getLaunchManager().cleanupTempPom(pid);
ProcessHandle.of(pid).ifPresent(ph -> {
if (forceKill) {
ph.destroyForcibly();
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
index 8b196dd055b0..cd3c0e1315fe 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java
@@ -21,8 +21,10 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
@@ -39,6 +41,7 @@ class LaunchManager {
private final Supplier<List<InfraInfo>> infraServices;
private final List<PendingLaunch> pendingLaunches = new ArrayList<>();
+ private final Map<Long, Path> activeTempPoms = new HashMap<>();
private DeferredLaunch deferredLaunch;
private volatile String pendingAutoSelect;
private BiConsumer<String, Boolean> notificationCallback;
@@ -204,8 +207,9 @@ class LaunchManager {
// Translate Camel JBang args to Maven-compatible args
cmd.addAll(translateArgsForMaven(extraArgs, projectType));
// Inject camel-cli-connector if not already in the project
+ Path tempPom = null;
if ("spring-boot".equals(projectType)) {
- injectCliConnectorIfMissing(dir, cmd);
+ tempPom = injectCliConnectorIfMissing(dir, cmd);
}
Path outputFile = createSecureTempFile("camel-maven-", ".log");
outputFile.toFile().deleteOnExit();
@@ -214,22 +218,25 @@ class LaunchManager {
pb.redirectErrorStream(true);
pb.redirectOutput(outputFile.toFile());
Process process = pb.start();
- addPendingLaunch(displayName, process, outputFile);
+ pendingLaunches.add(new PendingLaunch(displayName, process,
outputFile, System.currentTimeMillis(), tempPom));
+ if (pendingAutoSelect == null) {
+ pendingAutoSelect = displayName;
+ }
notify("Starting: " + displayName + " (mvn " + cmd.get(1) + ")",
false);
} catch (Exception e) {
notify("Failed to start Maven project: " + e.getMessage(), true);
}
}
- private void injectCliConnectorIfMissing(String dir, List<String> cmd) {
+ private Path injectCliConnectorIfMissing(String dir, List<String> cmd) {
try {
Path pomFile = Path.of(dir, "pom.xml");
if (!Files.isRegularFile(pomFile)) {
- return;
+ return null;
}
String pomContent = Files.readString(pomFile);
if (pomContent.contains("camel-cli-connector")) {
- return;
+ return null;
}
// Add cli-connector-starter dependency (version managed by BOM)
String dep = "\n <dependency>\n"
@@ -239,17 +246,18 @@ class LaunchManager {
// Find the project-level </dependencies> (not inside
dependencyManagement or plugins)
int insertIdx = findProjectDependenciesEnd(pomContent);
if (insertIdx < 0) {
- return;
+ return null;
}
String modified = pomContent.substring(0, insertIdx) + dep + "\n
" + pomContent.substring(insertIdx);
// Write temp pom in the project dir so Maven can find sources
Path tempPom = Path.of(dir, ".camel-tui-pom.xml");
- tempPom.toFile().deleteOnExit();
Files.writeString(tempPom, modified);
cmd.add("-f");
cmd.add(tempPom.getFileName().toString());
+ return tempPom;
} catch (Exception e) {
// best effort — don't fail the launch
+ return null;
}
}
@@ -418,21 +426,50 @@ class LaunchManager {
failureLogCallback.accept(pl.name(), pl.outputFile());
}
}
+ cleanupTempPom(pl);
it.remove();
} else if (now - pl.startTime() > 8000) {
notify("Started: " + pl.name(), false);
+ // keep temp pom reference for cleanup when process stops
+ if (pl.tempPom() != null) {
+ activeTempPoms.put(pl.process().pid(), pl.tempPom());
+ }
it.remove();
}
}
}
+ void cleanupTempPom(long pid) {
+ Path tempPom = activeTempPoms.remove(pid);
+ if (tempPom != null) {
+ try {
+ Files.deleteIfExists(tempPom);
+ } catch (Exception e) {
+ // best effort
+ }
+ }
+ }
+
+ private static void cleanupTempPom(PendingLaunch pl) {
+ if (pl.tempPom() != null) {
+ try {
+ Files.deleteIfExists(pl.tempPom());
+ } catch (Exception e) {
+ // best effort
+ }
+ }
+ }
+
private void notify(String msg, boolean error) {
if (notificationCallback != null) {
notificationCallback.accept(msg, error);
}
}
- private record PendingLaunch(String name, Process process, Path
outputFile, long startTime) {
+ private record PendingLaunch(String name, Process process, Path
outputFile, long startTime, Path tempPom) {
+ PendingLaunch(String name, Process process, Path outputFile, long
startTime) {
+ this(name, process, outputFile, startTime, null);
+ }
}
private record DeferredLaunch(