Skip to content

CAMEL-27045: camel-jbang - short commands no longer open every JAR of the class path - #30199

Merged
davsclaus merged 2 commits into
mainfrom
CAMEL-27045-cli-jar-scan
Nov 16, 2026
Merged

davsclaus merged 2 commits into
mainfrom
CAMEL-27045-cli-jar-scan

Conversation

@davsclaus

@davsclaus davsclaus commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

CAMEL-27045

The short commands of the Camel CLI (camel ps, version, get, log, stop) need classes from about 12 JARs, but on the distribution (341 JARs in lib/) they opened all of them. The JVM opens the JARs of the class path in order until it finds a class, so one class from a JAR far down opens every JAR before it. aesh's class path scan does the same; aesh is fixing that (aeshell/aesh#779 MetadataProviderRegistry.useOnly, aeshell/aesh#782 lazy JUL loggers). This PR fixes the Camel side, so the aesh fixes pay off when they are released.

Changes

  • Embedded plugins: CamelLauncherMain.PLUGINS used constructor references (GeneratePlugin::new), which load their class when the list is created. Every command loaded the 7 plugin classes, and through TestPlugin also Citrus and picocli (JARs at position 94-291). Now lambdas, which load a plugin only when it is created.
  • Version without the catalog: UpdateChecker (runs on every command of a web-installer install; the network check stays once a day) took the running version from DefaultCamelCatalog, whose JAR was at position 270. It now reads Implementation-Version from the launcher manifest, and falls back to the catalog when there is none. PluginHelper no longer keeps the catalog in a CamelCatalog local, which made the verifier load the interface.
  • No System.exit(0): since JDK 21, Runtime.exit logs through System.getLogger("java.lang.Runtime"), and the first System.Logger makes the JDK look up a LoggerFinder with ServiceLoader over the whole class path. An empty program on our class path: return from main 24 ms, System.exit(0) 75 ms. CamelJBangMain.quit(0) now returns when no other non-daemon thread runs (the JVM then ends with 0 and runs the shutdown hooks); other exit codes, or other non-daemon threads, still use System.exit.
  • No stty without a terminal: TerminalWidthHelper ran stty size (mode con on Windows) whenever COLUMNS is not exported (the usual case, shells keep it as a shell variable), also without a terminal, where it fails or sizes a terminal that the output does not go to. Starting a process costs tens of milliseconds, and from JDK 24 it also asks for a System.Logger (the same LoggerFinder lookup over every JAR). Without a terminal the width is now the default 120 right away, as the Javadoc already said; COLUMNS still wins. A table piped to another command (camel get | grep x) is now 120 wide instead of the width of the terminal.
  • JAR order: the launcher declares aesh, ascii-table, slf4j-api and camel-catalog before camel-jbang-core, so they are first on the Class-Path of the launcher JAR. Before: aesh at 73, camel-catalog at 270. The set of JARs and their versions is the same (checked). Of the 62 entries that are in more than one JAR, 5 now come from another JAR: LICENSE.txt, NOTICE.txt, jandex.idx, and the other.properties of camel-dataweave vs camel-core-catalog, which nothing in the CLI reads as a single resource.

Measured

