This is an automated email from the ASF dual-hosted git repository.
apupier 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 1394701e78e CAMEL-22227 - basic heuristic to determine runtime
automatically when doing Camel JBang Dependency update
1394701e78e is described below
commit 1394701e78e633fa4f1fe68bff9d7be5cecd824f
Author: Aurélien Pupier <[email protected]>
AuthorDate: Tue Jul 15 11:05:46 2025 +0200
CAMEL-22227 - basic heuristic to determine runtime automatically when
doing Camel JBang Dependency update
it allows to have correct dependencies based on current runtime of the
Maven project without specifying the --runtime option (which is
relatively redundant with the pom.xml)
- ideally this should resolve the Maven pom and look for specific
dependencies
- looking to specific word in the file should be enough for most of the
cases
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../camel/dsl/jbang/core/commands/DependencyUpdate.java | 15 +++++++++++++++
.../dsl/jbang/core/commands/DependencyUpdateTest.java | 5 ++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdate.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdate.java
index 0935a7a00f2..2cd8f76ff25 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdate.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdate.java
@@ -28,6 +28,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.apache.camel.dsl.jbang.core.common.RuntimeType;
import org.apache.camel.tooling.maven.MavenGav;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.StringHelper;
@@ -71,6 +72,20 @@ public class DependencyUpdate extends DependencyList {
updateJBangSource();
}
+ if (maven && this.runtime == null) {
+ // Basic heuristic to determine if the project is a Quarkus or
Spring Boot one.
+ String pomContent = new String(Files.readAllBytes(file));
+ if (pomContent.contains("quarkus")) {
+ runtime = RuntimeType.quarkus;
+ } else if (pomContent.contains("spring-boot")) {
+ runtime = RuntimeType.springBoot;
+ } else if (pomContent.contains("camel-main")) {
+ runtime = RuntimeType.main;
+ } else {
+ // In case no specific word found, we keep the runtime type
unset even if the fallback is currently on Main Runtime type
+ }
+ }
+
return super.doCall();
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdateTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdateTest.java
index 5db253a0610..8c24172389d 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdateTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyUpdateTest.java
@@ -57,16 +57,15 @@ class DependencyUpdateTest extends CamelCommandBaseTest {
void shouldDependencyUpdate(RuntimeType rt) throws Exception {
prepareMavenProject(rt);
- checkNoUpdateOnFreshlyGeneratedproject(rt);
+ checkNoUpdateOnFreshlyGeneratedproject();
//TODO: check content of pom.xml after a new component is provided
}
- private void checkNoUpdateOnFreshlyGeneratedproject(RuntimeType rt) throws
Exception {
+ private void checkNoUpdateOnFreshlyGeneratedproject() throws Exception {
DependencyUpdate command = new DependencyUpdate(new
CamelJBangMain().withPrinter(printer));
CommandLine.populateCommand(command,
"--dir=" + workingDir,
- "--runtime=%s".formatted(rt.runtime()), // This parameter to
be removed when the runtime type will be auto-detected to compute dependencies
new File(workingDir, "pom.xml").getAbsolutePath());
int exit = command.doCall();
Assertions.assertEquals(0, exit, printer.getLines().toString());