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 91e55fe47a7a CAMEL-21693: camel-jbang - the Camel CLI runs Camel 4 
only (#30804)
91e55fe47a7a is described below

commit 91e55fe47a7aa16629c3d768d728d866539a7d14
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 26 08:57:46 2026 +0100

    CAMEL-21693: camel-jbang - the Camel CLI runs Camel 4 only (#30804)
    
    Remove the checks for Camel 3 versions in the run of a custom Camel
    version (camel-cli-connector since 3.19.0, --repos since 3.18.1), and
    refuse a Camel 3 version in camel run --camel-version (also when it
    comes from camel version set or application.properties) and in
    camel version set, with exit code 2 (usage).
    
    * CAMEL-21693: use a neutral vendor build version in the example
    
    * CAMEL-21693: camel run - name the Camel version in the error, not the 
--camel-version option
    
    The version may come from camel version set or application.properties too.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  7 +++++++
 .../modules/ROOT/pages/camel-jbang-projects.adoc   | 10 +++++-----
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 17 +++++++---------
 .../jbang/core/commands/version/VersionSet.java    |  5 +++++
 .../core/commands/version/VersionSetTest.java      | 21 ++++++++++++++++++++
 .../camel/dsl/jbang/run/common/VersionHelper.java  | 18 +++++++++++++++++
 .../dsl/jbang/run/common/VersionHelperTest.java    | 23 ++++++++++++++++++++++
 7 files changed, 86 insertions(+), 15 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index fcda3d28f9a6..345486cc25c5 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2888,6 +2888,13 @@ that the version exists before it stores it: a version 
that does not exist exits
 the repositories cannot be reached the version is stored with a warning. 
`camel version set` without a version,
 `--runtime`, `--repo` or `--reset` is now a usage error (exit code `2`) 
instead of doing nothing.
 
+=== camel-jbang - the Camel CLI runs Camel 4 only
+
+`camel run --camel-version` and `camel version set` refuse a Camel 3 version: 
they print that the Camel CLI runs
+Camel 4.0 or newer and exit with code `2` (usage). Before, the run went on 
with the CLI of that Camel 3 version, which
+does not know the options of the current CLI, and Camel 3 is no longer 
maintained. A Camel 3 version stored earlier
+with `camel version set` is refused by `camel run` as well: set a Camel 4 
version, or use `camel version set --reset`.
+
 === camel-jbang - a name of a running integration matches only that integration
 
 A name given to `camel stop`, `camel get`, `camel cmd`, `camel trace` and the 
other commands for running integrations
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
index 86669b413bfd..21d83a9599b0 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
@@ -788,23 +788,23 @@ camel version
 
 === Running with a different version
 
-Use `--camel-version` to run with a specific Camel version:
+Use `--camel-version` to run with a specific Camel version (Camel 4.0 or 
newer):
 
 [source,bash]
 ----
-camel run * --camel-version=3.18.4
+camel run * --camel-version=4.18.0
 ----
 
 Or set a persistent version override:
 
 [source,bash]
 ----
-camel version set 3.18.2
+camel version set 4.18.0
 camel version set --reset
 ----
 
 `camel version set` checks in the Maven repositories that the version exists, 
and refuses one that does not
-(exit code 3). `--reset` removes the `camel-version`, `kamelets-version`, 
`repos` and `runtime` settings.
+(exit code 3), as well as a Camel 3 version (exit code 2). `--reset` removes 
the `camel-version`, `kamelets-version`, `repos` and `runtime` settings.
 
 IMPORTANT: You cannot combine `camel version set` with `--camel-version`.
 
@@ -812,7 +812,7 @@ For SNAPSHOT versions:
 
 [source,bash]
 ----
-jbang --fresh -Dcamel.jbang.version=3.21.0-SNAPSHOT camel@apache/camel 
[command]
+jbang --fresh -Dcamel.jbang.version=4.25.0-SNAPSHOT camel@apache/camel 
[command]
 ----
 
 === Listing available releases
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 551c44a19d20..e11450f318f3 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -924,6 +924,12 @@ public class Run extends CamelCommand implements 
CommandLifecycle {
             return CliExitCode.USAGE;
         }
 
+        if (camelVersion != null && 
!VersionHelper.isCamel4OrNewer(camelVersion)) {
+            printer().printErr("Camel version " + camelVersion
+                               + " is not supported: the Camel CLI runs Camel 
4.0 or newer.");
+            return CliExitCode.USAGE;
+        }
+
         // if we have a specific camel version then make sure we really need 
to switch
         if (camelVersion != null) {
             CamelCatalog catalog = new DefaultCamelCatalog();
@@ -1625,9 +1631,7 @@ public class Run extends CamelCommand implements 
CommandLifecycle {
         sb.append(String.format("//DEPS 
org.apache.camel:camel-java-joor-dsl:%s%n", camelVersion));
         sb.append(String.format("//DEPS org.apache.camel:camel-kamelet:%s%n", 
camelVersion));
         sb.append(String.format("//DEPS 
org.apache.camel:camel-kamelet-main:%s%n", camelVersion));
-        if (VersionHelper.isGE(camelVersion, "3.19.0")) {
-            sb.append(String.format("//DEPS 
org.apache.camel:camel-cli-connector:%s%n", camelVersion));
-        }
+        sb.append(String.format("//DEPS 
org.apache.camel:camel-cli-connector:%s%n", camelVersion));
         model.put("CamelDependencies", sb.toString());
 
         // use apache distribution of camel-jbang/github-resolver
@@ -1657,13 +1661,6 @@ public class Run extends CamelCommand implements 
CommandLifecycle {
         if (background) {
             cmds = BackgroundWait.withoutBackgroundOptions(cmds);
         }
-        if (mavenResolver.repos() != null) {
-            if (!VersionHelper.isGE(v, "3.18.1")) {
-                // --repos is not supported in 3.18.0 or older, so remove
-                cmds.remove("--repos=" + mavenResolver.repos());
-            }
-        }
-
         cmds.remove("--camel-version=" + camelVersion);
         // need to use jbang command to specify camel version
         List<String> jbangArgs = new ArrayList<>();
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
index d6cb9e7ed571..e61099a80da0 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSet.java
@@ -28,6 +28,7 @@ import 
org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
 import org.apache.camel.dsl.jbang.core.common.RuntimeCompletionCandidates;
 import org.apache.camel.dsl.jbang.core.common.RuntimeTypeConverter;
 import org.apache.camel.dsl.jbang.run.common.RuntimeType;
+import org.apache.camel.dsl.jbang.run.common.VersionHelper;
 
 @CommandDefinition(name = "set", description = "Set/change current Camel 
version", generateHelp = true,
                    footer = {
@@ -65,6 +66,10 @@ public class VersionSet extends CamelCommand {
             printer().printErr("Give the Camel version to set, --runtime, 
--repo, or --reset");
             return CliExitCode.USAGE;
         }
+        if (!reset && version != null && 
!VersionHelper.isCamel4OrNewer(version)) {
+            printer().printErr("Camel version " + version + " is not 
supported: the Camel CLI runs Camel 4.0 or newer.");
+            return CliExitCode.USAGE;
+        }
         if (!reset && version != null) {
             // a version that was never released fails every command that uses 
it later (CAMEL-26931)
             String repos = repo;
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSetTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSetTest.java
index 729325c254a1..6be331cd8247 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSetTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/version/VersionSetTest.java
@@ -110,6 +110,27 @@ class VersionSetTest extends BaseConfigTestSupport {
         CommandLineHelper.loadProperties(properties -> assertEquals("4.9.0", 
properties.get("camel-version")));
     }
 
+    @Test
+    void shouldRefuseACamel3Version() throws Exception {
+        UserConfigHelper.createUserConfig("""
+                camel-version=4.9.0
+                """);
+
+        VersionSet command = command();
+        command.version = "3.22.0";
+        boolean[] checked = new boolean[1];
+        command.versionCheck = (version, repos) -> {
+            checked[0] = true;
+            return true;
+        };
+        // CAMEL-21693: the Camel CLI runs Camel 4 only
+        assertEquals(CliExitCode.USAGE, command.doCall());
+        assertTrue(printer.getStderr().contains("Camel version 3.22.0 is not 
supported"), printer.getOutput());
+        assertFalse(checked[0], "a Camel 3 version is refused before it is 
looked up in the Maven repositories");
+
+        CommandLineHelper.loadProperties(properties -> assertEquals("4.9.0", 
properties.get("camel-version")));
+    }
+
     @Test
     void shouldSetAVersionThatCannotBeCheckedWithAWarning() throws Exception {
         UserConfigHelper.createUserConfig("""
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/VersionHelper.java
 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/VersionHelper.java
index b23a14ed563a..3872899cc43b 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/VersionHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/VersionHelper.java
@@ -19,11 +19,16 @@ package org.apache.camel.dsl.jbang.run.common;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.camel.catalog.cve.AdvisoryVersions;
 
 public final class VersionHelper {
 
+    // the major version a version starts with (up to 9 digits, so it always 
fits an int)
+    private static final Pattern LEADING_MAJOR = Pattern.compile("^\\d{1,9}");
+
     private VersionHelper() {
     }
 
@@ -73,6 +78,19 @@ public final class VersionHelper {
         return AdvisoryVersions.compare(source, target);
     }
 
+    /**
+     * Whether the Camel version is 4.0 or newer, including its milestones 
(4.0.0-M1) and the builds of a vendor
+     * (4.10.3.vendor-00001). The Camel CLI runs Camel 4 only. A version that 
does not start with a number is not
+     * rejected here.
+     */
+    public static boolean isCamel4OrNewer(String version) {
+        if (version == null) {
+            return true;
+        }
+        Matcher m = LEADING_MAJOR.matcher(version.trim());
+        return !m.find() || Integer.parseInt(m.group()) >= 4;
+    }
+
     public static String getMajorMinorVersion(String version) {
         String[] parts = version.split("\\.");
         return parts[0] + "." + parts[1];
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/VersionHelperTest.java
 
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/VersionHelperTest.java
index 31bed0608dd6..de8b973e0807 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/VersionHelperTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/VersionHelperTest.java
@@ -54,6 +54,29 @@ class VersionHelperTest {
         assertThat(Integer.signum(VersionHelper.compare(source, 
target))).isEqualTo(expected);
     }
 
+    @ParameterizedTest
+    @CsvSource({
+            "4.0.0, true",
+            "4.0.0-M1, true",
+            "4.24.0-SNAPSHOT, true",
+            "4.10.3.vendor-00001, true",
+            "10.0.0, true",
+            "3.22.0, false",
+            "3.18.4, false",
+            "2.25.4, false",
+            "' 3.22.0', false",
+            // not a version that starts with a number: not rejected here
+            "latest, true" })
+    void camel4OrNewer(String version, boolean expected) {
+        // CAMEL-21693: the Camel CLI runs Camel 4 only
+        assertThat(VersionHelper.isCamel4OrNewer(version)).isEqualTo(expected);
+    }
+
+    @Test
+    void noVersionIsNotRejected() {
+        assertThat(VersionHelper.isCamel4OrNewer(null)).isTrue();
+    }
+
     @Test
     void missingVersionIsTheSame() {
         assertThat(VersionHelper.compare(null, "4.24.0")).isZero();

Reply via email to