Skip to content

Commit 3ac9af1

Browse files
committed
WIP
1 parent 35ca8cd commit 3ac9af1

File tree

6 files changed

+156
-52
lines changed

6 files changed

+156
-52
lines changed

cli/src/main/java/eu/maveniverse/maven/toolbox/cli/CopyAll.java cli/src/main/java/eu/maveniverse/maven/toolbox/cli/CopyTransitive.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* Resolves transitively a given GAV and copies resulting artifacts to target.
2222
*/
2323
@CommandLine.Command(
24-
name = "copyAll",
24+
name = "copyTransitive",
2525
description = "Resolves Maven Artifact transitively and copies all of them to target")
26-
public final class CopyAll extends ResolverCommandSupport {
26+
public final class CopyTransitive extends ResolverCommandSupport {
2727
@CommandLine.Parameters(index = "0", description = "The target", arity = "1")
2828
private Path target;
2929

@@ -48,7 +48,7 @@ protected boolean doCall(Context context) throws Exception {
4848
Path targetPath = target.toAbsolutePath();
4949
ToolboxCommando toolboxCommando = getToolboxCommando(context);
5050
ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver();
51-
return toolboxCommando.copyAll(
51+
return toolboxCommando.copyTransitive(
5252
ResolutionScope.parse(resolutionScope),
5353
gav.stream()
5454
.map(g -> {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
subcommands = {
1919
Classpath.class,
2020
Copy.class,
21-
CopyAll.class,
21+
CopyTransitive.class,
2222
Deploy.class,
2323
DeployRecorded.class,
2424
Dump.class,
@@ -31,6 +31,7 @@
3131
Record.class,
3232
Repl.class,
3333
Resolve.class,
34+
ResolveTransitive.class,
3435
Search.class,
3536
Tree.class,
3637
Verify.class

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

+4-22
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,20 @@
88
package eu.maveniverse.maven.toolbox.cli;
99

1010
import eu.maveniverse.maven.mima.context.Context;
11-
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
1211
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
13-
import eu.maveniverse.maven.toolbox.shared.ToolboxResolver;
1412
import java.util.stream.Collectors;
15-
import org.eclipse.aether.resolution.ArtifactDescriptorException;
13+
import org.eclipse.aether.artifact.DefaultArtifact;
1614
import picocli.CommandLine;
1715

1816
/**
19-
* Resolves transitively given artifact.
17+
* Resolves given artifact.
2018
*/
2119
@CommandLine.Command(name = "resolve", description = "Resolves Maven Artifacts")
2220
public final class Resolve extends ResolverCommandSupport {
2321

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

27-
@CommandLine.Option(
28-
names = {"--resolutionScope"},
29-
defaultValue = "runtime",
30-
description = "Resolution scope to resolve (default main-runtime)")
31-
private String resolutionScope;
32-
3325
@CommandLine.Option(
3426
names = {"--boms"},
3527
defaultValue = "",
@@ -39,7 +31,7 @@ public final class Resolve extends ResolverCommandSupport {
3931

4032
@CommandLine.Option(
4133
names = {"--sources"},
42-
description = "Download sources JARs as well (best effort)")
34+
description = "Download source JARs as well (best effort)")
4335
private boolean sources;
4436

4537
@CommandLine.Option(
@@ -55,18 +47,8 @@ public final class Resolve extends ResolverCommandSupport {
5547
@Override
5648
protected boolean doCall(Context context) throws Exception {
5749
ToolboxCommando toolboxCommando = getToolboxCommando(context);
58-
ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver();
5950
return toolboxCommando.resolve(
60-
ResolutionScope.parse(resolutionScope),
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()),
51+
gav.stream().map(DefaultArtifact::new).collect(Collectors.toList()),
7052
sources,
7153
javadoc,
7254
signature,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2023-2024 Maveniverse Org.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*/
8+
package eu.maveniverse.maven.toolbox.cli;
9+
10+
import eu.maveniverse.maven.mima.context.Context;
11+
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
12+
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;
16+
import picocli.CommandLine;
17+
18+
/**
19+
* Resolves transitively given artifact.
20+
*/
21+
@CommandLine.Command(name = "resolveTransitive", description = "Resolves Maven Artifacts Transitively")
22+
public final class ResolveTransitive extends ResolverCommandSupport {
23+
24+
@CommandLine.Parameters(index = "0..*", description = "The GAV to graph", arity = "1")
25+
private java.util.List<String> gav;
26+
27+
@CommandLine.Option(
28+
names = {"--resolutionScope"},
29+
defaultValue = "runtime",
30+
description = "Resolution scope to resolve (default main-runtime)")
31+
private String resolutionScope;
32+
33+
@CommandLine.Option(
34+
names = {"--boms"},
35+
defaultValue = "",
36+
split = ",",
37+
description = "Comma separated list of BOMs to apply")
38+
private java.util.List<String> boms;
39+
40+
@CommandLine.Option(
41+
names = {"--sources"},
42+
description = "Download source JARs as well (best effort)")
43+
private boolean sources;
44+
45+
@CommandLine.Option(
46+
names = {"--javadoc"},
47+
description = "Download javadoc JARs as well (best effort)")
48+
private boolean javadoc;
49+
50+
@CommandLine.Option(
51+
names = {"--signature"},
52+
description = "Download signatures as well (best effort)")
53+
private boolean signature;
54+
55+
@Override
56+
protected boolean doCall(Context context) throws Exception {
57+
ToolboxCommando toolboxCommando = getToolboxCommando(context);
58+
ToolboxResolver toolboxResolver = toolboxCommando.toolboxResolver();
59+
return toolboxCommando.resolveTransitive(
60+
ResolutionScope.parse(resolutionScope),
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()),
70+
sources,
71+
javadoc,
72+
signature,
73+
output);
74+
}
75+
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void unset(Context context) {
7777

7878
boolean copy(Collection<Artifact> artifacts, Consumer<Collection<Artifact>> consumer, Output output);
7979

80-
boolean copyAll(
80+
boolean copyTransitive(
8181
ResolutionScope resolutionScope,
8282
Collection<ResolutionRoot> resolutionRoots,
8383
Consumer<Collection<Artifact>> consumer,
@@ -97,12 +97,14 @@ boolean copyAll(
9797

9898
boolean recordStop(Output output);
9999

100-
boolean resolve(
100+
boolean resolve(Collection<Artifact> artifacts, boolean sources, boolean javadoc, boolean signature, Output output);
101+
102+
boolean resolveTransitive(
101103
ResolutionScope resolutionScope,
102104
Collection<ResolutionRoot> resolutionRoots,
103105
boolean sources,
104106
boolean javadoc,
105-
boolean signatures,
107+
boolean signature,
106108
Output output);
107109

108110
boolean tree(ResolutionScope resolutionScope, ResolutionRoot resolutionRoot, boolean verbose, Output output);

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

+67-23
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.eclipse.aether.installation.InstallRequest;
6565
import org.eclipse.aether.installation.InstallationException;
6666
import org.eclipse.aether.repository.RemoteRepository;
67+
import org.eclipse.aether.resolution.ArtifactResolutionException;
6768
import org.eclipse.aether.resolution.ArtifactResult;
6869
import org.eclipse.aether.resolution.DependencyResult;
6970
import org.eclipse.aether.util.ChecksumUtils;
@@ -236,7 +237,7 @@ public boolean copy(Collection<Artifact> artifacts, Consumer<Collection<Artifact
236237
}
237238

238239
@Override
239-
public boolean copyAll(
240+
public boolean copyTransitive(
240241
ResolutionScope resolutionScope,
241242
Collection<ResolutionRoot> resolutionRoots,
242243
Consumer<Collection<Artifact>> consumer,
@@ -352,14 +353,51 @@ public boolean recordStop(Output output) {
352353

353354
@Override
354355
public boolean resolve(
356+
Collection<Artifact> artifacts, boolean sources, boolean javadoc, boolean signature, Output output) {
357+
try {
358+
output.verbose("Resolving {}", artifacts);
359+
toolboxResolver.resolveArtifacts(artifacts);
360+
if (sources || javadoc || signature) {
361+
HashSet<Artifact> subartifacts = new HashSet<>();
362+
artifacts.forEach(a -> {
363+
if (sources && a.getClassifier().isEmpty()) {
364+
subartifacts.add(new SubArtifact(a, "sources", "jar"));
365+
}
366+
if (javadoc && a.getClassifier().isEmpty()) {
367+
subartifacts.add(new SubArtifact(a, "javadoc", "jar"));
368+
}
369+
if (signature && !a.getExtension().endsWith(".asc")) {
370+
subartifacts.add(new SubArtifact(a, "*", "*.asc"));
371+
}
372+
});
373+
if (!subartifacts.isEmpty()) {
374+
output.verbose("Resolving (best effort) {}", subartifacts);
375+
try {
376+
toolboxResolver.resolveArtifacts(subartifacts);
377+
} catch (ArtifactResolutionException e) {
378+
// ignore, this is "best effort"
379+
}
380+
}
381+
}
382+
return true;
383+
} catch (Exception e) {
384+
throw new RuntimeException(e);
385+
}
386+
}
387+
388+
@Override
389+
public boolean resolveTransitive(
355390
ResolutionScope resolutionScope,
356391
Collection<ResolutionRoot> resolutionRoots,
357392
boolean sources,
358393
boolean javadoc,
359-
boolean signatures,
394+
boolean signature,
360395
Output output) {
361396
try {
397+
int totalArtifactCount = 0;
398+
long totalArtifactSize = 0;
362399
for (ResolutionRoot resolutionRoot : resolutionRoots) {
400+
output.verbose("Resolving {}", resolutionRoot.getArtifact());
363401
DependencyResult dependencyResult = toolboxResolver.resolve(
364402
resolutionScope,
365403
resolutionRoot.getArtifact(),
@@ -375,28 +413,34 @@ public boolean resolve(
375413
artifactResult.getArtifact().getFile());
376414
}
377415
}
378-
output.normal("Resolved: {}", resolutionRoot.getArtifact());
379-
if (output.isVerbose()) {
380-
output.verbose(
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()));
398-
}
416+
int artifactCount = dependencyResult.getArtifactResults().size();
417+
long artifactSize = dependencyResult.getArtifactResults().stream()
418+
.map(ArtifactResult::getArtifact)
419+
.map(Artifact::getFile)
420+
.filter(Objects::nonNull)
421+
.map(f -> {
422+
try {
423+
return Files.size(f.toPath());
424+
} catch (IOException e) {
425+
throw new RuntimeException(e);
426+
}
427+
})
428+
.collect(Collectors.summarizingLong(Long::longValue))
429+
.getSum();
430+
totalArtifactCount += artifactCount;
431+
totalArtifactSize += artifactSize;
432+
433+
output.normal(
434+
"Resolved: {} (count: {}, size: {})",
435+
resolutionRoot.getArtifact(),
436+
artifactCount,
437+
humanReadableByteCountBin(artifactSize));
399438
}
439+
output.normal(
440+
"Total resolved: {} (count: {}, size: {})",
441+
resolutionRoots.size(),
442+
totalArtifactCount,
443+
humanReadableByteCountBin(totalArtifactSize));
400444
return true;
401445
} catch (Exception e) {
402446
throw new RuntimeException(e);

0 commit comments

Comments
 (0)