ascheman commented on code in PR #11632:
URL: https://github.com/apache/maven/pull/11632#discussion_r2751560290
##########
impl/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java:
##########
@@ -470,4 +478,257 @@ void
testModularSourcesWithExplicitResourcesIssuesWarning() throws Exception {
assertTrue(mainModules.contains("org.foo.moduleA"), "Should have
resource root for moduleA");
assertTrue(mainModules.contains("org.foo.moduleB"), "Should have
resource root for moduleB");
}
+
+ /**
+ * Tests that legacy sourceDirectory and testSourceDirectory are ignored
in modular projects.
+ * <p>
+ * In modular projects, legacy directories are unconditionally ignored
because it is not clear
+ * how to dispatch their content between different modules. A warning is
emitted if these
+ * properties are explicitly set (differ from Super POM defaults).
+ * <p>
+ * This verifies:
+ * - WARNINGs are emitted for explicitly set legacy directories in modular
projects
+ * - sourceDirectory and testSourceDirectory are both ignored
+ * - Only modular sources from {@code <sources>} are used
+ * <p>
+ * Acceptance Criteria:
+ * - AC1 (boolean flags eliminated - uses hasSources() for main/test
detection)
+ * - AC7 (legacy directories warning - {@code <sourceDirectory>} and
{@code <testSourceDirectory>}
+ * are unconditionally ignored with a WARNING in modular projects)
+ *
+ * @see <a href="https://github.com/apache/maven/issues/11612">Issue
#11612</a>
+ */
+ @Test
+ void testMixedSourcesModularMainClassicTest() throws Exception {
+ File pom = getProject("mixed-sources");
+
+ MavenSession mavenSession = createMavenSession(null);
+ ProjectBuildingRequest configuration = new
DefaultProjectBuildingRequest();
+
configuration.setRepositorySession(mavenSession.getRepositorySession());
+
+ ProjectBuildingResult result = getContainer()
+ .lookup(org.apache.maven.project.ProjectBuilder.class)
+ .build(pom, configuration);
+
+ MavenProject project = result.getProject();
+
+ // Verify WARNINGs are emitted for explicitly set legacy directories
+ List<ModelProblem> warnings = result.getProblems().stream()
+ .filter(p -> p.getSeverity() == ModelProblem.Severity.WARNING)
+ .filter(p -> p.getMessage().contains("Legacy") &&
p.getMessage().contains("ignored in modular project"))
+ .toList();
+
+ // Should have 2 warnings: one for sourceDirectory, one for
testSourceDirectory
+ assertEquals(2, warnings.size(), "Should have 2 warnings for ignored
legacy directories");
+ assertTrue(
+ warnings.stream().anyMatch(w ->
w.getMessage().contains("<sourceDirectory>")),
+ "Should warn about ignored <sourceDirectory>");
+ assertTrue(
+ warnings.stream().anyMatch(w ->
w.getMessage().contains("<testSourceDirectory>")),
+ "Should warn about ignored <testSourceDirectory>");
+
+ // Get main Java source roots - should have modular sources, not
classic sourceDirectory
+ List<SourceRoot> mainJavaRoots =
project.getEnabledSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY)
+ .toList();
+
+ // Should have 2 modular main Java sources (moduleA and moduleB)
+ assertEquals(2, mainJavaRoots.size(), "Should have 2 modular main Java
source roots");
+
+ Set<String> mainModules = mainJavaRoots.stream()
+ .map(SourceRoot::module)
+ .filter(opt -> opt.isPresent())
+ .map(opt -> opt.get())
+ .collect(Collectors.toSet());
+
+ assertEquals(2, mainModules.size(), "Should have main sources for 2
modules");
+ assertTrue(mainModules.contains("org.foo.moduleA"), "Should have main
source for moduleA");
+ assertTrue(mainModules.contains("org.foo.moduleB"), "Should have main
source for moduleB");
+
+ // Verify the classic sourceDirectory is NOT used (should be ignored)
+ boolean hasClassicMainSource = mainJavaRoots.stream()
+ .anyMatch(sr -> sr.directory().toString().replace('\\',
'/').contains("src/classic/main/java"));
Review Comment:
Done in commit 08fa756ce2. Applied `replace(File.separatorChar, '/')` to all
occurrences.
--
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]