This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 6e8663490e4a CAMEL-23334: Fix lazy plugin loading to skip unnecessary
Maven resolution
6e8663490e4a is described below
commit 6e8663490e4a4c79014372bc16fbbcca9176da5c
Author: Croway <[email protected]>
AuthorDate: Wed May 6 13:21:44 2026 +0200
CAMEL-23334: Fix lazy plugin loading to skip unnecessary Maven resolution
PluginHelper.addPlugins() was downloading ALL configured plugins before
filtering by the target command. This caused expensive Maven resolution
(e.g. 3.7s for 453 transitive dependencies) on every CLI invocation,
even for commands like "camel version" that don't use any plugin.
Move the command-name filter into getActivePlugins() so it runs before
getPlugin()/downloadPlugin(), skipping resolution entirely for plugins
that don't match the current command.
---
.../camel/dsl/jbang/core/common/PluginHelper.java | 30 ++++++++---
.../dsl/jbang/core/common/PluginHelperTest.java | 59 ++++++++++++++++++++++
2 files changed, 82 insertions(+), 7 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
index 0a1fa6544965..a55c7a87ff39 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java
@@ -117,14 +117,11 @@ public final class PluginHelper {
}
}
- // Fall back to JSON configuration for additional or missing plugins
- Map<String, Plugin> plugins = getActivePlugins(main, repos);
+ // Fall back to JSON configuration for additional or missing plugins.
+ // Pass target so only matching plugins are downloaded — avoids
expensive
+ // Maven resolution for plugins unrelated to the current command.
+ Map<String, Plugin> plugins = getActivePlugins(main, repos, target);
for (Map.Entry<String, Plugin> plugin : plugins.entrySet()) {
- // only load the plugin if the command-line is calling this plugin
- if (target != null && !"shell".equals(target) &&
!target.equals(plugin.getKey())) {
- continue;
- }
-
// Skip if this plugin was already loaded from embedded plugins
if (foundEmbeddedPlugins &&
commandLine.getSubcommands().containsKey(plugin.getKey())) {
continue;
@@ -143,6 +140,20 @@ public final class PluginHelper {
* @return map of plugins where key represents the plugin command
and value the plugin instance.
*/
public static Map<String, Plugin> getActivePlugins(CamelJBangMain main,
String repos) {
+ return getActivePlugins(main, repos, null);
+ }
+
+ /**
+ * Gets the active plugins according to the local plugin configuration
file, optionally filtered by target command.
+ * When a target command is specified (and is not "shell"), only the
plugin matching that command is downloaded and
+ * instantiated — other plugins are skipped entirely, avoiding expensive
Maven resolution.
+ *
+ * @param main to exit the CLI process in case of error
+ * @param repos custom maven repositories
+ * @param target the target command name to filter by, or null to load
all plugins
+ * @return map of plugins where key represents the plugin command
and value the plugin instance.
+ */
+ public static Map<String, Plugin> getActivePlugins(CamelJBangMain main,
String repos, String target) {
Map<String, Plugin> activePlugins = new HashMap<>();
JsonObject config = getPluginConfig();
if (config != null) {
@@ -158,6 +169,11 @@ public final class PluginHelper {
final String firstVersion =
properties.getOrDefault("firstVersion", "").toString();
final String gav = properties.getOrDefault("dependency",
"").toString();
+ // skip plugins that don't match the target command to avoid
unnecessary downloads
+ if (target != null && !"shell".equals(target) &&
!target.equals(command)) {
+ continue;
+ }
+
// check if plugin version can be loaded (cannot if we use an
older camel version than the plugin)
if (!version.isBlank() && !firstVersion.isBlank()) {
versionCheck(main, version, firstVersion, command);
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
index 1efc607f078c..0a1b9db38ff9 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/PluginHelperTest.java
@@ -19,14 +19,18 @@ package org.apache.camel.dsl.jbang.core.common;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
+import java.util.Map;
+import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.util.json.JsonObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class PluginHelperTest {
@@ -72,4 +76,59 @@ public class PluginHelperTest {
JsonObject userPlugin = plugins.getMap("user-plugin");
assertNotNull(userPlugin);
}
+
+ @Test
+ public void testGetActivePluginsFiltersByTarget() throws Exception {
+ Path userConfig =
CommandLineHelper.getHomeDir().resolve(PluginHelper.PLUGIN_CONFIG);
+ String configContent = """
+ {
+ "plugins": {
+ "forage": {
+ "name": "forage",
+ "command": "forage",
+ "description": "Forage plugin",
+ "firstVersion": "4.18.0"
+ },
+ "test": {
+ "name": "test",
+ "command": "test",
+ "description": "Test plugin",
+ "firstVersion": "4.14.0"
+ }
+ }
+ }
+ """;
+ Files.writeString(userConfig, configContent,
StandardOpenOption.CREATE);
+
+ CamelJBangMain main = new CamelJBangMain();
+
+ // target "version" should not match any plugin — returns empty
without downloading
+ Map<String, Plugin> plugins = PluginHelper.getActivePlugins(main,
null, "version");
+ assertTrue(plugins.isEmpty());
+ }
+
+ @Test
+ public void testGetActivePluginsNoFilterLoadsAll() throws Exception {
+ Path userConfig =
CommandLineHelper.getHomeDir().resolve(PluginHelper.PLUGIN_CONFIG);
+ String configContent = """
+ {
+ "plugins": {
+ "test": {
+ "name": "test",
+ "command": "test",
+ "description": "Test plugin",
+ "firstVersion": "4.14.0"
+ }
+ }
+ }
+ """;
+ Files.writeString(userConfig, configContent,
StandardOpenOption.CREATE);
+
+ // null target should attempt to load all plugins (will fail to
download in test,
+ // but the important thing is the filter logic doesn't skip it)
+ JsonObject config = PluginHelper.getPluginConfig();
+ assertNotNull(config);
+ JsonObject pluginsConfig = config.getMap("plugins");
+ assertEquals(1, pluginsConfig.size());
+ }
}