Croway commented on code in PR #27959: URL: https://github.com/apache/camel/pull/27959#discussion_r4300246762
########## 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: Done in ea3b4a6d18f7: `forVersion` returns the exact release, else the newest of the same minor, else null, so a version newer than every release takes the unknown-version path (the `warnings` entry pointing at `camel_version_list`, no `javaCompatibility`, no blocker). `CamelReleasesTest` covers it with a stub catalog (4.24.0, 4.24.0-SNAPSHOT, 5.0.0 and an unknown older minor give null; 4.22.5 and 4.23.1-SNAPSHOT fall back to their minor), and `MigrationToolsTest` checks it against the real catalog with the minor after `CamelReleases.latest`, so the test holds once 4.24.0 is in the catalog. The upgrade guide entry says so in a sentence. _Claude Code on behalf of Croway_ ########## 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: Done in ea3b4a6d18f7: a dependency is Spring Boot when its group is `org.springframework.boot` or `org.apache.camel.springboot`; the parent and `spring-boot-maven-plugin` markers are unchanged. Test `quarkusSpringBootPropertiesIsNotSpringBoot`: a POM with `quarkus-camel-bom`, `camel-quarkus-kafka` and `io.quarkus:quarkus-spring-boot-properties` is analysed as `quarkus`. _Claude Code on behalf of Croway_ ########## 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: Done in ea3b4a6d18f7: `formatBomSnippet` takes the Camel Quarkus version and uses it for the `camel-quarkus-bom` snippet when there is no Quarkus platform version (the placeholder and the look-up comment stay for a project with neither); `DependencyCheckTools` passes `pom.camelQuarkusVersion()`. Tests in `DependencyCheckToolsTest`. _Claude Code on behalf of Croway_ -- 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]
