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 18ef0e5 commit 35ca8cd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
18 changes: 15 additions & 3 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import eu.maveniverse.maven.toolbox.shared.ToolboxResolver;
import java.util.stream.Collectors;
import org.eclipse.aether.resolution.ArtifactDescriptorException;
import picocli.CommandLine;

/**
Expand All @@ -18,8 +21,8 @@
@CommandLine.Command(name = "resolve", description = "Resolves Maven Artifacts")
public final class Resolve extends ResolverCommandSupport {

@CommandLine.Parameters(index = "0", description = "The GAV to graph")
private String gav;
@CommandLine.Parameters(index = "0..*", description = "The GAV to graph", arity = "1")
private java.util.List<String> gav;

@CommandLine.Option(
names = {"--resolutionScope"},
Expand Down Expand Up @@ -52,9 +55,18 @@ public final class Resolve extends ResolverCommandSupport {
@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = getToolboxCommando(context);
ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver();
return toolboxCommando.resolve(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
gav.stream()
.map(g -> {
try {
return toolboxResolver.loadGav(g, boms);
} catch (ArtifactDescriptorException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList()),
sources,
javadoc,
signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class DirectorySink implements Consumer<Collection<Artifact>> {
*/
public static DirectorySink flat(Output output, Path path) throws IOException {
return new DirectorySink(
output, path, ArtifactMatcher.any(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false);
output, path, ArtifactMatcher.unique(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false);
}

private final Output output;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void accept(Collection<Artifact> artifacts) {
}

private void accept(Artifact artifact) throws IOException {
output.verbose("Artifact {} processed", artifact);
output.verbose("Accept artifact {}", artifact);
if (artifactMatcher.test(artifact)) {
output.verbose(" matched");
String name = artifactNameMapper.map(artifactMapper.map(artifact));
Expand All @@ -111,6 +111,8 @@ private void accept(Artifact artifact) throws IOException {
target,
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
} else {
output.verbose(" not matched");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ boolean copyAll(

boolean resolve(
ResolutionScope resolutionScope,
ResolutionRoot resolutionRoot,
Collection<ResolutionRoot> resolutionRoots,
boolean sources,
boolean javadoc,
boolean signatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ && matches(prototype.getExtension(), a.getExtension())
}

static ArtifactMatcher any() {
return a -> true;
return artifact("*");
}

static ArtifactMatcher unique() {
HashSet<Artifact> artifacts = new HashSet<>();
return artifacts::add;
return new ArtifactMatcher() {
@Override
public boolean test(Artifact artifact) {
return artifacts.add(artifact);
}
};
}

private static boolean isAny(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,48 +353,50 @@ public boolean recordStop(Output output) {
@Override
public boolean resolve(
ResolutionScope resolutionScope,
ResolutionRoot resolutionRoot,
Collection<ResolutionRoot> resolutionRoots,
boolean sources,
boolean javadoc,
boolean signatures,
Output output) {
try {
DependencyResult dependencyResult = toolboxResolver.resolve(
resolutionScope,
resolutionRoot.getArtifact(),
resolutionRoot.getDependencies(),
resolutionRoot.getManagedDependencies());
for (ResolutionRoot resolutionRoot : resolutionRoots) {
DependencyResult dependencyResult = toolboxResolver.resolve(
resolutionScope,
resolutionRoot.getArtifact(),
resolutionRoot.getDependencies(),
resolutionRoot.getManagedDependencies());

output.normal("");
if (output.isVerbose()) {
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
output.normal("");
if (output.isVerbose()) {
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
output.verbose(
"{} -> {}",
artifactResult.getArtifact(),
artifactResult.getArtifact().getFile());
}
}
output.normal("Resolved: {}", resolutionRoot.getArtifact());
if (output.isVerbose()) {
output.verbose(
"{} -> {}",
artifactResult.getArtifact(),
artifactResult.getArtifact().getFile());
" Transitive hull count: {}",
dependencyResult.getArtifactResults().size());
output.verbose(
" Transitive hull size: {}",
humanReadableByteCountBin(dependencyResult.getArtifactResults().stream()
.map(ArtifactResult::getArtifact)
.map(Artifact::getFile)
.filter(Objects::nonNull)
.map(f -> {
try {
return Files.size(f.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.summarizingLong(Long::longValue))
.getSum()));
}
}
output.normal("Resolved: {}", resolutionRoot.getArtifact());
if (output.isVerbose()) {
output.verbose(
" Transitive hull count: {}",
dependencyResult.getArtifactResults().size());
output.verbose(
" Transitive hull size: {}",
humanReadableByteCountBin(dependencyResult.getArtifactResults().stream()
.map(ArtifactResult::getArtifact)
.map(Artifact::getFile)
.filter(Objects::nonNull)
.map(f -> {
try {
return Files.size(f.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.summarizingLong(Long::longValue))
.getSum()));
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 35ca8cd

Please sign in to comment.