Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2024
1 parent b31600b commit c53e885
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import picocli.CommandLine;

/**
* Resolves transitively a given GAV and outputs classpath path.
*/
@CommandLine.Command(name = "listRepositories", description = "Lists repositories used to resolve given GAV")
public final class ListRepositories extends ResolverCommandSupport {
@CommandLine.Parameters(index = "0", description = "The GAV to list repositories for")
private String gav;

@CommandLine.Option(
names = {"--resolutionScope"},
defaultValue = "runtime",
description = "Resolution scope to resolve (default main-runtime)")
private String resolutionScope;

@CommandLine.Option(
names = {"--boms"},
defaultValue = "",
split = ",",
description = "Comma separated list of BOMs to apply")
private java.util.List<String> boms;

@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
return toolboxCommando.listRepositories(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Identify.class,
Install.class,
List.class,
ListRepositories.class,
ListAvailablePlugins.class,
Search.class,
Record.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static void unset(Context context) {

boolean install(Collection<Artifact> artifacts, Output output);

boolean listRepositories(ResolutionScope resolutionScope, ResolutionRoot resolutionRoot, Output output);

boolean listAvailablePlugins(Collection<String> groupIds, Output output);

boolean resolve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand All @@ -45,6 +46,8 @@
import org.eclipse.aether.collection.CollectResult;
import org.eclipse.aether.deployment.DeployRequest;
import org.eclipse.aether.deployment.DeploymentException;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.DependencyVisitor;
import org.eclipse.aether.installation.InstallRequest;
import org.eclipse.aether.installation.InstallationException;
import org.eclipse.aether.repository.RemoteRepository;
Expand All @@ -54,6 +57,7 @@
import org.eclipse.aether.util.artifact.SubArtifact;
import org.eclipse.aether.util.graph.visitor.DependencyGraphDumper;
import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator;
import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.VersionConstraint;
Expand Down Expand Up @@ -153,6 +157,34 @@ public boolean install(Collection<Artifact> artifacts, Output output) {
}
}

@Override
public boolean listRepositories(ResolutionScope resolutionScope, ResolutionRoot resolutionRoot, Output output) {
try {
output.verbose("Loading root of: {}", resolutionRoot.getArtifact());
ResolutionRoot root = toolboxResolver.loadRoot(resolutionRoot);
output.verbose("Collecting graph of: {}", resolutionRoot.getArtifact());
CollectResult collectResult = toolboxResolver.collect(
resolutionScope, root.getArtifact(), root.getDependencies(), root.getManagedDependencies(), false);
HashSet<RemoteRepository> repositories = new HashSet<>();
collectResult.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {
@Override
public boolean visitEnter(DependencyNode node) {
repositories.addAll(node.getRepositories());
return true;
}

@Override
public boolean visitLeave(DependencyNode node) {
return true;
}
}));
repositories.forEach(r -> output.normal(r.toString()));
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public boolean listAvailablePlugins(Collection<String> groupIds, Output output) {
toolboxResolver.listAvailablePlugins(groupIds).forEach(p -> output.normal(p.toString()));
Expand Down Expand Up @@ -185,10 +217,10 @@ public boolean resolve(
}
output.normal("Resolved: {}", resolutionRoot.getArtifact());
if (output.isVerbose()) {
output.normal(
output.verbose(
" Transitive hull count: {}",
dependencyResult.getArtifactResults().size());
output.normal(
output.verbose(
" Transitive hull size: {}",
humanReadableByteCountBin(dependencyResult.getArtifactResults().stream()
.map(ArtifactResult::getArtifact)
Expand Down

0 comments on commit c53e885

Please sign in to comment.