diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 9e397bf219ab0..186aaa4d41acf 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -9295,6 +9295,14 @@ could not start, such as with Docker down, was gone without a word. Now: The output of the service goes to `~/.camel/-run.log`, instead of a pipe that nobody read. `camel infra stop` removes it. +=== camel-launcher - the generate plugin installs on first use + +The Camel CLI launcher, as installed by the install script or a package manager such as Homebrew, no longer has the +generate plugin in it: the plugin and the OpenAPI generator it uses are about 24 MB, a fifth of the download. The first +`camel generate` downloads the plugin from Maven Central into the local Maven repository, and adds it to the plugin +configuration, as for `camel edit`. To have it on a machine that is offline later, run `camel generate --help` once +while it is online. + === camel-jbang - camel run loads one version of each library `camel run` downloads the JARs of each component when it is first used. It now keeps one version of each library: when diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc index b4726c4594797..eb89693b176d4 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc @@ -267,7 +267,9 @@ The plugins of the Apache Camel project: | edit | `camel edit`: edit a Camel file in the terminal with suggestions and diagnostics |=== -Plugins bundled with the CLI, such as `tui`, are installed on first use. +The plugins of the Apache Camel project are installed on first use: the first `camel tui` installs the tui plugin. +The Camel CLI launcher, as installed by the install script or a package manager such as Homebrew, has kubernetes, test, +validate, tui and mcp in it, and downloads generate and edit from Maven Central the first time they are used. Add, list installed, and remove plugins: diff --git a/dsl/camel-jbang/camel-launcher/pom.xml b/dsl/camel-jbang/camel-launcher/pom.xml index 53d57d5111430..00d9327ca77be 100644 --- a/dsl/camel-jbang/camel-launcher/pom.xml +++ b/dsl/camel-jbang/camel-launcher/pom.xml @@ -67,13 +67,10 @@ org.commonmark @@ -124,12 +121,8 @@ - - - org.apache.camel - camel-jbang-plugin-generate - ${project.version} - + org.apache.camel camel-jbang-plugin-test diff --git a/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMain.java b/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMain.java index cac15903e344a..7e05d9bf9e24a 100644 --- a/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMain.java +++ b/dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMain.java @@ -25,7 +25,6 @@ import java.util.function.Supplier; import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; -import org.apache.camel.dsl.jbang.core.commands.generate.GeneratePlugin; import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesPlugin; import org.apache.camel.dsl.jbang.core.commands.mcp.McpPlugin; import org.apache.camel.dsl.jbang.core.commands.test.TestPlugin; @@ -46,12 +45,12 @@ public class CamelLauncherMain extends CamelJBangMain { private record EmbeddedPlugin(Supplier factory, Set commands) { } - // Lambdas, not constructor references (GeneratePlugin::new): a constructor reference loads its class when this list - // is created, so every command would load all the plugins (and the test plugin loads Citrus and picocli). Their + // Lambdas, not constructor references (KubernetesPlugin::new): a constructor reference loads its class when this + // list is created, so every command would load all the plugins (and the test plugin loads Citrus and picocli). Their // JARs are far down the class path of the distribution, and loading a class from there opens every JAR before it. + // Not the generate plugin, which camel generate installs on first use, as it is a fifth of the download. @SuppressWarnings("java:S1612") private static final List PLUGINS = List.of( - new EmbeddedPlugin(() -> new GeneratePlugin(), Set.of("generate")), new EmbeddedPlugin(() -> new KubernetesPlugin(), Set.of("kubernetes", "k8s")), // its jar was in the launcher, but camel mcp installed the plugin on first use, in the plugin configuration new EmbeddedPlugin(() -> new McpPlugin(), Set.of("mcp")), diff --git a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java index b071f45afc4ed..85aeec6c39651 100644 --- a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java +++ b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherTest.java @@ -25,13 +25,16 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.camel.dsl.jbang.core.common.CommandTree; +import org.apache.camel.dsl.jbang.core.common.PluginHelper; import org.apache.camel.dsl.jbang.run.common.Printer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -98,7 +101,6 @@ public void quit(int exitCode) { @Test public void aCommandOfAnEmbeddedPluginCreatesOnlyThatPlugin() { // creating all the commands of the CLI and the plugins costs more than half a second - assertEquals(Set.of("generate"), commandsOf("generate")); assertEquals(Set.of("kubernetes", "k8s"), commandsOf("k8s", "--help")); // embedded like the others, so camel mcp does not install it in the plugin configuration on first use assertEquals(Set.of("mcp"), commandsOf("mcp", "--help")); @@ -108,7 +110,17 @@ public void aCommandOfAnEmbeddedPluginCreatesOnlyThatPlugin() { @Test public void theHelpCreatesTheCommandsOfAllEmbeddedPlugins() { assertTrue(commandsOf("--help") - .containsAll(Set.of("version", "generate", "kubernetes", "mcp", "self-update", "tui", "validate", "test"))); + .containsAll(Set.of("version", "kubernetes", "mcp", "self-update", "tui", "validate", "test"))); + } + + @Test + public void theGeneratePluginIsNotEmbedded() { + // camel generate installs it on first use: it and the OpenAPI generator are a fifth of the download (CAMEL-27005) + assertFalse(commandsOf("--help").contains("generate")); + assertTrue(PluginHelper.isPluginCommand("generate"), "camel generate installs the plugin on first use"); + assertThrows(ClassNotFoundException.class, + () -> Class.forName("org.apache.camel.dsl.jbang.core.commands.generate.GeneratePlugin")); + assertThrows(ClassNotFoundException.class, () -> Class.forName("org.openapitools.codegen.DefaultGenerator")); } private static Set commandsOf(String... args) {