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 @@ -157,6 +157,12 @@ the matching `*_doc` tool. The default `limit` for `camel_catalog_components` an
`camel_catalog_dataformats` is also lowered from 50 to 20; pass an explicit `limit` to restore the
previous behaviour.

==== camel-jbang plugin commands

The `camel plugin get --all` option is deprecated. Use the new `camel plugin list` command instead,
which lists all available plugins (installed, bundled, and known 3rd party).
The `camel plugin get` command now only shows installed plugins.

==== camel-jbang plugins

Plugins are now loaded lazily. Built-in commands that do not consume plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AUTO-GENERATED by camel-package-maven-plugin - DO NOT EDIT THIS FILE
= camel plugin get

Display available plugins
Get installed plugins


== Usage
Expand All @@ -19,7 +19,6 @@ camel plugin get [options]
[cols="2,5,1,2",options="header"]
|===
| Option | Description | Default | Type
| `--all` | Display all available plugins | false | boolean
| `--repos` | Display maven repository column | false | boolean
| `-h,--help` | Display the help and sub-commands | | boolean
|===
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

// AUTO-GENERATED by camel-package-maven-plugin - DO NOT EDIT THIS FILE
= camel plugin list

List all available plugins


== Usage

[source,bash]
----
camel plugin list [options]
----



== Options

