gnodet-bot commented on code in PR #13196:
URL: https://github.com/apache/maven/pull/13196#discussion_r4050798273


##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/ParentCycleDetectionTest.java:
##########
@@ -322,4 +326,88 @@ void 
testMultipleModulesWithSameParentDoNotCauseCycle(@TempDir Path tempDir) thr
         assertNotNull(resultA);
         assertNotNull(resultB);
     }
+
+    /**
+     * Reproduces GH-13191: maven-shade-plugin generates 
dependency-reduced-pom.xml with
+     * {@code <relativePath>pom.xml</relativePath>} copied from the original 
POM. When Maven 4
+     * processes this generated POM, the relativePath resolves to the 
project's own pom.xml, whose
+     * G:A matches the child (not the declared parent). This must produce a 
WARNING (fallback to
+     * repository), never a FATAL that breaks the build.
+     */
+    @Test
+    void testSelfReferentialRelativePathInGeneratedPomIsWarning(@TempDir Path 
tempDir) throws IOException {
+        Files.createDirectories(tempDir.resolve(".mvn"));
+
+        // Simulates the original project pom.xml (the child artifact itself)
+        Path projectPom = tempDir.resolve("pom.xml");
+        Files.writeString(projectPom, """
+            <project xmlns="http://maven.apache.org/POM/4.0.0";>
+                <modelVersion>4.0.0</modelVersion>
+                <parent>
+                    <groupId>org.apache.sling</groupId>
+                    <artifactId>sling-bundle-parent</artifactId>
+                    <version>57</version>
+                    <relativePath/>
+                </parent>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>org.apache.sling.models.impl</artifactId>
+                <version>2.0.3-SNAPSHOT</version>
+                <packaging>jar</packaging>
+            </project>
+            """);
+
+        // Simulates dependency-reduced-pom.xml generated by 
maven-shade-plugin.
+        // It copies <relativePath>pom.xml</relativePath> from the original 
POM transformation,
+        // which resolves to the project's own pom.xml — a self-referential 
path.
+        Path reducedPom = tempDir.resolve("dependency-reduced-pom.xml");
+        Files.writeString(reducedPom, """
+            <project xmlns="http://maven.apache.org/POM/4.0.0";>
+                <modelVersion>4.0.0</modelVersion>
+                <parent>
+                    <groupId>org.apache.sling</groupId>
+                    <artifactId>sling-bundle-parent</artifactId>
+                    <version>57</version>
+                    <relativePath>pom.xml</relativePath>
+                </parent>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>org.apache.sling.models.impl</artifactId>
+                <version>2.0.3-SNAPSHOT</version>
+                <packaging>jar</packaging>
+            </project>
+            """);
+
+        ModelBuilderRequest request = ModelBuilderRequest.builder()
+                .session(session)
+                .source(Sources.buildSource(reducedPom))
+                .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT)

Review Comment:
   💡 **Coverage gap — `doReadFileModel` call site untested.** This 
`BUILD_PROJECT` + full G:A:V parent exercises only 
`ParentResolutionFrame.advance()` (call site 2). The other call site in 
`doReadFileModel` fires when the parent's version is missing or contains a 
`${…}` expression AND `<relativePath>` is non-empty. Consider adding a second 
test with `<version>${revision}</version>` in the parent to cover that path — 
or add a comment explaining why it can't be reached for generated POMs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to