This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24469 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 27e07c1af51ec623e04ba657cb8303b7dd3b1e10 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Aug 25 10:58:25 2026 +0200 CAMEL-24469: Fix camel-jbang plugin versionCheck rejecting same SNAPSHOT release versionCheck stripped -SNAPSHOT from the current version but not from the plugin firstVersion, then compared them with VersionHelper.compare. On patch releases such as 4.22.1-SNAPSHOT the string-based comparison of "4.22.1" vs "4.22.1-SNAPSHOT" returned a negative result, so a plugin whose firstVersion equals the current SNAPSHOT was rejected and main.quit(1) was invoked. In tests this is System.exit, which crashed the surefire fork running PluginHelperTest and broke all builds on the camel-4.22.x branch. Strip -SNAPSHOT from firstVersion as well before comparing, and add regression tests covering the same-SNAPSHOT accept and older-version reject cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/dsl/jbang/core/common/PluginHelper.java | 11 ++++++++--- .../dsl/jbang/core/common/PluginHelperTest.java | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java index 1638540992c9..5896dc18ce98 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java @@ -477,12 +477,17 @@ public final class PluginHelper { } static void versionCheck(CamelJBangMain main, String version, String firstVersion, String command) { - // compare versions without SNAPSHOT + // compare versions without SNAPSHOT (on both sides) so a SNAPSHOT build is not + // rejected against a plugin whose firstVersion is the same SNAPSHOT release String source = version; - if (source.endsWith("-SNAPSHOT")) { + if (source != null && source.endsWith("-SNAPSHOT")) { source = source.replace("-SNAPSHOT", ""); } - boolean accept = VersionHelper.isGE(source, firstVersion); + String first = firstVersion; + if (first != null && first.endsWith("-SNAPSHOT")) { + first = first.replace("-SNAPSHOT", ""); + } + boolean accept = VersionHelper.isGE(source, first); if (!accept) { main.getOut().println("Cannot load plugin camel-jbang-plugin-" + command + " with version: " + version + " because plugin has first version: " + firstVersion + ". Exit"); diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java index c9a0255953d2..cff501ef7210 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import picocli.CommandLine; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -264,6 +265,26 @@ public class PluginHelperTest { "plugin loaded from the cached jar, not via FACTORY_FINDER"); } + @Test + void testVersionCheckAcceptsSameSnapshotVersion() { + // CAMEL-24469: a SNAPSHOT build must not be rejected against a plugin whose firstVersion + // is the same SNAPSHOT release. Rejection calls quit() which, on the real main, is System.exit + // and crashes the surefire fork. This regressed on patch releases such as 4.22.1-SNAPSHOT. + QuitCapture main = new QuitCapture(); + assertThatCode(() -> PluginHelper.versionCheck(main, "4.22.1-SNAPSHOT", "4.22.1-SNAPSHOT", "fake")) + .doesNotThrowAnyException(); + assertFalse(main.quitCalled, "same SNAPSHOT version must be accepted, not quit"); + } + + @Test + void testVersionCheckRejectsOlderVersion() { + // A plugin requiring a newer firstVersion than the current build must be rejected (quit). + QuitCapture main = new QuitCapture(); + assertThrows(RuntimeException.class, + () -> PluginHelper.versionCheck(main, "4.22.1-SNAPSHOT", "4.23.0", "fake")); + assertTrue(main.quitCalled, "older build than plugin firstVersion must be rejected"); + } + private void writeConfig(JsonObject pluginEntry) throws Exception { JsonObject plugins = new JsonObject(); plugins.put(pluginEntry.getString("name"), pluginEntry);