[cols="2,5,1,2",options="header"]
|===
| Option | Description | Default | Type
| `--repos` | Display maven repository column | false | boolean
| `-h,--help` | Display the help and sub-commands | | boolean
|===


Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ camel plugin [options]
| Subcommand | Description
| xref:jbang-commands/camel-jbang-plugin-add.adoc[add] | Add new plugin
| xref:jbang-commands/camel-jbang-plugin-delete.adoc[delete] | Removes a plugin
| xref:jbang-commands/camel-jbang-plugin-get.adoc[get] | Display available plugins
| xref:jbang-commands/camel-jbang-plugin-get.adoc[get] | Get installed plugins
| xref:jbang-commands/camel-jbang-plugin-list.adoc[list] | List all available plugins
|===


Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginCommand;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginDelete;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginGet;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginList;
import org.apache.camel.dsl.jbang.core.commands.process.*;
import org.apache.camel.dsl.jbang.core.commands.update.UpdateCommand;
import org.apache.camel.dsl.jbang.core.commands.update.UpdateList;
Expand Down Expand Up @@ -185,7 +186,8 @@ public void execute(String... args) {
.addSubcommand("plugin", new CommandLine(new PluginCommand(this))
.addSubcommand("add", new CommandLine(new PluginAdd(this)))
.addSubcommand("delete", new CommandLine(new PluginDelete(this)))
.addSubcommand("get", new CommandLine(new PluginGet(this))))
.addSubcommand("get", new CommandLine(new PluginGet(this)))
.addSubcommand("list", new CommandLine(new PluginList(this))))
.addSubcommand("ps", new CommandLine(new ListProcess(this)))
.addSubcommand("run", new CommandLine(new Run(this)))
.addSubcommand("sbom", new CommandLine(new SBOMGenerator(this)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import picocli.CommandLine;

@CommandLine.Command(name = "get",
description = "Display available plugins", sortOptions = false, showDefaultValues = true)
description = "Get installed plugins", sortOptions = false, showDefaultValues = true)
public class PluginGet extends PluginBaseCommand {

@CommandLine.Option(names = { "--all" }, defaultValue = "false", description = "Display all available plugins")
@Deprecated
@CommandLine.Option(names = { "--all" }, hidden = true, defaultValue = "false",
description = "DEPRECATED: use 'camel plugin list' instead")
public boolean all;

@CommandLine.Option(names = { "--repos" }, defaultValue = "false", description = "Display maven repository column")
Expand All @@ -46,6 +48,12 @@ public PluginGet(CamelJBangMain main) {

@Override
public Integer doCall() throws Exception {
if (all) {
PluginList delegate = new PluginList(getMain());
delegate.repos = this.repos;
return delegate.doCall();
}

List<Row> rows = new ArrayList<>();

JsonObject plugins = loadConfig().getMap("plugins");
Expand All @@ -64,50 +72,11 @@ public Integer doCall() throws Exception {
rows.add(new Row(name, command, dependency, description, repos, vendor));
});

printRows(rows);

if (all) {
rows.clear();
for (PluginType camelPlugin : PluginType.values()) {
if (plugins.get(camelPlugin.getName()) == null) {
String dependency = "org.apache.camel:camel-jbang-plugin-%s".formatted(camelPlugin.getCommand());
rows.add(new Row(
camelPlugin.getName(), camelPlugin.getCommand(), dependency,
camelPlugin.getDescription(), camelPlugin.getRepos(), camelPlugin.getVendor()));
}
}

if (!rows.isEmpty()) {
printer().println();
printer().println("Supported plugins:");
printer().println();

printRows(rows);
}

rows.clear();
List<JsonObject> knownPlugins = PluginHelper.loadKnownPlugins();
for (JsonObject kp : knownPlugins) {
String kpName = kp.getString("name");
if (plugins.get(kpName) == null && PluginType.findByName(kpName).isEmpty()) {
String dep = kp.getString("groupId") != null && kp.getString("artifactId") != null
? "%s:%s".formatted(kp.getString("groupId"), kp.getString("artifactId"))
: kp.getStringOrDefault("dependency", "");
rows.add(new Row(
kpName, kp.getString("command"), dep,
kp.getString("description"), kp.getString("repos"),
kp.getStringOrDefault("vendor", "Community")));
}
}

if (!rows.isEmpty()) {
printer().println();
printer().println("Known 3rd party plugins:");
printer().println();

printRows(rows);
}
if (!rows.isEmpty()) {
printer().println("Installed plugins:");
printer().println();
}
printRows(rows);

return 0;
}
Expand All @@ -119,7 +88,7 @@ private String resolveVendor(String name) {
.orElse("");
}

private void printRows(List<Row> rows) {
protected void printRows(List<Row> rows) {
if (!rows.isEmpty()) {
printer().println(AsciiTable.getTable(AsciiTable.NO_BORDERS, rows, Arrays.asList(
new Column().header("NAME").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT)
Expand All @@ -134,11 +103,11 @@ private void printRows(List<Row> rows) {
.dataAlign(HorizontalAlign.LEFT)
.with(r -> r.repos),
new Column().header("DESCRIPTION").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT)
.maxWidth(50, OverflowBehaviour.ELLIPSIS_RIGHT)
.maxWidth(80, OverflowBehaviour.ELLIPSIS_RIGHT)
.with(r -> r.description))));
}
}

private record Row(String name, String command, String dependency, String description, String repos, String vendor) {
record Row(String name, String command, String dependency, String description, String repos, String vendor) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.plugin;

import java.util.ArrayList;
import java.util.List;

import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.common.PluginHelper;
import org.apache.camel.dsl.jbang.core.common.PluginType;
import org.apache.camel.util.json.JsonObject;
import picocli.CommandLine;

@CommandLine.Command(name = "list",
description = "List all available plugins", sortOptions = false, showDefaultValues = true)
public class PluginList extends PluginGet {

public PluginList(CamelJBangMain main) {
super(main);
}

@Override
public Integer doCall() throws Exception {
super.doCall();

JsonObject plugins = loadConfig().getMap("plugins");

List<Row> rows = new ArrayList<>();
for (PluginType camelPlugin : PluginType.values()) {
if (plugins.get(camelPlugin.getName()) == null) {
String dependency = "org.apache.camel:camel-jbang-plugin-%s".formatted(camelPlugin.getCommand());
rows.add(new Row(
camelPlugin.getName(), camelPlugin.getCommand(), dependency,
camelPlugin.getDescription(), camelPlugin.getRepos(), camelPlugin.getVendor()));
}
}

if (!rows.isEmpty()) {
printer().println();
printer().println("Bundled plugins:");
printer().println();
printRows(rows);
}

rows.clear();
List<JsonObject> knownPlugins = PluginHelper.loadKnownPlugins();
for (JsonObject kp : knownPlugins) {
String kpName = kp.getString("name");
if (plugins.get(kpName) == null && PluginType.findByName(kpName).isEmpty()) {
String dep = kp.getString("groupId") != null && kp.getString("artifactId") != null
? "%s:%s".formatted(kp.getString("groupId"), kp.getString("artifactId"))
: kp.getStringOrDefault("dependency", "");
rows.add(new Row(
kpName, kp.getString("command"), dep,
kp.getString("description"), kp.getString("repos"),
kp.getStringOrDefault("vendor", "Community")));
}
}

if (!rows.isEmpty()) {
printer().println();
printer().println("Known 3rd party plugins:");
printer().println();
printRows(rows);
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ void testNotPluginMessageWhenErrorNotOnFirstArgument(StdErr err) {
CamelJBangMain.run(camelJBangMainNotExiting, "plugin", "secondInvalid");

String[] lines = err.capturedLines();
Assertions.assertEquals(3, lines.length, "3 lines for the error is expected but received " + lines.length);
Assertions.assertTrue(lines.length >= 3, "At least 3 lines for the error is expected but received " + lines.length);
Assertions.assertEquals("Unmatched argument at index 1: 'secondInvalid'", lines[0],
"First line mentioning unmatched argument");
Assertions.assertEquals("Usage: camel plugin [-h] [COMMAND]", lines[1], "Second line with usage");
Assertions.assertEquals("Try 'camel plugin --help' for more information.", lines[2],
Assertions.assertEquals("Usage: camel plugin [-h] [COMMAND]", lines[lines.length - 2],
"Second to last line with usage");
Assertions.assertEquals("Try 'camel plugin --help' for more information.", lines[lines.length - 1],
"Last line with what to try to get help");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,12 @@ public void shouldGetPlugin() throws Exception {
command.doCall();

List<String> output = printer.getLines();
Assertions.assertEquals(2, output.size());
Assertions.assertEquals(4, output.size());
Assertions.assertEquals("Installed plugins:", output.get(0));
Assertions.assertEquals("NAME COMMAND VENDOR DEPENDENCY DESCRIPTION",
output.get(0));
Assertions.assertEquals(
"kubernetes kubernetes ASF org.apache.camel:camel-jbang-plugin-kubernetes %s"
.formatted(PluginType.KUBERNETES.getDescription()),
output.get(1));
}

@Test
public void shouldGetDefaultPlugins() throws Exception {
PluginGet command = new PluginGet(new CamelJBangMain().withPrinter(printer));
command.all = true;
command.doCall();

List<String> output = printer.getLines();
Assertions.assertTrue(output.size() >= 10);
Assertions.assertEquals("Supported plugins:", output.get(0));
Assertions.assertEquals(
"NAME COMMAND VENDOR DEPENDENCY DESCRIPTION",
output.get(2));
Assertions.assertEquals(
"kubernetes kubernetes ASF org.apache.camel:camel-jbang-plugin-kubernetes %s"
"kubernetes kubernetes ASF org.apache.camel:camel-jbang-plugin-kubernetes %s"
.formatted(PluginType.KUBERNETES.getDescription()),
output.get(3));
}
Expand All @@ -97,71 +80,12 @@ public void shouldGenerateDependencyAndDescription() throws Exception {
command.doCall();

List<String> output = printer.getLines();
Assertions.assertEquals(2, output.size());
Assertions.assertEquals("NAME COMMAND VENDOR DEPENDENCY DESCRIPTION", output.get(0));
Assertions.assertEquals(4, output.size());
Assertions.assertEquals("Installed plugins:", output.get(0));
Assertions.assertEquals("NAME COMMAND VENDOR DEPENDENCY DESCRIPTION", output.get(2));
Assertions.assertEquals(
"foo foo org.apache.camel:camel-jbang-plugin-foo Plugin foo called with command foo",
output.get(1));
}

@Test
public void shouldGetAllPlugins() throws Exception {
JsonObject pluginConfig = PluginHelper.getOrCreatePluginConfig();
JsonObject plugins = pluginConfig.getMap("plugins");

JsonObject fooPlugin = new JsonObject();
fooPlugin.put("name", "foo-plugin");
fooPlugin.put("command", "foo");
fooPlugin.put("dependency", "org.apache.camel:foo-plugin:1.0.0");
plugins.put("foo-plugin", fooPlugin);

PluginHelper.savePluginConfig(pluginConfig);

PluginGet command = new PluginGet(new CamelJBangMain().withPrinter(printer));
command.all = true;
command.doCall();

List<String> output = printer.getLines();
Assertions.assertTrue(output.size() >= 13);
Assertions.assertEquals("NAME COMMAND VENDOR DEPENDENCY DESCRIPTION", output.get(0));
Assertions.assertEquals(
"foo-plugin foo org.apache.camel:foo-plugin:1.0.0 Plugin foo-plugin called with command foo",
output.get(1));

Assertions.assertEquals("Supported plugins:", output.get(3));
Assertions.assertEquals(
"NAME COMMAND VENDOR DEPENDENCY DESCRIPTION",
output.get(5));
Assertions.assertEquals(
"kubernetes kubernetes ASF org.apache.camel:camel-jbang-plugin-kubernetes %s"
.formatted(PluginType.KUBERNETES.getDescription()),
output.get(6));
Assertions.assertEquals(
"generate generate ASF org.apache.camel:camel-jbang-plugin-generate %s"
.formatted(PluginType.GENERATE.getDescription()),
output.get(7));
Assertions.assertEquals(
"edit edit ASF org.apache.camel:camel-jbang-plugin-edit %s"
.formatted(PluginType.EDIT.getDescription()),
output.get(8));
Assertions.assertEquals(
"test test ASF org.apache.camel:camel-jbang-plugin-test %s"
.formatted(PluginType.TEST.getDescription()),
output.get(9));
Assertions.assertEquals(
"route-parser route-parser ASF org.apache.camel:camel-jbang-plugin-route-parser %s"
.formatted(PluginType.ROUTE_PARSER.getDescription()),
output.get(10));
Assertions.assertEquals(
"validate validate ASF org.apache.camel:camel-jbang-plugin-validate %s"
.formatted(PluginType.VALIDATE.getDescription()),
output.get(11));
Assertions.assertEquals(
"tui tui ASF org.apache.camel:camel-jbang-plugin-tui %s"
.formatted(PluginType.TUI.getDescription()),
output.get(12));

Assertions.assertEquals("Known 3rd party plugins:", output.get(14));
output.get(3));
}

}
Loading