gnodet-bot commented on code in PR #13601:
URL: https://github.com/apache/maven/pull/13601#discussion_r4308766547
##########
impl/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java:
##########
@@ -283,6 +283,65 @@ void testFailedParentStillInitializesChild(@TempDir Path
tempDir) throws Excepti
}
}
+ @Test
+ void testLocalParentResolutionWithValidationLevels(@TempDir Path tempDir)
throws Exception {
+ Path parentPom = tempDir.resolve("pom.xml");
+ Files.writeString(parentPom, """
+ <project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>parent</artifactId>
+ <version>1</version>
+ <packaging>pom</packaging>
+ </project>
+ """);
+
+ Path childPom =
Files.createDirectory(tempDir.resolve("child")).resolve("pom.xml");
+ Files.writeString(childPom, """
+ <project xmlns="http://maven.apache.org/POM/4.1.0">
+ <modelVersion>4.1.0</modelVersion>
+ <parent>
+ <groupId>test</groupId>
+ <artifactId>parent</artifactId>
+ <version>1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>child</artifactId>
+ </project>
+ """);
+
+ MavenSession session = createMavenSession(null);
+ session.getRequest().setRootDirectory(tempDir);
+ org.apache.maven.project.ProjectBuilder builder =
+
getContainer().lookup(org.apache.maven.project.ProjectBuilder.class);
+
+ for (int validationLevel :
+ List.of(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL,
ModelBuildingRequest.VALIDATION_LEVEL_STRICT)) {
+ for (boolean processPlugins : List.of(false, true)) {
+ ProjectBuildingRequest request = new
DefaultProjectBuildingRequest();
+ request.setRepositorySession(session.getRepositorySession());
+ request.setValidationLevel(validationLevel);
+ request.setProcessPlugins(processPlugins);
+ ProjectBuildingResult result =
builder.build(childPom.toFile(), request);
+ MavenProject child = result.getProject();
+
+ assertNotNull(child.getParentArtifact());
+ assertEquals("parent",
child.getParentArtifact().getArtifactId());
+ assertEquals(parentPom.toFile(), child.getParentFile());
+
+ boolean hasRelativePathWarning = result.getProblems().stream()
+ .anyMatch(problem ->
+ problem.getMessage().contains("only specify
relativePath or groupId/artifactId"));
+
+ assertEquals(
+ validationLevel ==
ModelBuildingRequest.VALIDATION_LEVEL_STRICT,
+ hasRelativePathWarning,
Review Comment:
⚠️ **Bug:** This assertion is incorrect for `(STRICT=30,
processPlugins=false)`.
When `processPlugins=false`, `DefaultProjectBuilder` sets `type =
CONSUMER_DEPENDENCY` (the `pomFile != null && request.isProcessPlugins()`
branch is false). The `validationLevel` override is therefore `null`, and
`DefaultModelBuilder.getValidationLevel()` falls back to `MINIMAL(0)` for a
non-build request. No relativePath warning is emitted at level 0 (the threshold
is `MAVEN_4_0 = 40`), so `hasRelativePathWarning` is `false` — but
`validationLevel == VALIDATION_LEVEL_STRICT` is `true` (30 == 30), causing the
assertion to fail.
The test needs to account for the fact that `processPlugins=false`
suppresses validation regardless of the requested level. Consider adjusting the
expected value based on both `validationLevel` and `processPlugins`, or narrow
the test matrix to only the combinations where a warning is actually produced.
##########
api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java:
##########
@@ -93,6 +93,15 @@ enum RepositoryMerging {
@Nonnull
RequestType getRequestType();
+ /**
Review Comment:
🔧 **Style:** Missing blank line before the Javadoc. Every other method in
this interface has a blank line between the previous method declaration and its
Javadoc. Please add one here:
```suggestion
/**
```
--
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]