elharo commented on code in PR #11505:
URL: https://github.com/apache/maven/pull/11505#discussion_r2602318202


##########
impl/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java:
##########
@@ -371,4 +376,98 @@ void testLocationTrackingResolution() throws Exception {
         assertEquals(
                 "org.apache.maven.its:parent:0.1", 
pluginLocation.getSource().getModelId());
     }
+    /**
+     * Tests that a project with multiple modules defined in sources is 
detected as modular,
+     * and module-aware resource roots are injected for each module.
+     */
+    @Test
+    void testModularSourcesInjectResourceRoots() throws Exception {
+        File pom = getProject("modular-sources");
+
+        MavenSession session = createMavenSession(pom);
+        MavenProject project = session.getCurrentProject();
+
+        // Get all resource source roots for main scope
+        List<SourceRoot> mainResourceRoots = 
project.getEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES)
+                .collect(Collectors.toList());
+
+        // Should have resource roots for both modules
+        Set<String> modules = mainResourceRoots.stream()
+                .map(SourceRoot::module)
+                .filter(opt -> opt.isPresent())
+                .map(opt -> opt.get())
+                .collect(Collectors.toSet());
+
+        assertEquals(2, modules.size(), "Should have resource roots for 2 
modules");
+        assertTrue(modules.contains("org.foo.moduleA"), "Should have resource 
root for moduleA");
+        assertTrue(modules.contains("org.foo.moduleB"), "Should have resource 
root for moduleB");
+
+        // Get all resource source roots for test scope
+        List<SourceRoot> testResourceRoots = 
project.getEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES)
+                .collect(Collectors.toList());
+
+        // Should have test resource roots for both modules
+        Set<String> testModules = testResourceRoots.stream()
+                .map(SourceRoot::module)
+                .filter(opt -> opt.isPresent())
+                .map(opt -> opt.get())
+                .collect(Collectors.toSet());
+
+        assertEquals(2, testModules.size(), "Should have test resource roots 
for 2 modules");
+        assertTrue(testModules.contains("org.foo.moduleA"), "Should have test 
resource root for moduleA");
+        assertTrue(testModules.contains("org.foo.moduleB"), "Should have test 
resource root for moduleB");
+    }
+
+    /**
+     * Tests that when modular sources are configured alongside explicit 
legacy resources,
+     * the legacy resources are ignored and a warning is issued.
+     *
+     * This verifies the behavior described in the design:
+     * - Modular projects with explicit legacy {@code <resources>} 
configuration should issue a warning
+     * - The modular resource roots are injected instead of using the legacy 
configuration
+     */
+    @Test
+    void testModularSourcesWithExplicitResourcesIssuesWarning() throws 
Exception {
+        File pom = getProject("modular-sources-with-explicit-resources");
+
+        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 issued for ignored legacy resources
+        List<org.apache.maven.model.building.ModelProblem> warnings = 
result.getProblems().stream()

Review Comment:
   can this just be imported in short form



##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -700,12 +709,24 @@ private void initProject(MavenProject project, 
ModelBuilderResult result) {
                 if (!hasTest) {
                     
project.addTestCompileSourceRoot(build.getTestSourceDirectory());
                 }
-                for (Resource resource : 
project.getBuild().getDelegate().getResources()) {
-                    project.addSourceRoot(new DefaultSourceRoot(baseDir, 
ProjectScope.MAIN, resource));
-                }
-                for (Resource resource : 
project.getBuild().getDelegate().getTestResources()) {
-                    project.addSourceRoot(new DefaultSourceRoot(baseDir, 
ProjectScope.TEST, resource));
-                }
+                // Extract modules from sources to detect modular projects
+                Set<String> modules = extractModules(sources);
+                boolean isModularProject = !modules.isEmpty();
+
+                logger.debug(
+                        "Module detection for project {}: found {} module(s) 
{} - modular project: {}",
+                        project.getId(),
+                        modules.size(),
+                        modules,
+                        isModularProject);
+
+                // Handle main and test resources using shared method
+                ResourceHandlingContext ctx =

Review Comment:
   ctx --> context or resourceHandlingContext;
   
   in general don't abbreviate



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