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

   JIRA: [CAMEL-26350](https://issues.apache.org/jira/browse/CAMEL-26350)
   
   ## Problem
   
   Since CAMEL-26344, `camel plugin add <name>` stores the exact release of a 
community plugin built for the CLI (for example 
`io.kaoto.forage:camel-jbang-plugin-forage:1.6.2` with 
`camelVersions=[4.22.0,4.23.0)`) instead of `LATEST`. `camel self-update` only 
replaces the CLI and never touches `~/.camel-jbang-plugins.json`, so after an 
upgrade the plugins stay on the release of the previous Camel line, the 
load-time check warns, and the user has to add every plugin again. New plugin 
patches are no longer picked up either.
   
   ## Change
   
   **`camel plugin update [name]`** (new). It runs the CAMEL-26344 selection 
again (`PluginVersionResolver`, not duplicated) for the running CLI. It only 
does this for the plugins whose release `camel plugin add` selected, which are 
the entries that have `camelVersions`:
   - When another release is selected, it downloads that release first and then 
rewrites the entry: `dependency`, `camelVersions` and `camelVersionsSource`, 
plus `selectedForCamel` when the nearest older release is selected. It drops 
the cached `resolved` class path. A release that cannot be downloaded or loaded 
keeps the old entry, and the command exits with `1`.
   - A plugin added with `--version`/`--gav`, a plugin of the Apache Camel 
project, and a plugin added as `LATEST` (legacy) are reported and kept as they 
are. The legacy one gets the `camel plugin add` command that selects a release.
   - No match, or releases that cannot be read (offline): it warns and keeps 
the entry.
   - A release built for the CLI is never replaced by an older one. This guards 
against the case where the POM of the stored release cannot be read, or the 
stored release is on a release line beyond the ones that were read.
   - The file is only written when an entry changes, so it stays byte for byte 
when nothing changes.
   - `--dry-run` reports what would change, without downloading or writing 
anything.
   - The load-time warning now says `Run 'camel plugin update <name>'`. The 
load path is otherwise unchanged: it only warns and makes no network calls.
   
   **`camel self-update`**. It always runs the new launcher's `camel plugin 
update` after a successful install: releases, release-line/LTS pins and nightly 
builds. It uses `<versionsRoot>/<version>/bin/camel.sh`, or `camel.bat` through 
`cmd.exe /c` on Windows, with `CAMEL_SELF_UPDATE_CHECK=false`. Only the new CLI 
knows the Camel version it is built for.
   - It is skipped when the plugin configuration has no plugins. That 
configuration is read from the environment the new CLI runs with.
   - A failure or timeout prints a hint and never changes the exit code. The 
CLI stays installed.
   - `--skip-plugins` turns it off.
   - When `--check` finds a newer version, it runs `camel plugin update` 
in-process as a dry run for that version.
   - The process handling of `runInstaller` was extracted into `runProcess`, 
which keeps the same timeout, output drain and environment override, and is 
shared by both processes.
   
   ## User-visible behaviour
   
   ```
   $ camel plugin update
   forage 1.6.2 -> 1.7.0 (built for Camel 4.23.0)
   kit 0.4.0 is kept: camel plugin add did not select this release (such as one 
given with --version or --gav)
   kubernetes is released with the Camel CLI, and uses its version
   old is kept as LATEST: it was added without the Camel versions it is built 
for. Run 'camel plugin add old' to select the release built for this Camel CLI
   
   $ camel plugin update forage      # with no release for this CLI yet
   WARN: No release of forage is built for Camel CLI 4.24.0 yet. The newest, 
forage 1.7.0, is built for Camel 4.23.0. Keeping forage 1.4.2.
   Newest release per Camel version:
     Camel 4.23: forage 1.7.0
     ...
   
   $ camel self-update --check
   A new version is available (4.24.0 -> 4.25.0)
   Dry run for Camel CLI 4.25.0, nothing is changed:
   forage 1.7.0 -> 1.8.0 (built for Camel 4.25.0)
   
   $ camel self-update
   ...
   Installed Camel CLI 4.25.0 to ~/.local/share/camel-cli/versions/4.25.0
   forage 1.7.0 -> 1.8.0 (built for Camel 4.25.0)
   ```
   
   In the examples above, the second one is real output: a `--dry-run` against 
Maven Central with the 4.24.0-SNAPSHOT CLI. Forage has no release for 4.24 yet. 
The `self-update` outputs are illustrative.
   
   ## Tests
   
   - `PluginUpdateTest` (new). It uses the existing `FakePluginDownloader` 
fixture plugin and has no network calls. It tests the update decisions only, 
because the selection algorithm is already covered by 
`PluginVersionResolverTest` and `PluginAddTest`:
     - rewrite: moved to a new Camel line, a patch within the line, the nearest 
older release, and `selectedForCamel` only (parameterized)
     - kept with the file unchanged byte for byte: already current, no match, 
offline, a stored release beyond the lines read, and no downgrade when the POM 
cannot be read (parameterized)
     - explicit, built-in and legacy entries reported and untouched
     - a download failure keeps the old entry and exits with 1
     - a dry run for another CLI version
     - only the named plugin is updated, and the other entry stays byte for byte
     - an unknown name exits with 3
   - `SelfUpdateIntegrationTest`: one parameterized test drives the real 
`install.sh`. The fixture launcher now answers `plugin` with what it ran. The 
rows cover: the new launcher runs `plugin update`, `--skip-plugins`, a failing 
plugin update does not fail the CLI update, the `--check` preview, and `--check 
--skip-plugins`. The plugin configuration is given only through the child 
environment. The test also isolates the CLI home from the developer's one.
   - `PluginHelperTest`: the expected text of the load-time hint is updated.
   - I ran the plugin and command-tree tests of `camel-jbang-core` and all 
`camel-launcher` unit tests.
   
   ## Upgrade note
   
   The 4.24 upgrade guide has a new entry: "camel-jbang - camel self-update 
updates the plugins". The CAMEL-26344 entry now points to `camel plugin 
update`. The plugin page (`camel-jbang-projects.adoc`, new "Updating plugins" 
section) and the self-update page (`camel-jbang-launcher-install.adoc`) are 
updated. The generated command metadata and the `plugin update` command page 
are regenerated.
   
   _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]

Reply via email to