Skip to content

Commit 71a4d6d

Browse files
authored
Add POMs to resolve/resolve-transitive (#325)
Add POMs to resolve/resolve-transitive Fixes #321
1 parent a0cb56b commit 71a4d6d

File tree

10 files changed

+98
-6
lines changed

10 files changed

+98
-6
lines changed

it/toolbox-cli-its/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<script>${itDir}/identify-1/it.groovy</script>
9696
<script>${itDir}/identify-2/it.groovy</script>
9797
<script>${itDir}/noarg-1/it.groovy</script>
98+
<script>${itDir}/resolve-1/it.groovy</script>
9899
<!-- fails often, relies heavily on search-api CSC backend -->
99100
<!--script>${itDir}/libyear-1/it.groovy</script-->
100101
</scripts>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
9+
StringBuilder out = new StringBuilder()
10+
StringBuilder err = new StringBuilder()
11+
String[] args = ["${java}", '-jar', "${cli}", "-e", "resolve", "junit:junit:4.13.2", "--poms"]
12+
13+
ProcessBuilder proc = new ProcessBuilder(args)
14+
Process process = proc.start()
15+
process.consumeProcessOutput(out, err)
16+
process.waitFor()
17+
18+
// this is junit:junit:pom:4.13.2 sha-512 hash:
19+
assert out.contains("SHA-512: abf1cf90ab6a525ae0cfa5235563b00bc6ef07c59f8cdd5c5495ea8b14941b5803a3f7adffaa36ec37152a7904a10e04939c0d11b48115f1943a1606cc5066c0")
20+
// this is junit:junit:jar:4.13.2 sha-512 hash:
21+
assert out.contains("SHA-512: a31b9950f929a7e5a600d89787ef40e42a8a8e2392e210d0c0f45b3572937670a18a524f1815508cd1152cd1eaa7275cb7430ba45c053be365c83c231bccd3f0")

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ public RecordStats(boolean active, int recordedCount) {
353353
* Resolves given artifacts.
354354
*/
355355
Result<List<Artifact>> resolve(
356-
Source<Artifact> artifacts, boolean sources, boolean javadoc, boolean signature, Sink<Artifact> sink)
356+
Source<Artifact> artifacts,
357+
boolean poms,
358+
boolean sources,
359+
boolean javadoc,
360+
boolean signature,
361+
Sink<Artifact> sink)
357362
throws Exception;
358363

359364
/**
@@ -362,6 +367,7 @@ Result<List<Artifact>> resolve(
362367
Result<List<Artifact>> resolveTransitive(
363368
ResolutionScope resolutionScope,
364369
Collection<ResolutionRoot> resolutionRoots,
370+
boolean poms,
365371
boolean sources,
366372
boolean javadoc,
367373
boolean signature,

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,21 +906,32 @@ public Result<Path> metadataPath(Metadata metadata, RemoteRepository repository)
906906

907907
@Override
908908
public Result<List<Artifact>> resolve(
909-
Source<Artifact> artifactSource, boolean sources, boolean javadoc, boolean signature, Sink<Artifact> sink)
909+
Source<Artifact> artifactSource,
910+
boolean poms,
911+
boolean sources,
912+
boolean javadoc,
913+
boolean signature,
914+
Sink<Artifact> sink)
910915
throws Exception {
911916
List<Artifact> result = new ArrayList<>();
912917
List<Artifact> artifacts = artifactSource.get().collect(Collectors.toList());
913-
output.suggest("Resolving {}", artifacts);
918+
output.marker(Output.Verbosity.NORMAL)
919+
.emphasize("Resolving ")
920+
.outstanding(artifacts.toString())
921+
.say();
914922
try (Sink<Artifact> artifactSink =
915923
ArtifactSinks.teeArtifactSink(sink, ArtifactSinks.statArtifactSink(0, true, true, output, this))) {
916924
List<Artifact> artifactResults = toolboxResolver.resolveArtifacts(artifacts).stream()
917925
.map(r -> origin(r.getArtifact(), r.getRepository()))
918926
.collect(Collectors.toList());
919927
result.addAll(artifactResults);
920928
artifactSink.accept(artifactResults);
921-
if (sources || javadoc || signature) {
929+
if (poms || sources || javadoc || signature) {
922930
HashSet<Artifact> subartifacts = new HashSet<>();
923931
artifacts.forEach(a -> {
932+
if (poms && a.getClassifier().isEmpty()) {
933+
subartifacts.add(new SubArtifact(a, "", "pom"));
934+
}
924935
if (sources && a.getClassifier().isEmpty()) {
925936
subartifacts.add(new SubArtifact(a, "sources", "jar"));
926937
}
@@ -958,6 +969,7 @@ public Result<List<Artifact>> resolve(
958969
public Result<List<Artifact>> resolveTransitive(
959970
ResolutionScope resolutionScope,
960971
Collection<ResolutionRoot> resolutionRoots,
972+
boolean poms,
961973
boolean sources,
962974
boolean javadoc,
963975
boolean signature,
@@ -969,6 +981,7 @@ public Result<List<Artifact>> resolveTransitive(
969981
doResolveTransitive(
970982
resolutionScope,
971983
resolutionRoot,
984+
poms,
972985
sources,
973986
javadoc,
974987
signature,
@@ -985,6 +998,7 @@ public Result<List<Artifact>> resolveTransitive(
985998
protected void doResolveTransitive(
986999
ResolutionScope resolutionScope,
9871000
ResolutionRoot resolutionRoot,
1001+
boolean poms,
9881002
boolean sources,
9891003
boolean javadoc,
9901004
boolean signature,
@@ -1001,11 +1015,14 @@ protected void doResolveTransitive(
10011015
.map(r -> origin(r.getArtifact(), r.getRepository()))
10021016
.collect(Collectors.toList()));
10031017

1004-
if (sources || javadoc || signature) {
1018+
if (poms || sources || javadoc || signature) {
10051019
HashSet<Artifact> subartifacts = new HashSet<>();
10061020
dependencyResult.getArtifactResults().stream()
10071021
.map(r -> origin(r.getArtifact(), r.getRepository()))
10081022
.forEach(a -> {
1023+
if (poms && a.getClassifier().isEmpty()) {
1024+
subartifacts.add(new SubArtifact(a, "", "pom"));
1025+
}
10091026
if (sources && a.getClassifier().isEmpty()) {
10101027
subartifacts.add(new SubArtifact(a, "sources", "jar"));
10111028
}

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavResolveMojo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public class GavResolveMojo extends GavMojoSupport {
3232
@Parameter(property = "gav", required = true)
3333
private String gav;
3434

35+
/**
36+
* Resolve POMs as well (derive coordinates from GAV).
37+
*/
38+
@CommandLine.Option(
39+
names = {"--poms"},
40+
description = "Resolve POMs as well (derive coordinates from GAV)")
41+
@Parameter(property = "poms", defaultValue = "false")
42+
private boolean poms;
43+
3544
/**
3645
* Resolve sources JAR as well (derive coordinates from GAV).
3746
*/
@@ -74,6 +83,7 @@ protected Result<List<Artifact>> doExecute() throws Exception {
7483
ToolboxCommando toolboxCommando = getToolboxCommando();
7584
return toolboxCommando.resolve(
7685
() -> slurp(gav).stream().map(DefaultArtifact::new),
86+
poms,
7787
sources,
7888
javadoc,
7989
signature,

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavResolveTransitiveMojo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public class GavResolveTransitiveMojo extends GavMojoSupport {
5252
@Parameter(property = "boms")
5353
private String boms;
5454

55+
/**
56+
* Resolve POMs as well (derive coordinates from GAV).
57+
*/
58+
@CommandLine.Option(
59+
names = {"--poms"},
60+
description = "Resolve POMs as well (derive coordinates from GAV)")
61+
@Parameter(property = "poms", defaultValue = "false")
62+
private boolean poms;
63+
5564
/**
5665
* Resolve sources JAR as well (derive coordinates from GAV).
5766
*/
@@ -95,6 +104,7 @@ protected Result<List<Artifact>> doExecute() throws Exception {
95104
return toolboxCommando.resolveTransitive(
96105
ResolutionScope.parse(scope),
97106
toolboxCommando.loadGavs(slurp(gav), slurp(boms)),
107+
poms,
98108
sources,
99109
javadoc,
100110
signature,

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginResolveMojo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*/
2525
@Mojo(name = "plugin-resolve", threadSafe = true)
2626
public class PluginResolveMojo extends MPPluginMojoSupport {
27+
/**
28+
* Resolve POMs as well (derive coordinates from GAV).
29+
*/
30+
@Parameter(property = "poms", defaultValue = "false")
31+
private boolean poms;
32+
2733
/**
2834
* Resolve sources JAR as well (derive coordinates from GAV).
2935
*/
@@ -61,6 +67,6 @@ protected Result<List<Artifact>> doExecute() throws Exception {
6167
.collect(Collectors.toList());
6268
}
6369
return toolboxCommando.resolve(
64-
roots::stream, sources, javadoc, signature, toolboxCommando.artifactSink(sinkSpec, dryRun));
70+
roots::stream, poms, sources, javadoc, signature, toolboxCommando.artifactSink(sinkSpec, dryRun));
6571
}
6672
}

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginResolveTransitiveMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public class PluginResolveTransitiveMojo extends MPPluginMojoSupport {
3030
@Parameter(property = "scope", defaultValue = "runtime", required = true)
3131
private String scope;
3232

33+
/**
34+
* Resolve POMs as well (derive coordinates from GAV).
35+
*/
36+
@Parameter(property = "poms", defaultValue = "false")
37+
private boolean poms;
38+
3339
/**
3440
* Resolve sources JAR as well (derive coordinates from GAV).
3541
*/
@@ -67,6 +73,7 @@ protected Result<List<Artifact>> doExecute() throws Exception {
6773
return toolboxCommando.resolveTransitive(
6874
ResolutionScope.parse(scope),
6975
roots,
76+
poms,
7077
sources,
7178
javadoc,
7279
signature,

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/ResolveMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public class ResolveMojo extends MPMojoSupport {
2626
@Parameter(property = "depSpec", defaultValue = "any()")
2727
private String depSpec;
2828

29+
/**
30+
* Resolve POMs as well (derive coordinates from GAV).
31+
*/
32+
@Parameter(property = "poms", defaultValue = "false")
33+
private boolean poms;
34+
2935
/**
3036
* Resolve sources JAR as well (derive coordinates from GAV).
3137
*/
@@ -57,6 +63,7 @@ protected Result<List<Artifact>> doExecute() throws Exception {
5763
() -> projectAsResolutionRoot().getDependencies().stream()
5864
.filter(toolboxCommando.parseDependencyMatcherSpec(depSpec))
5965
.map(toolboxCommando::toArtifact),
66+
poms,
6067
sources,
6168
javadoc,
6269
signature,

toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/ResolveTransitiveMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class ResolveTransitiveMojo extends MPMojoSupport {
3333
@Parameter(property = "depSpec", defaultValue = "any()")
3434
private String depSpec;
3535

36+
/**
37+
* Resolve POMs as well (derive coordinates from GAV).
38+
*/
39+
@Parameter(property = "poms", defaultValue = "false")
40+
private boolean poms;
41+
3642
/**
3743
* Resolve sources JAR as well (derive coordinates from GAV).
3844
*/
@@ -64,6 +70,7 @@ protected Result<List<Artifact>> doExecute() throws Exception {
6470
return toolboxCommando.resolveTransitive(
6571
resolutionScope,
6672
projectDependenciesAsResolutionRoots(toolboxCommando.parseDependencyMatcherSpec(depSpec)),
73+
poms,
6774
sources,
6875
javadoc,
6976
signature,

0 commit comments

Comments
 (0)