desruisseaux commented on code in PR #11632:
URL: https://github.com/apache/maven/pull/11632#discussion_r2678614380
##########
impl/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java:
##########
@@ -470,4 +478,255 @@ 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 mixed source configuration where:
+ * - Modular sources are defined for main Java (should override
sourceDirectory)
+ * - Classic testSourceDirectory is used (should be preserved since no
modular test sources)
+ * <p>
+ * This verifies:
+ * - sourceDirectory is ignored when modular main sources exist
+ * - testSourceDirectory is used when no modular test sources are defined
+ * <p>
+ * Acceptance Criterion: AC1 (boolean flags eliminated - uses hasSources()
for main/test detection)
+ *
+ * @see <a href="https://github.com/apache/maven/issues/11612">Issue
#11612</a>
+ */
+ @Test
+ void testMixedSourcesModularMainClassicTest() throws Exception {
+ File pom = getProject("mixed-sources");
+
+ MavenSession session = createMavenSession(pom);
+ MavenProject project = session.getCurrentProject();
+
+ // 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"));
+ assertTrue(!hasClassicMainSource, "Classic sourceDirectory should be
ignored");
+
+ // Get test Java source roots - should use classic testSourceDirectory
since no modular test sources
+ List<SourceRoot> testJavaRoots =
project.getEnabledSourceRoots(ProjectScope.TEST, Language.JAVA_FAMILY)
+ .toList();
+
+ // Should have 1 test source (from classic testSourceDirectory)
+ assertEquals(1, testJavaRoots.size(), "Should have 1 test Java source
root (classic)");
+
+ // The test source should be the classic one (no module)
+ SourceRoot testRoot = testJavaRoots.get(0);
+ assertTrue(testRoot.module().isEmpty(), "Classic test source should
not have a module");
+ assertTrue(
+ testRoot.directory().toString().replace('\\',
'/').contains("src/classic/test/java"),
+ "Should use classic testSourceDirectory");
+ }
+
+ /**
+ * Tests mixed modular/non-modular sources within the same {@code
<sources>} element.
Review Comment:
See comment in `sources-mixed-modules`: a project can be fully modular or
fully classic, but not a mix of both. An error should be emitted. In this case,
I think that it should be an error rather than a warning, because the compiler
plugin will not know what to do with such mixed project.
--
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]