Skip to content

Commit 53cb658

Browse files
committed
fix(manifest): keep a ranged Maven 3.2 declaration from inheriting a cached POM failure
Replaying another module's cached POM failure matched any version-range declaration of the same artifact, so a module whose range resolved to a healthy version inherited the failure. A direct dependency never loses a conflict, so one still among the graph's direct children resolved.
1 parent 506d191 commit 53cb658

4 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎src/commands/manifest/scripts/maven-extension/src/main/java/tech/coana/socket/SocketFactsRecordsEngine.java‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ private void collectModule(
259259
}
260260
if (collectorDropsFailedNodes) {
261261
// An earlier module's cached failure leaves no trace in this graph; only a direct dependency
262-
// can still be placed.
262+
// can still be placed. One still among the direct children resolved (a ranged declaration to
263+
// another version), since a direct dependency never loses a conflict.
263264
for (Map.Entry<String, FailedRequest> e : brokenDescriptors.entrySet()) {
264265
if (scopesByGav.containsKey(e.getKey()) || placed.contains(e.getKey())) continue;
266+
if (isDirectChild(graph, e.getValue().artifact)) continue;
265267
String scope = declaredScope(session, module, e.getValue().artifact);
266268
if (scope != null && passingScopes.contains(scope)) {
267269
failures.add(new Failure(e.getKey(), e.getValue().detail, scope, moduleCoord));
@@ -756,6 +758,22 @@ private static org.apache.maven.model.Dependency modelDependency(
756758
return null;
757759
}
758760

761+
// A direct dependency of `root` naming the artifact, at any version.
762+
private static boolean isDirectChild(DependencyNode root, Artifact artifact) {
763+
if (root == null) return false;
764+
for (DependencyNode child : root.getChildren()) {
765+
Artifact a = child.getArtifact();
766+
if (a != null
767+
&& a.getGroupId().equals(artifact.getGroupId())
768+
&& a.getArtifactId().equals(artifact.getArtifactId())
769+
&& a.getClassifier().equals(artifact.getClassifier())
770+
&& a.getExtension().equals(artifact.getExtension())) {
771+
return true;
772+
}
773+
}
774+
return false;
775+
}
776+
759777
// The final graph's root and every node on its classpath, by identity.
760778
private static Set<DependencyNode> onClasspath(DependencyNode root) {
761779
Set<DependencyNode> seen = Collections.newSetFromMap(new IdentityHashMap<>());

‎src/commands/manifest/scripts/test/maven-compat/descriptor-failure/a/pom.xml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
<!-- broken's POM names a parent that cannot be fetched. nopom has a jar but no POM; nothing has neither. sys and
1111
sysmissing are system-scoped, the latter at a path that does not exist. testparent (test) declares rangedchild
1212
at a range no version satisfies. loserparent declares conflict 1.0, whose POM is broken but which loses to the
13-
nearer conflict 2.0. -->
13+
nearer conflict 2.0. rebroken's range resolves to 2.0, not to the 1.0 whose broken POM b already met.
14+
-->
1415
<dependencies>
1516
<dependency>
1617
<groupId>demo.descfail</groupId>
1718
<artifactId>broken</artifactId>
1819
<version>1.0</version>
1920
</dependency>
21+
<dependency>
22+
<groupId>demo.descfail</groupId>
23+
<artifactId>rebroken</artifactId>
24+
<version>[2.0,3.0)</version>
25+
</dependency>
2026
<dependency>
2127
<groupId>demo.descfail</groupId>
2228
<artifactId>nopom</artifactId>

‎src/commands/manifest/scripts/test/maven-compat/descriptor-failure/b/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@
1919
<version>1.0</version>
2020
<scope>test</scope>
2121
</dependency>
22+
<dependency>
23+
<groupId>demo.descfail</groupId>
24+
<artifactId>rebroken</artifactId>
25+
<version>1.0</version>
26+
</dependency>
2227
</dependencies>
2328
</project>

‎src/commands/manifest/scripts/test/maven-compat/smoke-test-descriptor-failure.sh‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env bash
22
# Regression guard for failures Maven's resolver hides from a plain resolution result:
33
# - A POM that failed once is cached build-wide, so a later module gets the dependency without an
4-
# error. It must still fail there, in that module's scope (broken: test in b, compile in a).
4+
# error. It must still fail there, in that module's scope (broken: test in b, compile in a), but
5+
# not where a range resolved to another version (rebroken: 1.0 in b, [2.0,3.0) in a).
56
# - A missing POM is tolerated by Maven's default descriptor policy, losing the dependency's own
67
# dependencies. It must fail; the dependency stays emitted with its jar (nopom), and one whose jar
78
# is missing too gets no file (nothing).
@@ -57,6 +58,17 @@ jar_for broken 1.0
5758
jar_for nopom 1.0
5859
pom testparent 1.0 "$(dep rangedchild '[5.0,6.0)')"
5960
jar_for testparent 1.0
61+
pom rebroken 1.0 '<parent><groupId>demo.descfail</groupId><artifactId>absent-parent</artifactId><version>1.0</version></parent>'
62+
jar_for rebroken 1.0
63+
pom rebroken 2.0 ''
64+
jar_for rebroken 2.0
65+
cat > "$REPO/rebroken/maven-metadata-local.xml" <<'XML'
66+
<metadata>
67+
<groupId>demo.descfail</groupId>
68+
<artifactId>rebroken</artifactId>
69+
<versioning><versions><version>1.0</version><version>2.0</version></versions></versioning>
70+
</metadata>
71+
XML
6072
pom conflict 2.0 ''
6173
jar_for conflict 2.0
6274
pom conflict 1.0 '<parent><groupId>demo.descfail</groupId><artifactId>absent-parent</artifactId><version>1.0</version></parent>'
@@ -93,6 +105,7 @@ expected = {
93105
}
94106
if not keeps_failed:
95107
expected.add(('demo.descfail:conflict:1.0', '', a))
108+
expected.add(('demo.descfail:rebroken:1.0', 'compile', b))
96109
if with_test:
97110
expected.add(('demo.descfail:broken:1.0', 'test', b))
98111
if with_test or not steps:
@@ -112,7 +125,8 @@ for f in failures:
112125
errors.append(f"{f[0]} reports the batch wrapper, not its cause: {f[1]!r}")
113126
if any(n.startswith('demo.descfail:broken:') for n in nodes):
114127
errors.append(f"broken's POM failed, so it must not be emitted; nodes={sorted(nodes)}")
115-
for coord in ('demo.descfail:ok:jar:1.0', 'demo.descfail:nopom:jar:1.0', 'demo.descfail:sys:jar:1.0'):
128+
for coord in ('demo.descfail:ok:jar:1.0', 'demo.descfail:nopom:jar:1.0', 'demo.descfail:sys:jar:1.0',
129+
'demo.descfail:rebroken:jar:2.0'):
116130
if coord not in files:
117131
errors.append(f"{coord} must be emitted with its jar; files={sorted(files)}")
118132
if unfetched != {'demo.descfail:nothing:jar:1.0', 'demo.descfail:sysmissing:jar:1.0'}:

0 commit comments

Comments
 (0)