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


##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/CamelReleases.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.mcp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.tooling.model.ReleaseModel;
+
+/**
+ * Reads the Camel releases known to the catalog ({@link 
CamelCatalog#camelReleases()}, the data behind
+ * {@code camel_version_list}): the latest release and the JDK versions a 
release supports.
+ */
+final class CamelReleases {
+
+    private static final Pattern RELEASE_VERSION = 
Pattern.compile("\\d+\\.\\d+\\.\\d+");
+
+    private CamelReleases() {
+    }
+
+    /**
+     * The newest Camel release in the catalog, or null when the catalog has 
no release data. A SNAPSHOT catalog version
+     * is not a release, so this is what a project should be compared with.
+     */
+    static String latest(CamelCatalog catalog) {
+        String latest = null;
+        for (ReleaseModel release : releases(catalog)) {
+            if (latest == null || 
DependencyCheckTools.compareVersions(release.getVersion(), latest) > 0) {
+                latest = release.getVersion();
+            }
+        }
+        return latest;
+    }
+
+    /**
+     * The release that tells the requirements of a version: the release 
itself, else the newest release of the same
+     * major.minor, else (a version newer than every release, such as the one 
in development) the latest release.
+     * Returns null for a version the catalog does not know otherwise.
+     */
+    static ReleaseModel forVersion(CamelCatalog catalog, String version) {
+        if (version == null || version.isBlank()) {
+            return null;
+        }
+        String plain = version.trim().replace("-SNAPSHOT", "");
+        String[] parts = plain.split("\\.");
+        String minor = parts.length >= 2 ? parts[0] + "." + parts[1] + "." : 
null;
+        ReleaseModel exact = null;
+        ReleaseModel sameMinor = null;
+        ReleaseModel newest = null;
+        for (ReleaseModel release : releases(catalog)) {
+            String v = release.getVersion();
+            if (v.equals(plain)) {
+                exact = release;
+            }
+            if (minor != null && v.startsWith(minor)
+                    && (sameMinor == null || 
DependencyCheckTools.compareVersions(v, sameMinor.getVersion()) > 0)) {
+                sameMinor = release;
+            }
+            if (newest == null || DependencyCheckTools.compareVersions(v, 
newest.getVersion()) > 0) {
+                newest = release;
+            }
+        }
+        if (exact != null) {
+            return exact;
+        }
+        if (sameMinor != null) {
+            return sameMinor;
+        }
+        if (newest != null && DependencyCheckTools.compareVersions(plain, 
newest.getVersion()) > 0) {

Review Comment:
   For a version newer than every release in the catalog, this returns the 
newest release, so its JDK list becomes the requirement. The catalog learns 
about a release only once it is out (b741d6f9d695 added 4.23.0 on its release 
day), so the 4.24.0 server will list releases up to 4.23.x. 
`camel_migration_compatibility` with `targetVersion=4.24.0` and 
`javaVersion=17` then reports Java 17 as compatible (`requiredVersion` 17, 
`supportedVersions` 17, 21, 25), although Java 17 is dropped from Camel 4.24 
onwards (CAMEL-22996), and `camel_migration_recipes` gives no Java upgrade 
suggestion. That is the error this PR fixes, in the other direction.
   
   Returning null here takes the existing path for an unknown version (the 
warning "The catalog has no release data for Camel ...: check its Java 
requirement with camel_version_list", and `camel version list` reads the 
release pages online). The same-minor fallback above is fine, as a patch 
release does not change the JDK baseline.



##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/MigrationData.java:
##########
@@ -188,67 +196,145 @@ public static PomAnalysis parsePomContent(String 
pomContent) throws Exception {
                 javaVersion = getElementText(properties, 
"maven.compiler.target");
             }
         }
+        boolean springBoot = springBootVersion != null;
+        boolean quarkus = quarkusVersion != null;
+
+        Element parent = getChild(project, "parent");
+        if (parent != null) {
+            String artifactId = getChildText(parent, "artifactId");
+            String version = getChildText(parent, "version");
+            if ("spring-boot-starter-parent".equals(artifactId) || 
"spring-boot-dependencies".equals(artifactId)) {
+                springBoot = true;
+                if (springBootVersion == null && version != null && 
!version.startsWith("$")) {
+                    springBootVersion = version;
+                }
+            }
+        }
 
-        // Scan dependencyManagement and dependencies for version and runtime 
detection
+        // Scan dependencyManagement, dependencies and plugin dependencies for 
version and runtime detection
         NodeList allDeps = doc.getElementsByTagName("dependency");
         for (int i = 0; i < allDeps.getLength(); i++) {
             Element dep = (Element) allDeps.item(i);
-            String groupId = getElementText(dep, "groupId");
-            String artifactId = getElementText(dep, "artifactId");
-            String version = getElementText(dep, "version");
+            String groupId = getChildText(dep, "groupId");
+            String artifactId = getChildText(dep, "artifactId");
+            String version = getChildText(dep, "version");
 
             if (groupId == null || artifactId == null) {
                 continue;
             }
+            boolean fixedVersion = version != null && !version.startsWith("$");
 
-            // Detect Camel version from BOM
-            if (camelVersion == null && version != null && 
!version.startsWith("$")) {
-                if ("camel-bom".equals(artifactId) || 
"camel-spring-boot-bom".equals(artifactId)
-                        || "camel-quarkus-bom".equals(artifactId)) {
-                    camelVersion = version;
-                }
+            // Detect Camel version from BOM (the camel-quarkus-bom version is 
a Camel Quarkus version)
+            if (camelVersion == null && fixedVersion
+                    && ("camel-bom".equals(artifactId) || 
"camel-spring-boot-bom".equals(artifactId))) {
+                camelVersion = version;
+            }
+            if (camelQuarkusVersion == null && fixedVersion && 
"camel-quarkus-bom".equals(artifactId)) {
+                camelQuarkusVersion = version;
             }
 
             // Detect Spring Boot
-            if (springBootVersion == null && version != null && 
!version.startsWith("$")) {
-                if ("spring-boot-dependencies".equals(artifactId)
-                        || "spring-boot-starter-parent".equals(artifactId)) {
-                    springBootVersion = version;
-                }
+            if (artifactId.contains("spring-boot")) {

Review Comment:
   Nit: this matches any artifact with `spring-boot` in its name, also in 
dependency management and plugin dependencies. A Camel Quarkus project with 
`io.quarkus:quarkus-spring-boot-properties` (a Quarkus Spring compatibility 
extension) gets both flags, and `runtimeType()` checks Spring Boot first, so it 
is analysed as Spring Boot. Checking the group (`org.springframework.boot`, 
`org.apache.camel.springboot`) avoids that.



##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/MigrationData.java:
##########
@@ -172,6 +179,7 @@ public static PomAnalysis parsePomContent(String 
pomContent) throws Exception {
             if (camelVersion == null) {
                 camelVersion = getElementText(properties, "camel-version");
             }
+            camelQuarkusVersion = getElementText(properties, 
"camel-quarkus.version");

Review Comment:
   Nit: `camelQuarkusVersion` is read here and from the `camel-quarkus-bom`, 
but nothing uses it. `formatBomSnippet` could use it for the 
`camel-quarkus-bom` snippet when there is no Quarkus platform version, instead 
of the `${camel-quarkus.version}` placeholder, or the field could go.



-- 
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