desruisseaux commented on code in PR #11632:
URL: https://github.com/apache/maven/pull/11632#discussion_r2678595661
##########
impl/maven-core/src/main/java/org/apache/maven/project/SourceHandlingContext.java:
##########
@@ -59,6 +80,73 @@ class ResourceHandlingContext {
this.result = result;
}
+ /**
+ * Determines if a source root should be added to the project and tracks
it for duplicate detection.
+ * <p>
+ * Rules:
+ * <ul>
+ * <li>Disabled sources are always added (they're filtered by {@code
getEnabledSourceRoots()})</li>
+ * <li>First enabled source for an identity is added and tracked</li>
+ * <li>Subsequent enabled sources with same identity trigger a WARNING
and are NOT added</li>
+ * </ul>
+ *
+ * @param sourceRoot the source root to evaluate
+ * @return true if the source should be added to the project, false if
it's a duplicate enabled source
+ */
+ boolean shouldAddSource(SourceRoot sourceRoot) {
+ if (!sourceRoot.enabled()) {
+ // Disabled sources are always added - they're filtered out by
getEnabledSourceRoots()
+ LOGGER.debug(
+ "Adding disabled source (will be filtered by
getEnabledSourceRoots): lang={}, scope={}, module={}, dir={}",
+ sourceRoot.language(),
+ sourceRoot.scope(),
+ sourceRoot.module().orElse(null),
+ sourceRoot.directory());
+ return true;
+ }
+
+ SourceKey key = new SourceKey(
+ sourceRoot.language(), sourceRoot.scope(),
sourceRoot.module().orElse(null), sourceRoot.directory());
+
+ if (declaredSources.contains(key)) {
+ String message = String.format(
+ "Duplicate enabled source detected: lang=%s, scope=%s,
module=%s, directory=%s. "
+ + "First enabled source wins, this duplicate is
ignored.",
+ key.language(), key.scope(), key.module() != null ?
key.module() : "(none)", key.directory());
+ LOGGER.warn(message);
Review Comment:
I wonder if it should be an error (throwing an exception) instead of only a
warning. I'm not sure about that, just thinking.
--
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]