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 47bbbded2a58 chore: camel-jbang - camel run of an existing Spring Boot 
project without src/main/resources (#27204)
47bbbded2a58 is described below

commit 47bbbded2a5874f4892d035775c55378968438f6
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Oct 1 15:36:26 2026 +0200

    chore: camel-jbang - camel run of an existing Spring Boot project without 
src/main/resources (#27204)
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 41 ++++++++++++++++------
 .../core/commands/RunExistingProjectTest.java      |  8 +++--
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index e7ebda91b4b3..06cc2dade192 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -590,6 +590,9 @@ public class Run extends CamelCommand {
         return run();
     }
 
+    // the logback configuration of an existing Spring Boot project run, in a 
temp file
+    private Path springBootLogback;
+
     public Integer runExport() throws Exception {
         return runExport(false);
     }
@@ -2433,9 +2436,33 @@ public class Run extends CamelCommand {
      * The JVM arguments ({@code spring-boot.run.jvmArguments}) an existing 
Spring Boot project is run with: logging to
      * file, the profile, the port and properties, the flight recording and 
{@code --jvm-args}.
      */
+    /**
+     * The logback configuration an existing Spring Boot project runs with, 
logging to file so the TUI can read the log:
+     * a temp file, so the project is not changed and needs no 
src/main/resources. Null when it cannot be written.
+     */
+    Path springBootLogbackConfig() {
+        if (springBootLogback == null) {
+            try (InputStream is = 
Run.class.getClassLoader().getResourceAsStream("spring-boot-logback.xml")) {
+                if (is == null) {
+                    return null;
+                }
+                Path file = Files.createTempFile("camel-jbang-logback-", 
".xml");
+                file.toFile().deleteOnExit();
+                Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING);
+                springBootLogback = file;
+            } catch (IOException e) {
+                return null;
+            }
+        }
+        return springBootLogback;
+    }
+
     List<String> buildExistingSpringBootJvmArgs() {
         List<String> args = new ArrayList<>();
-        args.add("-Dlogging.config=classpath:logback-camel-jbang.xml");
+        Path logback = springBootLogbackConfig();
+        if (logback != null) {
+            args.add("-Dlogging.config=" + logback.toUri());
+        }
         if (profile != null && !"prod".equals(profile)) {
             args.add("-Dcamel.main.profile=" + profile);
         }
@@ -2487,14 +2514,6 @@ public class Run extends CamelCommand {
             w.write(fos, model);
         }
 
-        // copy logback config for logging to file (so TUI can read logs)
-        Path logbackPath = 
projectDir.resolve("src/main/resources/logback-camel-jbang.xml");
-        try (InputStream is = 
Run.class.getClassLoader().getResourceAsStream("spring-boot-logback.xml")) {
-            if (is != null) {
-                Files.copy(is, logbackPath, 
StandardCopyOption.REPLACE_EXISTING);
-            }
-        }
-
         // shutdown hook to clean up temp files
         Runtime.getRuntime().addShutdownHook(new Thread(() -> {
             try {
@@ -2513,7 +2532,9 @@ public class Run extends CamelCommand {
                     }
                 }
                 Files.deleteIfExists(tempPom);
-                Files.deleteIfExists(logbackPath);
+                if (springBootLogback != null) {
+                    Files.deleteIfExists(springBootLogback);
+                }
             } catch (Exception e) {
                 // ignore
             }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExistingProjectTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExistingProjectTest.java
index d40c744043f2..22cc293cabdc 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExistingProjectTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunExistingProjectTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.dsl.jbang.core.commands;
 
+import java.net.URI;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.List;
@@ -158,8 +159,11 @@ class RunExistingProjectTest extends 
CamelCommandBaseTestSupport {
         List<String> args = run("--profile=dev", "--port=9090", 
"--prop=foo=bar", "--jvm-args=-Xmx512m", "pom.xml")
                 .buildExistingSpringBootJvmArgs();
 
-        assertThat(args).containsExactly(
-                "-Dlogging.config=classpath:logback-camel-jbang.xml",
+        // the logback configuration is a temp file: the project needs no 
src/main/resources and is not changed
+        
assertThat(args.get(0)).startsWith("-Dlogging.config=file:").endsWith(".xml");
+        
assertThat(Path.of(URI.create(args.get(0).substring("-Dlogging.config=".length())))).exists()
+                .content().contains("<configuration");
+        assertThat(args.subList(1, args.size())).containsExactly(
                 "-Dcamel.main.profile=dev",
                 "-Dserver.port=9090",
                 "-Dfoo=bar",

Reply via email to