This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 9da94571393a CAMEL-26933: camel-launcher - camel export from the
launcher exports the Citrus tests (#29920)
9da94571393a is described below
commit 9da94571393af2216def39ccd83286e6400bb433
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 19:24:59 2026 +0100
CAMEL-26933: camel-launcher - camel export from the launcher exports the
Citrus tests (#29920)
The export took its exporters from the plugin configuration only, and the
launcher
embeds the test plugin without registering it there, so camel export from
the
launcher never had the Citrus tests (src/test was missing), unlike after
camel
plugin add test.
CamelJBangMain.getEmbeddedPlugins(target) gives the plugins built into the
CLI that
contribute to a command: the launcher returns its embedded plugins whose
PluginType
lists the command (the test plugin for export). CliExportContext adds them
to the
plugins of the configuration, unless the configuration has the same plugin.
CAMEL-26933: camel-jbang - getEmbeddedPlugins after postAddCommands, which
keeps its Javadoc
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../dsl/jbang/core/commands/CamelJBangMain.java | 13 ++++
.../dsl/jbang/core/commands/CliExportContext.java | 11 +++-
.../CliExportContextEmbeddedPluginsTest.java | 77 ++++++++++++++++++++++
.../dsl/jbang/launcher/CamelLauncherMain.java | 24 +++++++
.../CamelLauncherMainEmbeddedPluginsTest.java | 45 +++++++++++++
5 files changed, 169 insertions(+), 1 deletion(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index ebeaa0e54ad0..16b1e577be84 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -17,6 +17,7 @@
package org.apache.camel.dsl.jbang.core.commands;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -583,6 +584,18 @@ public class CamelJBangMain implements
Command<CommandInvocation> {
// noop
}
+ /**
+ * The plugins that this CLI has built in (the Camel launcher embeds
some), and that contribute to the given
+ * command, such as the test plugin, whose exporter adds the Citrus tests
to camel export. The plugins of the plugin
+ * configuration are not among them.
+ *
+ * @param target the command, such as run or export
+ * @return the plugins, none by default
+ */
+ public Collection<Plugin> getEmbeddedPlugins(String target) {
+ return List.of();
+ }
+
/**
* Called just before the command line is executed
*/
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CliExportContext.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CliExportContext.java
index e435bc9ee639..ba46041bd8d7 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CliExportContext.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CliExportContext.java
@@ -17,6 +17,8 @@
package org.apache.camel.dsl.jbang.core.commands;
import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Optional;
import org.apache.camel.dsl.jbang.core.commands.ai.YamlLoadFailureReport;
@@ -59,7 +61,14 @@ public final class CliExportContext {
T context, CamelJBangMain main, Printer printer, boolean yes,
String target) {
context.withPrinter(printer)
.withPlugins(repos -> {
- Collection<Plugin> plugins =
PluginHelper.getActivePlugins(main, repos, target, true).values();
+ Map<String, Plugin> active = new
LinkedHashMap<>(PluginHelper.getActivePlugins(main, repos, target, true));
+ // and the plugins built into the CLI, unless the plugin
configuration has the same plugin
+ for (Plugin embedded : main.getEmbeddedPlugins(target)) {
+ if (active.values().stream().noneMatch(p ->
p.getClass().equals(embedded.getClass()))) {
+ active.put(embedded.getClass().getName(),
embedded);
+ }
+ }
+ Collection<Plugin> plugins = active.values();
return new ExportContext.ActivePlugins(
plugins.stream().map(Plugin::getRunCustomizer).flatMap(Optional::stream).toList(),
plugins.stream().map(Plugin::getExporter).flatMap(Optional::stream).toList());
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/CliExportContextEmbeddedPluginsTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/CliExportContextEmbeddedPluginsTest.java
new file mode 100644
index 000000000000..6b816bb4de2b
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/CliExportContextEmbeddedPluginsTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+
+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.apache.camel.dsl.jbang.run.export.ExportContext;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The plugins built into the CLI take part in camel export: the Camel
launcher embeds the test plugin without a plugin
+ * configuration, so an export from the launcher had no Citrus tests
(CAMEL-26933).
+ */
+class CliExportContextEmbeddedPluginsTest extends CamelCommandBaseTestSupport {
+
+ @Test
+ void theExportHasTheExporterOfAnEmbeddedPlugin() throws Exception {
+ useTestHomeDir();
+ ExporterPlugin plugin = new ExporterPlugin();
+ CamelJBangMain main = new CamelJBangMain() {
+ @Override
+ public Collection<Plugin> getEmbeddedPlugins(String target) {
+ return "export".equals(target) ? List.of(plugin) : List.of();
+ }
+ }.withPrinter(printer);
+
+ ExportContext.ActivePlugins plugins = CliExportContext.create(main,
printer, true).getPlugins(null);
+
+ assertThat(plugins.exporters()).containsExactly(plugin.exporter);
+ }
+
+ @Test
+ void withoutEmbeddedPluginsTheExportHasThePluginsOfTheConfiguration()
throws Exception {
+ useTestHomeDir();
+ CamelJBangMain main = new CamelJBangMain().withPrinter(printer);
+
+ assertThat(CliExportContext.create(main, printer,
true).getPlugins(null).exporters()).isEmpty();
+ }
+
+ private static class ExporterPlugin implements Plugin {
+
+ final PluginExporter exporter = (Path buildDir, String packageName,
Printer printer) -> {
+ };
+
+ @Override
+ public void customize(CommandTree commandLine, CamelJBangMain main) {
+ }
+
+ @Override
+ public Optional<PluginExporter> getExporter() {
+ return Optional.of(exporter);
+ }
+ }
+}
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 1d64f30257d2..0fa63e81069d 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
@@ -16,7 +16,11 @@
*/
package org.apache.camel.dsl.jbang.launcher;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
@@ -28,6 +32,7 @@ import org.apache.camel.dsl.jbang.core.commands.tui.TuiPlugin;
import org.apache.camel.dsl.jbang.core.commands.validate.ValidatePlugin;
import org.apache.camel.dsl.jbang.core.common.CommandTree;
import org.apache.camel.dsl.jbang.core.common.Plugin;
+import org.apache.camel.dsl.jbang.core.common.PluginType;
import org.apache.camel.dsl.jbang.launcher.selfupdate.SelfUpdatePlugin;
import org.apache.camel.dsl.jbang.launcher.selfupdate.UpdateChecker;
@@ -64,6 +69,25 @@ public class CamelLauncherMain extends CamelJBangMain {
return PLUGINS.stream().anyMatch(p -> p.commands().contains(command))
|| super.isPluginCommand(command);
}
+ @Override
+ public Collection<Plugin> getEmbeddedPlugins(String target) {
+ // such as the test plugin for camel export: the launcher does not
register its plugins in the plugin
+ // configuration, so the export did not have the Citrus tests
(CAMEL-26933)
+ List<Plugin> answer = new ArrayList<>();
+ for (EmbeddedPlugin embedded : PLUGINS) {
+ boolean contributes = embedded.commands().stream()
+ .map(PluginType::findByName)
+ .flatMap(Optional::stream)
+ .anyMatch(type ->
Arrays.asList(type.getAppliesTo()).contains(target));
+ if (contributes) {
+ Plugin plugin = embedded.factory().get();
+ plugin.setClassLoader(getClass().getClassLoader());
+ answer.add(plugin);
+ }
+ }
+ return answer;
+ }
+
@Override
public void postAddCommands(CommandTree commandLine, String[] args) {
if (hasOnlyCommand(commandLine, args)) {
diff --git
a/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMainEmbeddedPluginsTest.java
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMainEmbeddedPluginsTest.java
new file mode 100644
index 000000000000..ed04a7f2182f
--- /dev/null
+++
b/dsl/camel-jbang/camel-launcher/src/test/java/org/apache/camel/dsl/jbang/launcher/CamelLauncherMainEmbeddedPluginsTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.launcher;
+
+import org.apache.camel.dsl.jbang.core.commands.test.TestPlugin;
+import org.apache.camel.dsl.jbang.core.common.Plugin;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * camel export from the launcher has the Citrus tests: the embedded test
plugin contributes its exporter (CAMEL-26933).
+ */
+class CamelLauncherMainEmbeddedPluginsTest {
+
+ @Test
+ void theTestPluginContributesToExport() {
+ assertThat(new CamelLauncherMain().getEmbeddedPlugins("export"))
+ .hasSize(1)
+ .allSatisfy(plugin -> {
+ assertThat(plugin).isInstanceOf(TestPlugin.class);
+ assertThat(plugin.getExporter()).isPresent();
+ });
+ }
+
+ @Test
+ void noEmbeddedPluginContributesToRun() {
+ assertThat(new
CamelLauncherMain().getEmbeddedPlugins("run")).extracting(Plugin::getClass)
+ .doesNotContain(TestPlugin.class.asSubclass(Plugin.class));
+ }
+}