Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ public final class PluginHelper {

/**
* Built-in top-level commands that consume plugins — either by accepting plugin-contributed sub-options (run,
* export) or by dispatching to plugin-provided commands (shell, cmd). Plugin discovery must still run for these
* even if the target name is registered as a built-in subcommand.
* export) or by dispatching to plugin-provided commands (shell). Plugin discovery must still run for these even if
* the target name is registered as a built-in subcommand. Not cmd: no plugin adds to it, and creating all commands
* and plugins for it made camel cmd take twice as long as the other commands.
*/
private static final Set<String> PLUGIN_CONSUMING_BUILTINS = Set.of("shell", "run", "export", "cmd");
private static final Set<String> PLUGIN_CONSUMING_BUILTINS = Set.of("shell", "run", "export");

// the plugins warned about by compatibilityCheck, to warn once
private static final Set<String> COMPATIBILITY_WARNED = ConcurrentHashMap.newKeySet();
Expand Down Expand Up @@ -146,8 +147,8 @@ static Path resolvePluginConfigPath(Path configPath, String envValue) {
/**
* Decides whether plugin discovery (classpath scan + JSON config + Maven resolution) is needed for the current
* invocation. Returns false when the target command is a built-in that does not consume plugins, skipping all
* plugin-related IO. Returns true for plugin-consuming built-ins (run/export/cmd/shell), for unknown commands
* (likely plugin-provided), and when no target is given (e.g. --help listing).
* plugin-related IO. Returns true for plugin-consuming built-ins (run/export/shell), for unknown commands (likely
* plugin-provided), and when no target is given (e.g. --help listing).
*
* @param commandLine the command line with all built-in subcommands already registered
* @param args the raw CLI args; only args[0] is inspected
Expand Down Expand Up @@ -182,7 +183,7 @@ public static boolean shouldDiscoverPlugins(CommandTree commandLine, String... a
* {@link #shouldDiscoverPlugins(CommandTree, String...)}).
*
* @param command the name of the command
* @return {@code true} for shell, run, export and cmd
* @return {@code true} for shell, run and export
*/
public static boolean isPluginConsumingCommand(String command) {
return PLUGIN_CONSUMING_BUILTINS.contains(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public void aCommandOfTheCliCreatesOnlyItself() {
assertTrue(CamelJBangMain.hasOnlyCommand(commandLine, "config", "list"));
}

@Test
public void cmdCreatesOnlyItself() {
// no plugin adds to cmd, so it needs neither the other commands nor the plugins
CommandTree commandLine = execute("cmd", "reset-stats", "--help");

assertEquals(Set.of("cmd"), commandLine.getSubcommands().keySet());
assertTrue(commandLine.getSubcommands().get("cmd").getSubcommands().containsKey("send"));
assertTrue(CamelJBangMain.hasOnlyCommand(commandLine, "cmd", "reset-stats", "--help"));
}

@Test
public void theHelpCreatesAllCommands() {
assertAllCommands(execute("--help"));
Expand Down Expand Up @@ -89,12 +99,14 @@ public void aCommandThatIsNotOfTheCliCreatesAllCommands() {

@Test
public void theCommandsThatUseTheOtherCommandsOrThePluginsCreateAllCommands() {
for (String command : List.of("shell", "completion", "run", "export", "cmd")) {
for (String command : List.of("shell", "completion", "run", "export")) {
assertNull(CamelJBangMain.onlyCommand(command, "--foo"), command);
}
assertNull(CamelJBangMain.onlyCommand("--verbose", "version"));
assertEquals("version", CamelJBangMain.onlyCommand("version", "get"));
assertEquals("version", CamelJBangMain.onlyCommand("version", "--help"));
// no plugin adds to cmd
assertEquals("cmd", CamelJBangMain.onlyCommand("cmd", "send", "--body=hello"));
assertNull(CamelJBangMain.onlyCommand("--help"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ public void testShouldDiscoverPlugins() {
// built-in non-plugin-consuming commands → short-circuit
assertFalse(PluginHelper.shouldDiscoverPlugins(cl, "version"));
assertFalse(PluginHelper.shouldDiscoverPlugins(cl, "get", "bean"));
assertFalse(PluginHelper.shouldDiscoverPlugins(cl, "cmd", "browse"));

// plugin-consuming built-ins → must load
assertTrue(PluginHelper.shouldDiscoverPlugins(cl, "run", "foo.yaml"));
assertTrue(PluginHelper.shouldDiscoverPlugins(cl, "export"));
assertTrue(PluginHelper.shouldDiscoverPlugins(cl, "shell"));
assertTrue(PluginHelper.shouldDiscoverPlugins(cl, "cmd", "browse"));

// unknown command (likely plugin-provided) → must load
assertTrue(PluginHelper.shouldDiscoverPlugins(cl, "kubernetes", "run"));
Expand Down
Loading