tools400 opened a new pull request, #27630:
URL: https://github.com/apache/camel/pull/27630

   # Description
   
   JIRA: [CAMEL-25497](https://issues.apache.org/jira/browse/CAMEL-25497)
   
   ## What is wrong
   
   With `--jvm-debug`, `--jvm-args` or `--open-telemetry-agent`, `camel run` 
starts the integration in a new JVM with `jbang run ... camel@apache/camel run 
...` (`Run.runCamelVersion`). It hands `-Dcamel.jbang.version` to that JVM only 
when `--camel-version` is given and differs from the running version (an equal 
one is reset to `null` as "same version"). Otherwise the new JVM runs the 
default version of the `camel@apache/camel` catalog script (`CamelJBang.java`, 
currently 4.22.0), not the version the user started.
   
   A Camel CLI pinned with `jbang -Dcamel.jbang.version=4.22.1` therefore runs 
the integration on 4.22.0. With the Camel JBang test plugin installed, the new 
JVM fails at start-up; otherwise it runs the other Camel version without a 
warning. The `camelVersion != null` guard dates from CAMEL-19726, which added 
the JVM debug relaunch to the code path that until then served 
`--camel-version` only.
   
   ## Steps to reproduce
   
   ```shell
   jbang -Dcamel.jbang.version=4.22.1 camel@apache/camel init hello.camel.yaml
   jbang -Dcamel.jbang.version=4.22.1 camel@apache/camel run hello.camel.yaml 
--jvm-args=-Dfoo=bar --max-seconds=10 --verbose
   # jbang run --java-options=-Dfoo=bar --java=21 camel@apache/camel run 
hello.camel.yaml --max-seconds=10 --verbose --kamelets-version=4.22.0
   # ... Artifact org.apache.camel:camel-jbang-plugin-test:pom:4.22.0 is 
present in the local repository, ...
   # Exception in thread "main" java.lang.NoClassDefFoundError: 
org/citrusframework/jbang/cli/Printer
   ```
   
   The same `camel run` without these options starts Apache Camel 4.22.1. 
`--jvm-debug=5005` builds the same command line with `--debug=5005`.
   
   ## Fix
   
   - The jbang command always names a version: `-Dcamel.jbang.version=` the 
requested `--camel-version`, else the running version (`new 
DefaultCamelCatalog().getCatalogVersion()`, as `Run` already records it for the 
run settings). The kamelets handling still depends on a requested 
`--camel-version` only, as before.
   - The command is built in the new package-private 
`createCamelVersionCommand()`; `runCamelVersion` starts the process with it, 
unchanged otherwise.
   
   ## Tests
   
   | Test | Asserts |
   |---|---|
   | `RunCamelVersionCommandTest.jvmDebugRunsTheRunningCamelVersion` | 
`--jvm-debug=5005`: the command has `-Dcamel.jbang.version=<running version>` 
and `--debug=5005` |
   | `RunCamelVersionCommandTest.jvmArgsRunTheRunningCamelVersion` | 
`--jvm-args=-Dfoo=bar`: the command has `-Dcamel.jbang.version=<running 
version>` and `--java-options=-Dfoo=bar` |
   | `RunCamelVersionCommandTest.theRequestedCamelVersionWins` | 
`--camel-version=4.21.0`: the command has `-Dcamel.jbang.version=4.21.0`, not 
the running version, and no `--camel-version` for the new JVM |
   
   The first two fail against `main`, the third passes. In 
`dsl/camel-jbang/camel-jbang-core`, all `Run*Test` classes are green (70 
tests). `mvn clean install -DskipTests` in the module leaves no uncommitted 
changes. With the fix, the reproducer above run with the locally built Camel 
CLI 4.23.0-SNAPSHOT prints `jbang run -Dcamel.jbang.version=4.23.0-SNAPSHOT 
--java-options=-Dfoo=bar ...`, and the new JVM starts Apache Camel 
4.23.0-SNAPSHOT and runs the route. I did not run a root `mvn clean install 
-DskipTests`.
   
   _Changes prepared with Claude Code on behalf of @tools400._
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other 
small items do not require a JIRA issue. In this case your pull request should 
address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] 
Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the 
appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build 
auto-formats your code. This will also be verified as part of the checks and 
your PR may be rejected if if there are uncommited changes after running `mvn 
clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at 
https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   


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