Skip to content

Commit 35ca8cd

Browse files
committed
WIP
1 parent 18ef0e5 commit 35ca8cd

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed

cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Resolve.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import eu.maveniverse.maven.mima.context.Context;
1111
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
1212
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
13+
import eu.maveniverse.maven.toolbox.shared.ToolboxResolver;
14+
import java.util.stream.Collectors;
15+
import org.eclipse.aether.resolution.ArtifactDescriptorException;
1316
import picocli.CommandLine;
1417

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

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

2427
@CommandLine.Option(
2528
names = {"--resolutionScope"},
@@ -52,9 +55,18 @@ public final class Resolve extends ResolverCommandSupport {
5255
@Override
5356
protected boolean doCall(Context context) throws Exception {
5457
ToolboxCommando toolboxCommando = getToolboxCommando(context);
58+
ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver();
5559
return toolboxCommando.resolve(
5660
ResolutionScope.parse(resolutionScope),
57-
toolboxCommando.toolboxResolver().loadGav(gav, boms),
61+
gav.stream()
62+
.map(g -> {
63+
try {
64+
return toolboxResolver.loadGav(g, boms);
65+
} catch (ArtifactDescriptorException e) {
66+
throw new RuntimeException(e);
67+
}
68+
})
69+
.collect(Collectors.toList()),
5870
sources,
5971
javadoc,
6072
signature,

shared/src/main/java/eu/maveniverse/maven/toolbox/shared/DirectorySink.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class DirectorySink implements Consumer<Collection<Artifact>> {
3535
*/
3636
public static DirectorySink flat(Output output, Path path) throws IOException {
3737
return new DirectorySink(
38-
output, path, ArtifactMatcher.any(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false);
38+
output, path, ArtifactMatcher.unique(), ArtifactMapper.identity(), ArtifactNameMapper.ACVE(), false);
3939
}
4040

4141
private final Output output;
@@ -96,7 +96,7 @@ public void accept(Collection<Artifact> artifacts) {
9696
}
9797

9898
private void accept(Artifact artifact) throws IOException {
99-
output.verbose("Artifact {} processed", artifact);
99+
output.verbose("Accept artifact {}", artifact);
100100
if (artifactMatcher.test(artifact)) {
101101
output.verbose(" matched");
102102
String name = artifactNameMapper.map(artifactMapper.map(artifact));
@@ -111,6 +111,8 @@ private void accept(Artifact artifact) throws IOException {
111111
target,
112112
StandardCopyOption.REPLACE_EXISTING,
113113
StandardCopyOption.COPY_ATTRIBUTES);
114+
} else {
115+
output.verbose(" not matched");
114116
}
115117
}
116118

shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ToolboxCommando.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ boolean copyAll(
9999

100100
boolean resolve(
101101
ResolutionScope resolutionScope,
102-
ResolutionRoot resolutionRoot,
102+
Collection<ResolutionRoot> resolutionRoots,
103103
boolean sources,
104104
boolean javadoc,
105105
boolean signatures,

shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcher.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ && matches(prototype.getExtension(), a.getExtension())
8181
}
8282

8383
static ArtifactMatcher any() {
84-
return a -> true;
84+
return artifact("*");
8585
}
8686

8787
static ArtifactMatcher unique() {
8888
HashSet<Artifact> artifacts = new HashSet<>();
89-
return artifacts::add;
89+
return new ArtifactMatcher() {
90+
@Override
91+
public boolean test(Artifact artifact) {
92+
return artifacts.add(artifact);
93+
}
94+
};
9095
}
9196

9297
private static boolean isAny(String str) {

shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java

+35-33
Original file line numberDiff line numberDiff line change
@@ -353,48 +353,50 @@ public boolean recordStop(Output output) {
353353
@Override
354354
public boolean resolve(
355355
ResolutionScope resolutionScope,
356-
ResolutionRoot resolutionRoot,
356+
Collection<ResolutionRoot> resolutionRoots,
357357
boolean sources,
358358
boolean javadoc,
359359
boolean signatures,
360360
Output output) {
361361
try {
362-
DependencyResult dependencyResult = toolboxResolver.resolve(
363-
resolutionScope,
364-
resolutionRoot.getArtifact(),
365-
resolutionRoot.getDependencies(),
366-
resolutionRoot.getManagedDependencies());
362+
for (ResolutionRoot resolutionRoot : resolutionRoots) {
363+
DependencyResult dependencyResult = toolboxResolver.resolve(
364+
resolutionScope,
365+
resolutionRoot.getArtifact(),
366+
resolutionRoot.getDependencies(),
367+
resolutionRoot.getManagedDependencies());
367368

368-
output.normal("");
369-
if (output.isVerbose()) {
370-
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
369+
output.normal("");
370+
if (output.isVerbose()) {
371+
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
372+
output.verbose(
373+
"{} -> {}",
374+
artifactResult.getArtifact(),
375+
artifactResult.getArtifact().getFile());
376+
}
377+
}
378+
output.normal("Resolved: {}", resolutionRoot.getArtifact());
379+
if (output.isVerbose()) {
371380
output.verbose(
372-
"{} -> {}",
373-
artifactResult.getArtifact(),
374-
artifactResult.getArtifact().getFile());
381+
" Transitive hull count: {}",
382+
dependencyResult.getArtifactResults().size());
383+
output.verbose(
384+
" Transitive hull size: {}",
385+
humanReadableByteCountBin(dependencyResult.getArtifactResults().stream()
386+
.map(ArtifactResult::getArtifact)
387+
.map(Artifact::getFile)
388+
.filter(Objects::nonNull)
389+
.map(f -> {
390+
try {
391+
return Files.size(f.toPath());
392+
} catch (IOException e) {
393+
throw new RuntimeException(e);
394+
}
395+
})
396+
.collect(Collectors.summarizingLong(Long::longValue))
397+
.getSum()));
375398
}
376399
}
377-
output.normal("Resolved: {}", resolutionRoot.getArtifact());
378-
if (output.isVerbose()) {
379-
output.verbose(
380-
" Transitive hull count: {}",
381-
dependencyResult.getArtifactResults().size());
382-
output.verbose(
383-
" Transitive hull size: {}",
384-
humanReadableByteCountBin(dependencyResult.getArtifactResults().stream()
385-
.map(ArtifactResult::getArtifact)
386-
.map(Artifact::getFile)
387-
.filter(Objects::nonNull)
388-
.map(f -> {
389-
try {
390-
return Files.size(f.toPath());
391-
} catch (IOException e) {
392-
throw new RuntimeException(e);
393-
}
394-
})
395-
.collect(Collectors.summarizingLong(Long::longValue))
396-
.getSum()));
397-
}
398400
return true;
399401
} catch (Exception e) {
400402
throw new RuntimeException(e);

0 commit comments

Comments
 (0)