desruisseaux commented on code in PR #11632:
URL: https://github.com/apache/maven/pull/11632#discussion_r2678589020


##########
impl/maven-core/src/main/java/org/apache/maven/project/SourceHandlingContext.java:
##########
@@ -19,34 +19,55 @@
 package org.apache.maven.project;
 
 import java.nio.file.Path;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.api.Language;
 import org.apache.maven.api.ProjectScope;
+import org.apache.maven.api.SourceRoot;
 import org.apache.maven.api.model.Resource;
 import org.apache.maven.api.services.BuilderProblem.Severity;
 import org.apache.maven.api.services.ModelBuilderResult;
 import org.apache.maven.api.services.ModelProblem.Version;
 import org.apache.maven.impl.DefaultSourceRoot;
+import org.apache.maven.impl.model.DefaultModelProblem;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Handles resource configuration for Maven projects.
- * Groups parameters shared between main and test resource handling.
+ * Handles source configuration for Maven projects with unified tracking for 
all language/scope combinations.
+ * <p>
+ * This class replaces the previous approach of hardcoded boolean flags 
(hasMain, hasTest, etc.)
+ * with a flexible set-based tracking mechanism that works for any language 
and scope combination.
+ * <p>
+ * Key features:
+ * <ul>
+ *   <li>Tracks declared sources using {@code (language, scope, module, 
directory)} identity</li>
+ *   <li>Only tracks enabled sources - disabled sources are effectively 
no-ops</li>
+ *   <li>Detects duplicate enabled sources and emits warnings</li>
+ *   <li>Provides {@link #hasSources(Language, ProjectScope)} to check if 
sources exist for a combination</li>
+ * </ul>
+ *
+ * @since 4.0.0
  */
-class ResourceHandlingContext {
+class SourceHandlingContext {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(ResourceHandlingContext.class);
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SourceHandlingContext.class);
+
+    /**
+     * Identity key for source tracking. Two sources with the same key are 
considered duplicates.
+     */
+    record SourceKey(Language language, ProjectScope scope, String module, 
Path directory) {}
 
     private final MavenProject project;
     private final Path baseDir;
     private final Set<String> modules;
     private final boolean modularProject;
     private final ModelBuilderResult result;
+    private final Set<SourceKey> declaredSources = new HashSet<>();

Review Comment:
   It is a very minor details, but moving this initialization inside the 
constructor would allow to specify an initial capacity as `new HashSet<>(4 * 
modules.size())` (assuming that each module is likely to have a `main`, a 
`test`, main resources and test resources).



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