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


##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -660,46 +660,75 @@ private void initProject(MavenProject project, 
ModelBuilderResult result) {
                         return build.getDirectory();
                     }
                 };
-                boolean hasScript = false;
-                boolean hasMain = false;
-                boolean hasTest = false;
+                // Extract modules from sources to detect modular projects
+                Set<String> modules = extractModules(sources);
+                boolean isModularProject = !modules.isEmpty();
+
+                logger.trace(
+                        "Module detection for project {}: found {} module(s) 
{} - modular project: {}.",
+                        project.getId(),
+                        modules.size(),
+                        modules,
+                        isModularProject);
+
+                // Create source handling context for unified tracking of all 
lang/scope combinations
+                SourceHandlingContext sourceContext =
+                        new SourceHandlingContext(project, baseDir, modules, 
isModularProject, result);
+
+                // Process all sources, tracking enabled ones and detecting 
duplicates
                 for (var source : sources) {
-                    var src = DefaultSourceRoot.fromModel(session, baseDir, 
outputDirectory, source);
-                    project.addSourceRoot(src);
-                    Language language = src.language();
-                    if (Language.JAVA_FAMILY.equals(language)) {
-                        ProjectScope scope = src.scope();
-                        if (ProjectScope.MAIN.equals(scope)) {
-                            hasMain = true;
-                        } else {
-                            hasTest |= ProjectScope.TEST.equals(scope);
-                        }
-                    } else {
-                        hasScript |= Language.SCRIPT.equals(language);
+                    var sourceRoot = DefaultSourceRoot.fromModel(session, 
baseDir, outputDirectory, source);

Review Comment:
   Personally I dislike var. It prioritizes trivial typing speed over code 
readability



##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -566,7 +566,7 @@ private List<ProjectBuildingResult> build(File pomFile, 
boolean recursive) {
                     project.setCollectedProjects(results(r)
                             .filter(cr -> cr != r && cr.getEffectiveModel() != 
null)
                             .map(cr -> 
projectIndex.get(cr.getEffectiveModel().getId()))
-                            .collect(Collectors.toList()));
+                            .toList());

Review Comment:
   ditto; good but not needed in this PR



##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -870,6 +899,49 @@ private void initProject(MavenProject project, 
ModelBuilderResult result) {
             project.setRemoteArtifactRepositories(remoteRepositories);
         }
 
+        /**
+         * Warns about legacy directory usage in a modular project. Two cases 
are handled:
+         * <ul>
+         *   <li>Case 1: The default legacy directory exists on the filesystem 
(e.g., src/main/java exists)</li>
+         *   <li>Case 2: An explicit legacy directory is configured that 
differs from the default</li>
+         * </ul>
+         * Legacy directories are unconditionally ignored in modular projects 
because it is not clear

Review Comment:
   I'm not sure I'm comfortable with this. If we can't dispatch, I think we 
need to hard fail the build rather than simply ignoring the content. Let the 
user figure out how to rearrange the project to make the build pass. A warning 
is not enough here. 



##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -520,7 +520,7 @@ List<ProjectBuildingResult> doBuild(List<File> pomFiles, 
boolean recursive) {
                 return pomFiles.stream()
                         .map(pomFile -> build(pomFile, recursive))
                         .flatMap(List::stream)
-                        .collect(Collectors.toList());
+                        .toList();

Review Comment:
   This could be a separate small change



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