davsclaus opened a new pull request, #30386: URL: https://github.com/apache/camel/pull/30386
The Camel CLI now generates the aesh metadata of its commands at compile time, with the aesh annotation processor. aesh then no longer reads the annotations of a command at run time, which makes the JDK create a proxy class for each kind of annotation. JIRA: [CAMEL-27232](https://issues.apache.org/jira/browse/CAMEL-27232) **Stacked on #30374 (CAMEL-27230: Upgrade to aesh 3.19.2 and skip its class path scan at start-up)**, which it builds on (`MetadataProviderRegistry.useOnly`). Retarget to `main` once #30374 is merged. Until then the PR build does not run (stacked PR); the results below are from local runs. ## Commits 1. **The CLI commands have a no-arg constructor** (the processor requires one). The constructors that took the `CamelJBangMain` are removed: `CamelJBangMain#command(T)` sets the main on a new command (`main.command(new Run())`), and `CamelCommand#getMain()` fails with a clear message when the main was not set. 195 constructors removed, about 250 call sites in main code and 850 in tests changed; all camel-jbang modules and plugins. This commit does not change behaviour. 2. **Generated metadata for the commands of camel-jbang-core.** - `aesh-processor` in the compiler of camel-jbang-core. It is not used for test compilation: `@CommandDefinition` is `@Inherited`, so it would also generate metadata for private nested test subclasses, which the generated code cannot reach (aeshell/aesh#785, point 3). - `CommandMetadataRegistry` finds the metadata of a command by its class name (`<command>_AeshMetadata`) in the packages of the commands. The registry of the processor is not used: it is in the package of the command the processor happens to see first, which can differ between machines. Its `META-INF` files are removed from the build output so aesh never discovers it. - **Export is read at run time.** aesh looks up the metadata of a class and then of its super classes, so `KubernetesExport` (which extends `Export` with 18 options of its own) would get the metadata of `Export` and lose those options. Generating it for the kubernetes plugin would need the 49 inherited option fields of `ExportBaseCommand` to be public. `CommandTree` now fails with a clear message when a command would get the metadata of a super class while it has options of its own, so a plugin command (such as one of camel-kit) cannot lose its options silently. - `CommandTree` takes the name and aliases of a command from the metadata (reading `@CommandDefinition` creates the annotation proxy as well). - The fields the generated code sets: 23 private option fields are now package-private (no reflection), and the option fields of 4 mixins used from other packages are public (aeshell/aesh#785, point 2). 3. **No method handles at start-up.** Three things in the first version loaded more than the metadata saves: string concatenation with `+` and the `equals` of a record (both start the method handles of the JDK, about 200 classes), and `command(new X())` in the command line of `CamelJBangMain`, for which the JVM loads every command class to verify it. Now `camel ps` loads 1,283 classes (#30374: 1,415). ## Numbers Launcher distribution, median of 15 runs after 3 warm-ups, the three builds interleaved per round, Apple M4 Pro, Java 25, CDS on (load average about 5): | Command | main | #30374 | this PR | |---|--:|--:|--:| | `camel version` | 131 ms | 96 ms | 78 ms | | `camel ps` | 144 ms | 103 ms | 90 ms | | `camel get route` | 151 ms | 124 ms | 108 ms | | `camel catalog component` | 184 ms | 157 ms | 143 ms | | `camel init --help` | 139 ms | 102 ms | 91 ms | | `camel get --help` | 162 ms | 125 ms | 97 ms | | `camel run --help` | 201 ms | 199 ms | 180 ms | | `camel --help` | 251 ms | 245 ms | 218 ms | ## Testing - All camel-jbang modules and plugins: `mvn test` (camel-jbang-core 3400 tests, kubernetes 2618, launcher 420, TUI, validate, MCP, ...), 0 failures. `RouteDiagramToolsTest.callsAtTheSameTime` (MCP) was a flake once (JMX name of two Camel contexts started at the same time) and passed on retry and in 5 reruns. - The help and parse golden files of camel-jbang-core are unchanged, so the generated metadata gives the same help and the same parse results as the annotations. - New `GeneratedCommandMetadataTest`: every command of the CLI (more than 150) has generated metadata of its own; a command without the main fails clearly; a sub class with options of its own and no metadata fails. - New `KubernetesExportMetadataTest`: `kubernetes export` has its own options and those of `Export`. Without `Export` excluded, it fails with the message of `CommandTree`. - Smoke test of the built launcher: `version`, `ps`, `get --help`, `kubernetes export --help` (`--image-registry` and `--runtime`), `test init` with and without `--force`, `self-update --help`, `catalog component`. The upgrade guide 4.24 (aesh section, for plugin authors) has the no-arg constructor and `main.command(new MyCommand())`. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
