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

davsclaus 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 cf4f7e8c1a31 CAMEL-24469: Fix camel-jbang plugin versionCheck 
rejecting same SNAPSHOT release
cf4f7e8c1a31 is described below

commit cf4f7e8c1a31603b81fa6cac8a0203cc1dd92579
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Aug 25 12:01:52 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 before the string-based VersionHelper.compare, so a 
plugin
    whose firstVersion equals the current SNAPSHOT release (e.g. 
4.22.1-SNAPSHOT)
    was rejected and main.quit(1) was invoked — System.exit in tests, crashing 
the
    surefire fork running PluginHelperTest. main carries the identical code and 
is
    latent-broken (survives only because 4.23.0-SNAPSHOT is a .0 release that 
sorts
    correctly), so this lands the canonical fix on main as a companion to #25678
    (camel-4.22.x). Strip -SNAPSHOT from firstVersion as well (with null-safety)
    before comparing, and add regression tests for the same-SNAPSHOT accept and
    older-version reject cases.
    
    Closes #25679
    
    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);

Reply via email to