gnodet commented on code in PR #13086:
URL: https://github.com/apache/maven/pull/13086#discussion_r4019088598


##########
compat/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderTest.java:
##########
@@ -99,6 +108,151 @@ public ModelSource resolveModel(Dependency dependency) 
throws UnresolvableModelE
         }
     }
 
+    // -----------------------------------------------------------------------
+    // MNG-5146: parent.relativePath GA mismatch severity
+    // -----------------------------------------------------------------------
+
+    private static final String REAL_PARENT = "<project>\n"
+            + "  <modelVersion>4.0.0</modelVersion>\n"
+            + "  <groupId>mygroup</groupId>\n"
+            + "  <artifactId>myparent</artifactId>\n"
+            + "  <version>1.0</version>\n"
+            + "  <packaging>pom</packaging>\n"
+            + "</project>\n";
+
+    private static final String WRONG_PARENT = "<project>\n"
+            + "  <modelVersion>4.0.0</modelVersion>\n"
+            + "  <groupId>wrong</groupId>\n"
+            + "  <artifactId>wrong</artifactId>\n"
+            + "  <version>1.0</version>\n"
+            + "  <packaging>pom</packaging>\n"
+            + "</project>\n";
+
+    /**
+     * MNG-5146: when {@code <relativePath>} is omitted (null), the default 
{@code ../pom.xml} is
+     * probed and, if its GA does not match the declared parent GA, Maven must 
emit a WARNING (not a
+     * FATAL) and fall back to repository resolution.  The build must succeed 
and the warning must
+     * contain the standard mismatch message.
+     */
+    @Test
+    public void 
testParentGaMismatchDefaultRelativePathProducesWarning(@TempDir Path tempDir)
+            throws IOException, ModelBuildingException {
+        // Layout: tempDir/pom.xml (wrong GA) and tempDir/child/pom.xml (no 
<relativePath>)
+        Path parentPom = tempDir.resolve("pom.xml");
+        Files.writeString(parentPom, WRONG_PARENT);
+
+        Path childDir = Files.createDirectory(tempDir.resolve("child"));
+        Path childPom = childDir.resolve("pom.xml");
+        // No <relativePath>: Maven defaults to ../pom.xml → finds parentPom 
(wrong GA)
+        String childContent = "<project>\n"
+                + "  <modelVersion>4.0.0</modelVersion>\n"
+                + "  <parent>\n"
+                + "    <groupId>mygroup</groupId>\n"
+                + "    <artifactId>myparent</artifactId>\n"
+                + "    <version>1.0</version>\n"
+                + "  </parent>\n"
+                + "  <artifactId>mychild</artifactId>\n"
+                + "</project>\n";
+        Files.writeString(childPom, childContent);
+
+        ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
+        DefaultModelBuildingRequest request = new 
DefaultModelBuildingRequest();
+        request.setPomFile(childPom.toFile());
+        // Resolver returns the *correct* parent for external resolution 
(fallback after mismatch)
+        request.setModelResolver(new ParentProvidingResolver("mygroup", 
"myparent", "1.0", REAL_PARENT));
+        
request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
+
+        ModelBuildingResult result = builder.build(request);
+
+        // The build must succeed; the mismatch diagnostic must be a WARNING, 
not a FATAL.
+        List<ModelProblem> problems = result.getProblems();
+        long warningCount = problems.stream()
+                .filter(p -> p.getSeverity() == Severity.WARNING
+                        && p.getMessage().contains("please verify your project 
structure"))
+                .count();
+        assertEquals(1, warningCount, "Expected exactly one WARNING about GA 
mismatch; got: " + problems);
+
+        // No FATAL problem for this mismatch.
+        boolean hasFatalMismatch = problems.stream()
+                .anyMatch(p -> p.getSeverity() == Severity.FATAL
+                        && p.getMessage().contains("please verify your project 
structure"));
+        assertTrue(!hasFatalMismatch, "Expected no FATAL for 
default-relativePath mismatch; got: " + problems);

Review Comment:
   Fixed in f99a00c02b.



-- 
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