diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/Plugin.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/Plugin.java index cbe81529772fb..00cce05c386ed 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/Plugin.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/Plugin.java @@ -80,6 +80,10 @@ public Optional getCatalogLocation() { return catalogLocation; } + public Plugin withName(String name) { + return new Plugin(name, type, location, description, catalogLocation, inUserCatalog); + } + public Plugin withDescription(Optional description) { return new Plugin(name, type, location, description, catalogLocation, inUserCatalog); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginManagerUtil.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginManagerUtil.java index 7e443ba21ddd8..8690e18156e8e 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginManagerUtil.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginManagerUtil.java @@ -10,6 +10,7 @@ public class PluginManagerUtil { + static final String ALIAS_SEPARATOR = ": "; private static final Pattern CLI_SUFFIX = Pattern.compile("(\\-cli)(@\\w+)?$"); private final PluginManagerSettings settings; @@ -32,7 +33,7 @@ public PluginManagerUtil(PluginManagerSettings settings) { * @param the location * @return the {@link Plugin} that corresponds to the location. */ - public Plugin from(String location) { + public Plugin fromLocation(String location) { Optional url = PluginUtil.checkUrl(location); Optional path = PluginUtil.checkPath(location); Optional gactv = PluginUtil.checkGACTV(location); @@ -41,6 +42,22 @@ public Plugin from(String location) { return new Plugin(name, type, Optional.of(location), Optional.empty()); } + /** + * Create a {@link Plugin} from the specified alias. + * + * @param alias (e.g. name: location) + * @return the {@link Plugin} that corresponds to the alias. + */ + public Plugin fromAlias(String alias) { + String name = null; + String location = alias; + if (alias.contains(ALIAS_SEPARATOR)) { + name = alias.substring(0, alias.indexOf(ALIAS_SEPARATOR)).trim(); + location = alias.substring(alias.indexOf(ALIAS_SEPARATOR) + 1).trim(); + } + return fromLocation(location).withName(name); + } + /** * Get the name that corresponds the the specified location. * The name is the filename (without the jar extension) of any of the specified gactv, url or path. diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginMangerState.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginMangerState.java index 3e5f0c2573491..9feccc033e1ce 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginMangerState.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginMangerState.java @@ -1,7 +1,8 @@ package io.quarkus.cli.plugin; +import static io.quarkus.cli.plugin.PluginManagerUtil.ALIAS_SEPARATOR; + import java.nio.file.Path; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -16,6 +17,7 @@ import io.quarkus.maven.dependency.ArtifactCoords; import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.platform.catalog.processor.ExtensionProcessor; +import io.quarkus.registry.catalog.Extension; class PluginMangerState { @@ -173,11 +175,15 @@ public Map extensionPlugins() { try { Set installed = project.getExtensionManager().getInstalled().stream() .map(ArtifactCoords::getKey).collect(Collectors.toSet()); - - extensionPlugins.putAll(project.getExtensionsCatalog().getExtensions().stream() - .filter(e -> installed.contains(e.getArtifact().getKey())) - .map(ExtensionProcessor::getCliPlugins).flatMap(Collection::stream).map(util::from) - .collect(Collectors.toMap(p -> p.getName(), p -> p.inProjectCatalog()))); + for (Extension e : project.getExtensionsCatalog().getExtensions()) { + if (installed.contains(e.getArtifact().getKey())) { + for (String cliPlugin : ExtensionProcessor.getCliPlugins(e)) { + Plugin plugin = cliPlugin.contains(ALIAS_SEPARATOR) ? util.fromAlias(cliPlugin) + : util.fromLocation(cliPlugin); + extensionPlugins.put(plugin.getName(), plugin); + } + } + } } catch (Exception ignore) { output.warn("Failed to read the extension catalog. Ignoring extension plugins."); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginUtil.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginUtil.java index e75b0df9c3447..40f5c3bab818a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginUtil.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/cli/plugin/PluginUtil.java @@ -5,6 +5,7 @@ import java.net.URL; import java.nio.file.InvalidPathException; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -136,7 +137,7 @@ public static Optional checkGACTV(Optional location) { */ public static Optional checkPath(String location) { try { - return Optional.of(Path.of(location)); + return Optional.of(Paths.get(location)); } catch (InvalidPathException | NullPointerException e) { return Optional.empty(); } diff --git a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/cli/plugin/PluginManagerUtilTest.java b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/cli/plugin/PluginManagerUtilTest.java index 6e62324e81e5f..7080e1b35669a 100644 --- a/independent-projects/tools/devtools-common/src/test/java/io/quarkus/cli/plugin/PluginManagerUtilTest.java +++ b/independent-projects/tools/devtools-common/src/test/java/io/quarkus/cli/plugin/PluginManagerUtilTest.java @@ -49,20 +49,41 @@ public void shouldGetNameFromLocation() { public void shouldGetPluginFromLocation() { PluginManagerUtil util = PluginManagerUtil.getUtil(); - Plugin p = util.from("http://shomehost/some/path/my.jar"); + Plugin p = util.fromLocation("http://shomehost/some/path/my.jar"); assertEquals("my", p.getName()); assertEquals(PluginType.jar, p.getType()); - p = util.from("/some/path/my.jar"); + p = util.fromLocation("/some/path/my.jar"); assertEquals("my", p.getName()); assertEquals(PluginType.jar, p.getType()); - p = util.from("my.group:my-artifact-cli:my.version"); + p = util.fromLocation("my.group:my-artifact-cli:my.version"); assertEquals("my-artifact", p.getName()); assertEquals(PluginType.maven, p.getType()); - p = util.from("quarkus-alias"); + p = util.fromLocation("quarkus-alias"); assertEquals("alias", p.getName()); assertEquals(PluginType.jbang, p.getType()); } + + @Test + public void shouldGetPluginFromAliasedLocation() { + PluginManagerUtil util = PluginManagerUtil.getUtil(); + + Plugin p = util.fromAlias("my-alias: http://shomehost/some/path/my.jar"); + assertEquals("my-alias", p.getName()); + assertEquals(PluginType.jar, p.getType()); + + p = util.fromAlias("my-alias: /some/path/my.jar"); + assertEquals("my-alias", p.getName()); + assertEquals(PluginType.jar, p.getType()); + + p = util.fromAlias("my-alias: my.group:my-artifact-cli:my.version"); + assertEquals("my-alias", p.getName()); + assertEquals(PluginType.maven, p.getType()); + + p = util.fromAlias("my-alias: quarkus-alias"); + assertEquals("my-alias", p.getName()); + assertEquals(PluginType.jbang, p.getType()); + } }