This is an automated email from the ASF dual-hosted git repository. christophd pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit cd27bcbd2d3ab29437869629a35df8cda4cb3810 Author: Christoph Deppisch <[email protected]> AuthorDate: Tue Nov 17 08:20:27 2026 +0100 CAMEL-26852: Address review feedback Move citrus.jbang.version/citrus.camel.jbang.version system properties into withClassLoader() so all Citrus commands get them. Wrap ps, agent run and agent stop with TCCL handling. Fix e.getClass() to getName(), narrow TestInit catch to RuntimeException, import FQCNs. Adapt CitrusTestChecks to Citrus 5.2.0 schema changes (additionalProperties on TestActions, TestActionBuilder_Object_ replaced by TestActions ref). Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../jbang/core/commands/ai/CitrusTestChecks.java | 11 ++++----- .../camel-jbang-plugin-commands-metadata.json | 2 +- .../dsl/jbang/core/commands/test/TestAgent.java | 6 ++--- .../test/{TestAgent.java => TestAgentRun.java} | 25 +++++++------------- .../jbang/core/commands/test/TestAgentStart.java | 9 ++------ .../test/{TestAgent.java => TestAgentStop.java} | 25 +++++++------------- .../dsl/jbang/core/commands/test/TestInit.java | 5 ++-- .../test/{TestAgent.java => TestListTests.java} | 27 ++++++++-------------- .../dsl/jbang/core/commands/test/TestPlugin.java | 22 ++++++++++-------- .../dsl/jbang/core/commands/test/TestRun.java | 11 +++------ 10 files changed, 54 insertions(+), 89 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CitrusTestChecks.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CitrusTestChecks.java index 9209f0198478..5931f0938003 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CitrusTestChecks.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CitrusTestChecks.java @@ -296,7 +296,7 @@ public final class CitrusTestChecks { for (String name : actions) { List<List<String>> paths = new ArrayList<>(); refPaths(model.at("/definitions/TestActions/properties/" + name), new ArrayList<>(), - ref -> ref.startsWith(NESTED_ACTION), paths, 0); + ref -> ref.startsWith(NESTED_ACTION) || TEST_ACTIONS.equals(ref), paths, 0); if (!paths.isEmpty()) { nested.put(name, paths); } @@ -538,10 +538,6 @@ public final class CitrusTestChecks { if ("camel".equals(name)) { checkLogMessage(at); } - JsonNode action = tree.at(at); - if (nested && !action.isMissingNode()) { - describe(schema.action().validate(action), at); - } for (List<String> path : schema.nested().getOrDefault(name, List.of())) { forEachAction(keys.get(0).getValueNode(), path, 0, at + "/" + escape(name), (n, p) -> checkAction(n, p, true)); @@ -626,7 +622,10 @@ public final class CitrusTestChecks { Map<String, List<Error>> unknown = new LinkedHashMap<>(); for (Error e : errors) { if ("additionalProperties".equals(e.getKeyword()) && e.getProperty() != null) { - unknown.computeIfAbsent(prefix + location(e), k -> new ArrayList<>()).add(e); + String at = prefix + location(e); + if (!slots.contains(at)) { + unknown.computeIfAbsent(at, k -> new ArrayList<>()).add(e); + } } } for (Error e : errors) { diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/generated/resources/META-INF/camel-jbang-plugin-commands-metadata.json b/dsl/camel-jbang/camel-jbang-plugin-test/src/generated/resources/META-INF/camel-jbang-plugin-commands-metadata.json index b80c234a33b7..800c026bed78 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/generated/resources/META-INF/camel-jbang-plugin-commands-metadata.json +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/generated/resources/META-INF/camel-jbang-plugin-commands-metadata.json @@ -1,5 +1,5 @@ { "commands": [ - { "name": "test", "fullName": "test", "description": "Manage tests for Camel applications", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.test.TestCommand", "plugin": "test", "options": [ { "names": "-h,--help", "description": "Display this help and exit", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "agent", "fullName": "test agent", "description": "Manage Citrus agents", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.test.TestAgent", [...] + { "name": "test", "fullName": "test", "description": "Manage tests for Camel applications", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.test.TestCommand", "plugin": "test", "options": [ { "names": "-h,--help", "description": "Display this help and exit", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "agent", "fullName": "test agent", "description": "Manage Citrus agents", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.test.TestAgent", [...] ] } diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java index e48a68fe8e7d..4b3041a3da0e 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java @@ -23,8 +23,6 @@ import org.aesh.command.Command; import org.aesh.command.invocation.CommandInvocation; import org.citrusframework.jbang.cli.CitrusJBangMain; import org.citrusframework.jbang.cli.commands.Agent; -import org.citrusframework.jbang.cli.commands.AgentRun; -import org.citrusframework.jbang.cli.commands.AgentStop; /** * Overrides the Citrus {@link Agent} group command so that the {@code start} subcommand dispatches to @@ -42,7 +40,7 @@ public class TestAgent extends Agent { public List<Command<CommandInvocation>> getCommands() { return List.of( new TestAgentStart(getMain()), - new AgentRun(getMain()), - new AgentStop(getMain())); + new TestAgentRun(getMain()), + new TestAgentStop(getMain())); } } diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentRun.java similarity index 54% copy from dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java copy to dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentRun.java index e48a68fe8e7d..0c2a78fa9717 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentRun.java @@ -17,32 +17,23 @@ package org.apache.camel.dsl.jbang.core.commands.test; -import java.util.List; - -import org.aesh.command.Command; +import org.aesh.command.CommandException; +import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; import org.citrusframework.jbang.cli.CitrusJBangMain; -import org.citrusframework.jbang.cli.commands.Agent; import org.citrusframework.jbang.cli.commands.AgentRun; -import org.citrusframework.jbang.cli.commands.AgentStop; /** - * Overrides the Citrus {@link Agent} group command so that the {@code start} subcommand dispatches to - * {@link TestAgentStart} instead of the plain Citrus {@code AgentStart}. The Citrus {@code Agent} implements - * {@code GroupCommand} and its {@code getCommands()} returns plain Citrus command instances, which aesh uses for - * dispatch — bypassing subcommands registered via the Camel {@code CommandTree}. + * Adjusts the thread context class loader for the duration of the Citrus agent run command. */ -public class TestAgent extends Agent { +public class TestAgentRun extends AgentRun { - public TestAgent(CitrusJBangMain main) { - super(main); + public TestAgentRun(CitrusJBangMain citrus) { + super(citrus); } @Override - public List<Command<CommandInvocation>> getCommands() { - return List.of( - new TestAgentStart(getMain()), - new AgentRun(getMain()), - new AgentStop(getMain())); + public CommandResult execute(CommandInvocation invocation) throws CommandException, InterruptedException { + return TestPlugin.withClassLoader(super::execute, invocation); } } diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStart.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStart.java index 75bc553b515c..b030a45cbd04 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStart.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStart.java @@ -25,12 +25,7 @@ import org.citrusframework.jbang.cli.CitrusJBangMain; import org.citrusframework.jbang.cli.commands.AgentStart; /** - * Resolves citrus-agent artifacts into the plugin classloader before the Citrus agent start command runs. This avoids a - * classloader identity conflict in {@code ClassLoaderHelper.instantiateType()}: the Citrus {@code AgentStart} command - * dynamically resolves the citrus-agent module and wraps the TCCL in an {@code OpenURLClassLoader}. When the plugin - * runs inside Camel JBang, the {@code CitrusAgentConfiguration} class loaded by that wrapper can differ (by classloader - * identity) from the one on the plugin classloader, causing the constructor lookup to fail. Pre-loading the artifacts - * into the plugin classloader keeps everything on one classloader so the identity check passes. + * Adjusts the thread context class loader and configures logging for the duration of the Citrus agent start command. */ public class TestAgentStart extends AgentStart { @@ -45,7 +40,7 @@ public class TestAgentStart extends AgentStart { RuntimeUtil.configureLog("info", true, false, false, false, null, null); } catch (Exception e) { printer().printErr("Failed to configure logging for agent start command '%s': %s" - .formatted(e.getClass(), e.getMessage())); + .formatted(e.getClass().getName(), e.getMessage())); } return super.execute(inv); }, invocation); diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStop.java similarity index 54% copy from dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java copy to dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStop.java index e48a68fe8e7d..c7f59c01755b 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgentStop.java @@ -17,32 +17,23 @@ package org.apache.camel.dsl.jbang.core.commands.test; -import java.util.List; - -import org.aesh.command.Command; +import org.aesh.command.CommandException; +import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; import org.citrusframework.jbang.cli.CitrusJBangMain; -import org.citrusframework.jbang.cli.commands.Agent; -import org.citrusframework.jbang.cli.commands.AgentRun; import org.citrusframework.jbang.cli.commands.AgentStop; /** - * Overrides the Citrus {@link Agent} group command so that the {@code start} subcommand dispatches to - * {@link TestAgentStart} instead of the plain Citrus {@code AgentStart}. The Citrus {@code Agent} implements - * {@code GroupCommand} and its {@code getCommands()} returns plain Citrus command instances, which aesh uses for - * dispatch — bypassing subcommands registered via the Camel {@code CommandTree}. + * Adjusts the thread context class loader for the duration of the Citrus agent stop command. */ -public class TestAgent extends Agent { +public class TestAgentStop extends AgentStop { - public TestAgent(CitrusJBangMain main) { - super(main); + public TestAgentStop(CitrusJBangMain citrus) { + super(citrus); } @Override - public List<Command<CommandInvocation>> getCommands() { - return List.of( - new TestAgentStart(getMain()), - new AgentRun(getMain()), - new AgentStop(getMain())); + public CommandResult execute(CommandInvocation invocation) throws CommandException, InterruptedException { + return TestPlugin.withClassLoader(super::execute, invocation); } } diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestInit.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestInit.java index cea8a4e2779e..d5266a0e5cd1 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestInit.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestInit.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import org.aesh.command.CommandException; import org.aesh.command.CommandResult; import org.aesh.command.impl.internal.OptionType; import org.aesh.command.impl.internal.ProcessedCommand; @@ -74,7 +75,7 @@ public class TestInit extends Init implements CommandTree.ParsedCommandAware { @Override public CommandResult execute(CommandInvocation invocation) - throws org.aesh.command.CommandException, InterruptedException { + throws CommandException, InterruptedException { return TestPlugin.withClassLoader(inv -> { try { Path target = targetFile(); @@ -83,7 +84,7 @@ public class TestInit extends Init implements CommandTree.ParsedCommandAware { return CommandResult.FAILURE; } return super.execute(inv); - } catch (Exception e) { + } catch (RuntimeException e) { printer().println( "Error: Failed to initialize test: %s %s".formatted(e.getClass().getName(), e.getMessage())); return CommandResult.FAILURE; diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestListTests.java similarity index 51% copy from dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java copy to dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestListTests.java index e48a68fe8e7d..43aec7fd893d 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestAgent.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestListTests.java @@ -17,32 +17,23 @@ package org.apache.camel.dsl.jbang.core.commands.test; -import java.util.List; - -import org.aesh.command.Command; +import org.aesh.command.CommandException; +import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; import org.citrusframework.jbang.cli.CitrusJBangMain; -import org.citrusframework.jbang.cli.commands.Agent; -import org.citrusframework.jbang.cli.commands.AgentRun; -import org.citrusframework.jbang.cli.commands.AgentStop; +import org.citrusframework.jbang.cli.commands.ListTests; /** - * Overrides the Citrus {@link Agent} group command so that the {@code start} subcommand dispatches to - * {@link TestAgentStart} instead of the plain Citrus {@code AgentStart}. The Citrus {@code Agent} implements - * {@code GroupCommand} and its {@code getCommands()} returns plain Citrus command instances, which aesh uses for - * dispatch — bypassing subcommands registered via the Camel {@code CommandTree}. + * Adjusts the thread context class loader for the duration of the Citrus list tests command. */ -public class TestAgent extends Agent { +public class TestListTests extends ListTests { - public TestAgent(CitrusJBangMain main) { - super(main); + public TestListTests(CitrusJBangMain citrus) { + super(citrus); } @Override - public List<Command<CommandInvocation>> getCommands() { - return List.of( - new TestAgentStart(getMain()), - new AgentRun(getMain()), - new AgentStop(getMain())); + public CommandResult execute(CommandInvocation invocation) throws CommandException, InterruptedException { + return TestPlugin.withClassLoader(super::execute, invocation); } } diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java index 3f85e3ede814..50a781ecb078 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestPlugin.java @@ -19,18 +19,18 @@ package org.apache.camel.dsl.jbang.core.commands.test; import java.lang.reflect.Field; import java.util.Optional; +import org.aesh.command.CommandException; import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; +import org.apache.camel.catalog.VersionHelper; import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; import org.apache.camel.dsl.jbang.core.common.CamelJBangPlugin; import org.apache.camel.dsl.jbang.core.common.CommandTree; import org.apache.camel.dsl.jbang.core.common.Plugin; import org.apache.camel.dsl.jbang.run.common.PluginExporter; import org.apache.camel.dsl.jbang.run.common.Printer; +import org.citrusframework.CitrusVersion; import org.citrusframework.jbang.cli.CitrusJBangMain; -import org.citrusframework.jbang.cli.commands.AgentRun; -import org.citrusframework.jbang.cli.commands.AgentStop; -import org.citrusframework.jbang.cli.commands.ListTests; @CamelJBangPlugin(name = "camel-jbang-plugin-test", firstVersion = "4.14.0", appliesTo = { "export" }) public class TestPlugin implements Plugin { @@ -46,11 +46,11 @@ public class TestPlugin implements Plugin { .addSubcommand("init", new CommandTree(new TestInit(citrus))) .addSubcommand("inspect", new CommandTree(new TestInspect(citrus))) .addSubcommand("run", new CommandTree(new TestRun(citrus))) - .addSubcommand("ps", new CommandTree(new ListTests(citrus)), "ls") + .addSubcommand("ps", new CommandTree(new TestListTests(citrus)), "ls") .addSubcommand("agent", new CommandTree(new TestAgent(citrus)) .addSubcommand("start", new CommandTree(new TestAgentStart(citrus))) - .addSubcommand("run", new CommandTree(new AgentRun(citrus))) - .addSubcommand("stop", new CommandTree(new AgentStop(citrus))))); + .addSubcommand("run", new CommandTree(new TestAgentRun(citrus))) + .addSubcommand("stop", new CommandTree(new TestAgentStop(citrus))))); } @Override @@ -64,11 +64,15 @@ public class TestPlugin implements Plugin { /** * Executes a Citrus command with the plugin class loader set as the thread context class loader, restoring the - * original class loader afterward. In the Camel Launcher runtime the class loader is already correct. + * original class loader afterward. Also sets the Citrus and Camel version system properties that Citrus commands + * use for Maven artifact resolution. In the Camel Launcher runtime the class loader is already correct. */ static CommandResult withClassLoader( CitrusCommandAction action, CommandInvocation invocation) - throws org.aesh.command.CommandException, InterruptedException { + throws CommandException, InterruptedException { + System.setProperty("citrus.jbang.version", CitrusVersion.version()); + System.setProperty("citrus.camel.jbang.version", new VersionHelper().getVersion()); + if (!isCamelLauncherRuntime()) { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { @@ -91,7 +95,7 @@ public class TestPlugin implements Plugin { @FunctionalInterface interface CitrusCommandAction { CommandResult execute(CommandInvocation invocation) - throws org.aesh.command.CommandException, InterruptedException; + throws CommandException, InterruptedException; } /** diff --git a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java index 09596812c505..c1bbd5d8aff3 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java +++ b/dsl/camel-jbang/camel-jbang-plugin-test/src/main/java/org/apache/camel/dsl/jbang/core/commands/test/TestRun.java @@ -20,15 +20,13 @@ package org.apache.camel.dsl.jbang.core.commands.test; import org.aesh.command.CommandException; import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; -import org.apache.camel.catalog.VersionHelper; import org.apache.camel.dsl.jbang.run.common.RuntimeUtil; -import org.citrusframework.CitrusVersion; import org.citrusframework.jbang.cli.CitrusJBangMain; import org.citrusframework.jbang.cli.commands.Run; /** - * Sets the Camel JBang version and adjusts the thread context class loader for the duration of the Citrus test run so - * that Citrus can resolve its resources. + * Adjusts the thread context class loader and configures logging for the duration of the Citrus test run so that Citrus + * can resolve its resources. */ public class TestRun extends Run { @@ -38,9 +36,6 @@ public class TestRun extends Run { @Override public CommandResult execute(CommandInvocation invocation) throws CommandException, InterruptedException { - System.setProperty("citrus.jbang.version", CitrusVersion.version()); - System.setProperty("citrus.camel.jbang.version", new VersionHelper().getVersion()); - return TestPlugin.withClassLoader(inv -> { configureLogging(); return super.execute(inv); @@ -64,7 +59,7 @@ public class TestRun extends Run { } } catch (Exception e) { printer().printErr("Failed to configure logging for run command '%s': %s" - .formatted(e.getClass(), e.getMessage())); + .formatted(e.getClass().getName(), e.getMessage())); } } }