JDK 25, macOS (Apple M4 Pro), no CDS, COLUMNS not set, output captured (as when an agent runs the CLI), median of 15 runs. "aesh fixes" = aesh master with useOnly plus a local lazy-JUL patch (aeshell/aesh#782), simulated.

command main this PR this PR + aesh fixes
camel ps 143 ms 140 ms 107 ms
camel version 149 ms 146 ms 114 ms
camel get 190 ms 185 ms 154 ms
camel doc timer 186 ms 173 ms 143 ms
camel catalog component --filter=kafka 419 ms 408 ms 396 ms

On its own this PR saves 3-13 ms: aesh 3.19.1 still scans the class path. With the aesh fixes, the short commands lose 35-43 ms. Once an aesh release has #779, the CLI also calls MetadataProviderRegistry.useOnly(new InternalCommandMetadataRegistry()) at start (follow-up).

Tests

  • CamelJBangMainQuitTest (new): the non-daemon thread check.
  • UpdateCheckerTest: the running version equals the catalog version.
  • TerminalWidthHelperTest: no terminal gives the default width, COLUMNS wins and then the terminal is not checked.
  • camel-jbang-core: 3102 run, 0 failures.
  • camel-launcher: 419 run, 0 failures, 47 skipped.
  • Distribution: ps, version, get route exit 0, nosuch exits 2; camel run --max-seconds=3 ends as before (3.8-4.0 s); -Xlog:class+load shows camel ps loading classes from 11 JARs.

Claude Code on behalf of davsclaus

🤖 Generated with Claude Code

https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS

… the class path

- The embedded plugins of the launcher are created by lambdas instead of
  constructor references, so a command no longer loads all the plugin
  classes (and Citrus and picocli through the test plugin).
- The update notice and the plugin checks no longer load CamelCatalog
  for the version: the launcher takes it from its manifest.
- quit(0) returns instead of calling System.exit when no other
  non-daemon thread runs: since JDK 21 System.exit asks for a
  System.Logger, and the JDK then looks for a LoggerFinder in every JAR.
- The launcher declares aesh, ascii-table, slf4j-api and camel-catalog
  first, so the JARs the short commands need are first on the class path
  of the distribution (same JARs, other order).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@davsclaus davsclaus added this to the 4.24.0 milestone Nov 16, 2026
@davsclaus davsclaus added dsl enhancement New feature or request labels Nov 16, 2026
…erminal

Without COLUMNS, the table width came from stty size (mode con on
Windows), also when there is no terminal, where it fails or sizes a
terminal the output does not go to. Starting the process costs tens of
milliseconds: from JDK 24 a process start asks for a System.Logger,
which makes the JDK look for a LoggerFinder in every JAR of the class
path. Without a terminal the width is now the default 120 right away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No issues found.

The four-pronged approach is well-measured and correctly justified:

  • Switching to lambdas in PLUGINS avoids eager class loading of plugin classes at list-creation time — constructor references resolve their target class immediately, lambdas do not.
  • Reading Implementation-Version from the manifest in UpdateChecker avoids instantiating DefaultCamelCatalog on every command invocation.
  • The quit(0) → return path correctly avoids System.exit's LoggerFinder lookup on JDK 21+ while preserving shutdown-hook execution and the right exit code.
  • JAR ordering puts the short-command dependencies first on the class path, minimising how many JARs the JVM opens before finding a class.

Tests are well-structured: CamelJBangMainQuitTest directly exercises hasOtherNonDaemonThread with daemon/non-daemon/unstarted thread cases, and runningVersionIsTheCatalogVersion validates the manifest-fallback path.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@oscerd oscerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice startup win, and the mechanism is the correct one.

The core move is switching the embedded plugin registry from constructor references (GeneratePlugin::new) to lazy lambdas (() -> new GeneratePlugin()). That matters because a constructor reference resolves and loads its class when the list is built, so every command loaded every plugin class, and the test plugin alone drags in Citrus and picocli, whose JARs sit far down the class path of the 341-JAR distribution. The JVM opens the class path JARs in order until it finds a class, so loading one from the bottom opens everything above it. With the lambda, the class is loaded only when a command actually selects that plugin by name through its Set.of(...) mapping, so a short command like camel ps touches none of them. The comment captures exactly that distinction, which is the easy thing to get wrong here.

The terminal-width change is the same spirit: when the output is not a terminal (!terminal.getAsBoolean()), it skips sizing a terminal the output does not go to, avoiding loading the terminal classes for a piped command. The test for the no-terminal path covers it.

Command dispatch still works because selection is by the name sets, and the lambda instantiates the right plugin on demand, so nothing that a command needs is excluded, only deferred. Good, well-reasoned optimization.

Claude Code on behalf of oscerd

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-launcher

🔁 1 test passed only after a retry on JDK 21 (1 retried attempt)

Recovered flaky tests on JDK 21 (1)
Module Test Failed attempts First failure
dsl/camel-jbang/camel-jbang-plugin-tui AiPanelAcpTest.retryResendsTheLastQuestionToTheAgent 1 expected: <2> but was: <1>

ℹ️ These tests did not fail the build. Surefire retried them and they passed.
Retries are enabled project-wide by surefire.rerunFailingTestsCount in parent/pom.xml.


🔬 Scalpel shadow comparison — Scalpel: 5 of 726 tested, 0 compile-only — current: 5 all tested

Maveniverse Scalpel detected 5 affected modules (current approach: 5).

Skip-tests mode would test 5 modules (2 direct + 0 downstream), skip tests for 0 (generated code, meta-modules)

Modules Scalpel would test (5)
  • camel-jbang-mcp ← depends on affected reactor module org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-mcp ← depends on affected reactor module org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← depends on affected reactor module org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-validate ← depends on affected reactor module org.apache.camel:camel-jbang-core
  • camel-launcher-container ← depends on affected reactor module org.apache.camel:camel-launcher

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 2 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core, dsl/camel-jbang/camel-launcher. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (14 modules, 2m 36s total)

Total reactor time: 2m 36s

Module Duration Status
Camel :: JBang :: Plugin :: TUI 45.9s SUCCESS
Camel :: JBang :: MCP 42.2s SUCCESS
Camel :: JBang :: Plugin :: Validate 23.9s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 12.1s SUCCESS
Camel :: JBang :: Plugin :: Testing 10.8s SUCCESS
Camel :: JBang :: Plugin :: Generate 7.6s SUCCESS
Camel :: Coverage 4.4s SUCCESS
Camel :: JBang :: Plugin :: MCP 3.3s SUCCESS
Camel :: JBang :: Plugin :: Edit 3.0s SUCCESS
Camel :: JBang :: Main 1.5s SUCCESS
Camel :: JBang :: Integration tests 1.0s SUCCESS
Camel :: Launcher :: Container 0.6s SUCCESS
Camel :: JBang :: Core n/a
Camel :: Launcher n/a

Top 20 slowest modules:

  • Camel :: JBang :: Plugin :: TUI (45.9s)
  • Camel :: JBang :: MCP (42.2s)
  • Camel :: JBang :: Plugin :: Validate (23.9s)
  • Camel :: JBang :: Plugin :: Kubernetes (12.1s)
  • Camel :: JBang :: Plugin :: Testing (10.8s)
  • Camel :: JBang :: Plugin :: Generate (7.6s)
  • Camel :: Coverage (4.4s)
  • Camel :: JBang :: Plugin :: MCP (3.3s)
  • Camel :: JBang :: Plugin :: Edit (3.0s)
  • Camel :: JBang :: Main (1.5s)
  • Camel :: JBang :: Integration tests (1.0s)
  • Camel :: Launcher :: Container (0.6s)

⚙️ View full build and test results

@davsclaus davsclaus self-assigned this Nov 16, 2026
@davsclaus
davsclaus merged commit 3f1138f into main Nov 16, 2026
13 checks passed
@davsclaus
davsclaus deleted the CAMEL-27045-cli-jar-scan branch November 16, 2026 16:02
davsclaus added a commit that referenced this pull request Nov 16, 2026
The embedded plugins are lambdas now (CAMEL-27045, #30199); the generate plugin stays out of the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dsl enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants