This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch fix/CAMEL-25422
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ac841753113c34dda1174b9534aec686e2787f6b
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Oct 7 21:42:07 2026 +0200

    CAMEL-25422: camel-jbang - detect Quarkus projects that name the BOM with 
properties
    
    camel run pom.xml ran a project generated by code.quarkus.io (and the
    camel-quarkus-examples) as a plain Camel Main project, because the BOM is
    declared as ${quarkus.platform.artifact-id}. Resolve the pom properties
    before matching, and also detect the runtime from the quarkus-maven-plugin
    or spring-boot-maven-plugin build plugin.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
---
 .../camel/dsl/jbang/core/commands/RunHelper.java   |  33 +++++-
 .../core/commands/RunHelperDetectRuntimeTest.java  | 132 +++++++++++++++++++++
 2 files changed, 163 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/RunHelper.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/RunHelper.java
index dccf404e15c7..bbd365ebab44 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/RunHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/RunHelper.java
@@ -39,6 +39,7 @@ import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ReflectionHelper;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 
@@ -79,9 +80,14 @@ public final class RunHelper {
     public static RuntimeType detectRuntimeFromPom(Path pomPath) {
         try {
             Model model = loadMavenModel(pomPath);
-            if (model != null && model.getDependencyManagement() != null) {
+            if (model == null) {
+                return null;
+            }
+            if (model.getDependencyManagement() != null) {
                 for (Dependency d : 
model.getDependencyManagement().getDependencies()) {
-                    String a = d.getArtifactId();
+                    // a project generated by code.quarkus.io names its BOMs 
with properties:
+                    // 
<artifactId>${quarkus.platform.artifact-id}</artifactId> (CAMEL-25422)
+                    String a = resolveProperty(model, d.getArtifactId());
                     if ("camel-spring-boot-bom".equals(a) || 
"spring-boot-dependencies".equals(a)) {
                         return RuntimeType.springBoot;
                     }
@@ -90,12 +96,35 @@ public final class RunHelper {
                     }
                 }
             }
+            // the Maven plugin of the runtime builds the application
+            if (model.getBuild() != null) {
+                for (Plugin plugin : model.getBuild().getPlugins()) {
+                    String a = resolveProperty(model, plugin.getArtifactId());
+                    if ("quarkus-maven-plugin".equals(a)) {
+                        return RuntimeType.quarkus;
+                    }
+                    if ("spring-boot-maven-plugin".equals(a)) {
+                        return RuntimeType.springBoot;
+                    }
+                }
+            }
         } catch (Exception e) {
             // ignore
         }
         return null;
     }
 
+    /** The value with a ${name} property of the pom resolved, as Maven would; 
as written when the pom has none. */
+    static String resolveProperty(Model model, String value) {
+        if (value != null && value.startsWith("${") && value.endsWith("}") && 
model.getProperties() != null) {
+            String resolved = 
model.getProperties().getProperty(value.substring(2, value.length() - 1));
+            if (resolved != null) {
+                return resolveProperty(model, resolved);
+            }
+        }
+        return value;
+    }
+
     public static List<String> scanMavenDependenciesFromPom(Path pomPath) 
throws Exception {
         Model model = loadMavenModel(pomPath);
         if (model != null) {
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunHelperDetectRuntimeTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunHelperDetectRuntimeTest.java
new file mode 100644
index 000000000000..bfaabad17861
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunHelperDetectRuntimeTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.camel.dsl.jbang.core.common.RuntimeType;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Verifies how {@code camel run pom.xml} tells the runtime of an existing 
Maven project from its pom.
+ */
+class RunHelperDetectRuntimeTest {
+
+    @TempDir
+    Path dir;
+
+    @Test
+    void quarkusBomNamedWithProperties() throws Exception {
+        // as generated by code.quarkus.io and used by camel-quarkus-examples
+        Path pom = pom("""
+                <properties>
+                    
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
+                    
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
+                    <quarkus.platform.version>3.30.0</quarkus.platform.version>
+                </properties>
+                <dependencyManagement>
+                    <dependencies>
+                        <dependency>
+                            <groupId>${quarkus.platform.group-id}</groupId>
+                            
<artifactId>${quarkus.platform.artifact-id}</artifactId>
+                            <version>${quarkus.platform.version}</version>
+                            <type>pom</type>
+                            <scope>import</scope>
+                        </dependency>
+                    </dependencies>
+                </dependencyManagement>
+                """);
+        
assertThat(RunHelper.detectRuntimeFromPom(pom)).isEqualTo(RuntimeType.quarkus);
+    }
+
+    @Test
+    void quarkusMavenPlugin() throws Exception {
+        Path pom = pom("""
+                <build>
+                    <plugins>
+                        <plugin>
+                            <groupId>io.quarkus.platform</groupId>
+                            <artifactId>quarkus-maven-plugin</artifactId>
+                        </plugin>
+                    </plugins>
+                </build>
+                """);
+        
assertThat(RunHelper.detectRuntimeFromPom(pom)).isEqualTo(RuntimeType.quarkus);
+    }
+
+    @Test
+    void springBootBom() throws Exception {
+        Path pom = pom("""
+                <dependencyManagement>
+                    <dependencies>
+                        <dependency>
+                            <groupId>org.apache.camel.springboot</groupId>
+                            <artifactId>camel-spring-boot-bom</artifactId>
+                            <version>4.23.0</version>
+                            <type>pom</type>
+                            <scope>import</scope>
+                        </dependency>
+                    </dependencies>
+                </dependencyManagement>
+                """);
+        
assertThat(RunHelper.detectRuntimeFromPom(pom)).isEqualTo(RuntimeType.springBoot);
+    }
+
+    @Test
+    void springBootMavenPlugin() throws Exception {
+        Path pom = pom("""
+                <build>
+                    <plugins>
+                        <plugin>
+                            <groupId>org.springframework.boot</groupId>
+                            <artifactId>spring-boot-maven-plugin</artifactId>
+                        </plugin>
+                    </plugins>
+                </build>
+                """);
+        
assertThat(RunHelper.detectRuntimeFromPom(pom)).isEqualTo(RuntimeType.springBoot);
+    }
+
+    @Test
+    void plainProject() throws Exception {
+        Path pom = pom("""
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.camel</groupId>
+                        <artifactId>camel-main</artifactId>
+                    </dependency>
+                </dependencies>
+                """);
+        assertThat(RunHelper.detectRuntimeFromPom(pom)).isNull();
+    }
+
+    private Path pom(String body) throws Exception {
+        Path pom = dir.resolve("pom.xml");
+        Files.writeString(pom, """
+                <project xmlns="http://maven.apache.org/POM/4.0.0";>
+                    <modelVersion>4.0.0</modelVersion>
+                    <groupId>org.example</groupId>
+                    <artifactId>demo</artifactId>
+                    <version>1.0</version>
+                """ + body + "</project>\n");
+        return pom;
+    }
+}

Reply via email to