Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support transitive extensions when searching for plugins #43025

Merged
merged 1 commit into from
Sep 6, 2024
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 @@ -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
Loading