Skip to content

Commit

Permalink
Merge pull request quarkusio#43025 from iocanel/cli-transitives
Browse files Browse the repository at this point in the history
Support transitive extensions when searching for plugins
  • Loading branch information
iocanel committed Sep 6, 2024
2 parents fe706f2 + f012929 commit 441c98d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.GACTV;
import io.quarkus.registry.catalog.Extension;

public class PluginManagerUtil {

Expand Down Expand Up @@ -95,6 +100,29 @@ public String getName(Optional<GACTV> gactv, Optional<URL> url, Optional<Path> p
.orElseThrow(() -> new IllegalStateException("Could not determinate name for location."));
}

/**
* Collect all the transitive dependencies of the specified artifact.
*
* @param artifactKey the artifact key
* @param allExtensions all the extensions
* @return the set of transitive dependencies
*/
public static List<ArtifactKey> getTransitives(ArtifactKey artifactKey, Map<ArtifactKey, Extension> allExtensions) {
Extension extension = allExtensions.get(artifactKey);
Map<String, Object> metadata = extension.getMetadata();
List<ArtifactKey> result = new ArrayList<>();

if (metadata.get("extension-dependencies") instanceof List extensionDependencies) {
for (Object extensionDependency : extensionDependencies) {
if (extensionDependency instanceof String artifactCoords) {
ArtifactKey k = ArtifactKey.fromString(artifactCoords);
result.add(k);
}
}
}
return result;
}

private String stripCliSuffix(String s) {
Matcher m = CLI_SUFFIX.matcher(s);
if (m.find()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.quarkus.cli.plugin;

import static io.quarkus.cli.plugin.PluginManagerUtil.ALIAS_SEPARATOR;
import static io.quarkus.cli.plugin.PluginManagerUtil.getTransitives;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -173,11 +174,18 @@ public Map<String, Plugin> extensionPlugins() {
Map<String, Plugin> extensionPlugins = new HashMap<>();
projectRoot.map(r -> quarkusProject.get()).ifPresent(project -> {
try {
Set<ArtifactKey> installed = project.getExtensionManager().getInstalled().stream()
.map(ArtifactCoords::getKey).collect(Collectors.toSet());
for (Extension e : project.getExtensionsCatalog().getExtensions()) {
if (installed.contains(e.getArtifact().getKey())) {
for (String cliPlugin : ExtensionProcessor.getCliPlugins(e)) {
Map<ArtifactKey, Extension> allExtensions = new HashMap<>();
project.getExtensionsCatalog().getExtensions().forEach(e -> allExtensions.put(e.getArtifact().getKey(), e));

for (ArtifactCoords artifactCoords : project.getExtensionManager().getInstalled()) {
ArtifactKey artifactKey = artifactCoords.getKey();
List<ArtifactKey> allKeys = new ArrayList<>();
allKeys.add(artifactKey);
allKeys.addAll(getTransitives(artifactKey, allExtensions));

for (ArtifactKey key : allKeys) {
Extension extension = allExtensions.get(key);
for (String cliPlugin : ExtensionProcessor.getCliPlugins(extension)) {
Plugin plugin = cliPlugin.contains(ALIAS_SEPARATOR) ? util.fromAlias(cliPlugin)
: util.fromLocation(cliPlugin);
extensionPlugins.put(plugin.getName(), plugin);
Expand Down

0 comments on commit 441c98d

Please sign in to comment.