Repository navigation
CAMEL-27232: camel-jbang - generated aesh metadata for the CLI commands - #30386
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…a registries The CLI commands have no generated aesh metadata, so the CLI tells aesh 3.19.2 to use only its internal registry (MetadataProviderRegistry.useOnly) instead of looking through every JAR on the class path. The test plugin registers the generated aesh metadata of the Citrus commands it extends. Takes 30-40 ms off camel version, ps, get route and catalog component. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…, and get the main set after creation The aesh annotation processor generates the metadata of a command only when it has a no-arg constructor. 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 clearly when it was not set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…enerated at compile time The aesh annotation processor generates the metadata of the commands of camel-jbang-core, so aesh no longer reads their annotations at run time (which creates a proxy class for each kind of annotation). CommandMetadataRegistry finds the metadata of a command by its class name in the packages of the commands; the registry of the processor is removed from the jar, as it is in a package that depends on the order the processor sees the commands. CommandTree takes the name and aliases of a command from the metadata. aesh looks up the metadata of a command and then of its super classes, so Export (which KubernetesExport extends with options of its own) is read at run time, and CommandTree fails when a command would get the metadata of a super class while it has options of its own. The option fields that the generated code sets are no longer private, and the fields of mixins used from other packages are public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
…method handles of the JDK Three things on the path of every command made the JVM load more than the metadata saves: the 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 CamelJBangMain. camel ps loads 1,283 classes again, as the prototype did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
The design is sound: separating command construction (no-arg) from main-binding (setCamelMain()) enables compile-time metadata generation while keeping the runtime contract enforced via the getMain() guard. The cmd(Object) / command(T) split cleanly separates the deferred-loading internal API from the typed plugin API.
Three low-severity comments below — no blockers.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
LGTM. This is a clean implementation of compile-time aesh metadata generation for camel-jbang commands.
The key design decisions are well-reasoned and documented:
cmd(Object)/command(T)split —Objectparameter type intentionally prevents the JVM from verifying that every command class is a subtype ofCamelCommandat class-loading time, deferring per-command class load until the command is actually invoked. The Javadoc makes the rationale explicit.CommandMetadataRegistryas a plain class (not a record) — the commit message explains thatrecord#equalstriggers JDK method handles (~200 classes), costing more than the metadata saves on short commands (camel ps).String.concatinstead of+— same rationale (method handle avoidance). Unusual but correctly justified.checkMetadataOf()guard — fires at command-tree construction time (startup) and catches the case where a plugin extends a CLI command that has generated metadata, but the plugin has options of its own that the inherited metadata doesn't cover. TheKubernetesExportMetadataTestspecifically validates this forKubernetesExport extends Export.excludedset — correctly scoped toExport,ExportBaseCommand, andCamelCommand(the CLI's extension points for plugins). The registry returnsnullfor these, forcing aesh to fall back to runtime annotation reflection.- pom.xml pattern —
aesh-processorasannotationProcessorPathfor main compile,<proc>none</proc>for test compile (tests have private nested subclasses of commands that the processor can't reach),maven-antrun-pluginatgenerate-test-sourcesto delete the processor's registry (which is not used — the CLI usesCommandMetadataRegistryinstead).
Test coverage is solid:
GeneratedCommandMetadataTest.everyCommandHasGeneratedMetadataOfItsOwnloads the full command tree (150+ commands) and checks each one has its own generated metadata — this is a high-value regression guard.aSubClassWithOptionsOfItsOwnAndNoMetadataFailsvalidates thecheckMetadataOf()guard directly.aCommandIsCreatedWithoutTheMainAndGetsItAfterwardsvalidates theIllegalStateExceptionpath ingetMain().KubernetesExportMetadataTestvalidates thatKubernetesExportsees both its own options andExport's options (the excluded-set mechanism is exercised end-to-end).
Upgrade guide correctly instructs plugin authors on the no-arg constructor requirement and the main.command(new MyCommand()) pattern.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
…IllegalStateException in the upgrade guide Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
All three comments from the previous review are addressed in the latest commit. ✅
CommandMetadataRegistry: the class-level guard comment// not a record (see above): do not convert it to oneis in place — future readers get the why without digging into the Javadoc.String.concatrationale: the comment now includes the measured timing (45 ms with String.concatvs47 ms with +), giving future readers a concrete data point to revisit if the JDK changes the tradeoff.- Upgrade guide:
getMain()is described as throwingIllegalStateException, making the error searchable in stack traces.
No new issues in this commit. Good to merge.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review: CI failure — missed constructor migration in ExportDependencyTest
The latest commit merged main into the branch. CI is now failing on posix-validator (ubuntu-latest):
[ERROR] ExportDependencyTest.java:[596,26] constructor Export in class Export cannot be applied to given types;
required: no arguments
found: org.apache.camel.dsl.jbang.core.commands.CamelJBangMain
reason: actual and formal argument lists differ in length
Root cause: The PR migrated new Export(new CamelJBangMain()) → new CamelJBangMain().command(new Export()) at lines 541 and 565 of ExportDependencyTest.java, but missed the third occurrence around line 596. The Export constructor no longer accepts a CamelJBangMain argument after this PR's changes, so the un-migrated call fails to compile.
Fix: Apply the same migration pattern to the remaining call at line ~596 of ExportDependencyTest.java:
- Export command = new Export(new CamelJBangMain());
+ Export command = new CamelJBangMain().command(new Export());This review was generated by an AI agent, Hermès on behalf of @gnodet.
…ort with the no-arg constructor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
Thanks @gnodet-bot, fixed in 859fa7a. That test ( Claude Code on behalf of Claus Ibsen |
gnodet-bot
left a comment
There was a problem hiding this comment.
The fix is correct. ✅
ExportDependencyTest.java line 596 — the remaining new Export(new CamelJBangMain()) call site has been migrated to new CamelJBangMain().command(new Export()), consistent with the two calls already migrated earlier in the same test file.
No new issues in this commit.
Next step: rebase the branch onto main to drop the now-merged #30374 stacked commits — that will also re-trigger CI.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
The --mask option from CAMEL-27223 goes into the commands without their CamelJBangMain constructor, and its tests create the commands with CamelJBangMain.command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
Previous findings are all addressed. ✅
The --mask feature added in this batch of commits is clean across all 11 commands. ListingFormat.masked() delegates correctly to URISupport.sanitizeUri() (Camel's established log-sanitization method), propagation is consistent across every command that displays endpoint URIs, the default of true is the right security posture, and both --mask=false and the edge cases (RAW-encoded passwords, user-info passwords, bracket-notation parameters, null input) are covered by the new unit and integration tests. No issues found.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 5 of 728 tested, 0 compile-only — current: 5 all testedMaveniverse Scalpel detected 5 affected modules (current approach: 5). Skip-tests mode would test 5 modules (11 direct + 0 downstream), skip tests for 0 (generated code, meta-modules) Modules Scalpel would test (5)
💡 Manual integration tests recommended:
All tested modules (14 modules, 3m 54s total)Total reactor time: 3m 54s
Top 20 slowest modules:
|
oscerd
left a comment
There was a problem hiding this comment.
Large but coherent, and it completes the aesh story started in #30374. The driver is the aesh annotation processor: it generates the command metadata at compile time, which is what lets the runtime class-path scan stay off, and it instantiates commands through a no-arg constructor. That is why every command drops its (CamelJBangMain main) constructor and CamelCommand moves from a final, constructor-injected main to a setCamelMain that CamelJBangMain#command calls right after creating the command, with getMain() throwing IllegalStateException when it was not set.
The per-command change is uniform, just removing the forwarding constructor, so the large file count is mechanical. The one design trade-off is that main is no longer final, but that is forced by the no-arg requirement, and the getMain() guard turns a command created outside the factory into a fast, clear failure instead of an NPE, which is the right mitigation. Since the old constructors only forwarded main to super and initialized nothing from it, the late set does not break any field-initialization assumption.
The pom side is the careful part and the comments earn their place. The processor runs with native-image metadata disabled, and its own generated registry (META-INF/aesh/registry and the MetadataRegistry service file) is deleted after process-classes because it carries the metadata of commands a plugin extends, in the package of whichever command the processor saw first, leaving the CLI's own CommandMetadataRegistry as the single source. That explains a deletion that would otherwise look surprising.
Together with #30374 this is the full picture: compile-time generated metadata, the CLI's own registry, and no runtime scan. Green, with an upgrade-guide note. The surface area is wide, so the CamelJBangMain#command factory wiring is the one spot I would give a second committer read, but the pattern holds. No blockers.
Claude Code on behalf of oscerd
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
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 tomainonce #30374 is merged. Until then the PR build does not run (stacked PR); the results below are from local runs.Commits
CamelJBangMainare removed:CamelJBangMain#command(T)sets the main on a new command (main.command(new Run())), andCamelCommand#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.aesh-processorin the compiler of camel-jbang-core. It is not used for test compilation:@CommandDefinitionis@Inherited, so it would also generate metadata for private nested test subclasses, which the generated code cannot reach (aesh-processor: commands without a no-arg constructor, mixin fields it cannot reach, inaccessible subclasses aeshell/aesh#785, point 3).CommandMetadataRegistryfinds 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. ItsMETA-INFfiles are removed from the build output so aesh never discovers it.KubernetesExport(which extendsExportwith 18 options of its own) would get the metadata ofExportand lose those options. Generating it for the kubernetes plugin would need the 49 inherited option fields ofExportBaseCommandto be public.CommandTreenow 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.CommandTreetakes the name and aliases of a command from the metadata (reading@CommandDefinitioncreates the annotation proxy as well).+and theequalsof a record (both start the method handles of the JDK, about 200 classes), andcommand(new X())in the command line ofCamelJBangMain, for which the JVM loads every command class to verify it. Nowcamel psloads 1,283 classes (CAMEL-27230: Upgrade to aesh 3.19.2 and skip its class path scan at start-up #30374: 1,415).String.concatcomment, andIllegalStateExceptionnamed in the upgrade guide.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):
camel versioncamel pscamel get routecamel catalog componentcamel init --helpcamel get --helpcamel run --helpcamel --helpTesting
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.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.KubernetesExportMetadataTest:kubernetes exporthas its own options and those ofExport. WithoutExportexcluded, it fails with the message ofCommandTree.version,ps,get --help,kubernetes export --help(--image-registryand--runtime),test initwith 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