desruisseaux commented on code in PR #11505:
URL: https://github.com/apache/maven/pull/11505#discussion_r2637979905
##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -1099,6 +1123,193 @@ public Set<Entry<K, V>> entrySet() {
}
}
+ /**
+ * Context object for resource handling configuration.
+ * Groups parameters shared between main and test resource handling to
reduce method parameter count.
+ */
+ private record ResourceHandlingContext(
+ MavenProject project,
+ Path baseDir,
+ Set<String> modules,
+ boolean modularProject,
+ ModelBuilderResult result) {}
+
+ /**
+ * Handles resource configuration for a given scope (main or test).
+ * This method applies the resource priority rules:
+ * <ol>
+ * <li>Modular project: use resources from {@code <sources>} if present,
otherwise inject defaults</li>
+ * <li>Classic project: use resources from {@code <sources>} if present,
otherwise use legacy resources</li>
+ * </ol>
+ *
+ * @param context the resource handling context containing project info
+ * @param resources the legacy resource list (from {@code <resources>} or
{@code <testResources>})
+ * @param hasResourcesInSources whether resources are configured via
{@code <sources>}
+ * @param scope the project scope (MAIN or TEST)
+ */
+ private void handleResourceConfiguration(
+ ResourceHandlingContext context,
+ List<Resource> resources,
+ boolean hasResourcesInSources,
+ ProjectScope scope) {
+
+ String scopeId = scope.id();
+ String scopeName = scope == ProjectScope.MAIN ? "Main" : "Test";
+ String legacyElement = scope == ProjectScope.MAIN ? "<resources>" :
"<testResources>";
+ String sourcesConfig = scope == ProjectScope.MAIN
+ ? "<source><lang>resources</lang></source>"
+ : "<source><lang>resources</lang><scope>test</scope></source>";
+
+ if (context.modularProject()) {
+ if (hasResourcesInSources) {
+ // Modular project with resources configured via <sources> -
already added above
+ if (hasExplicitLegacyResources(resources, context.baseDir(),
scopeId)) {
+ logger.warn(
+ "Legacy {} element is ignored because {} resources
are configured via {} in <sources>",
+ legacyElement,
+ scopeId,
+ sourcesConfig);
+ }
+ logger.debug(
+ "{} resources configured via <sources> element,
ignoring legacy {} element",
+ scopeName,
+ legacyElement);
+ } else {
+ // Modular project without resources in <sources> - inject
module-aware defaults
+ if (hasExplicitLegacyResources(resources, context.baseDir(),
scopeId)) {
+ String message = "Legacy " + legacyElement
+ + " element is ignored because modular sources are
configured. "
+ + "Use " + sourcesConfig + " in <sources> for
custom resource paths.";
+ logger.warn(message);
+ context.result()
+ .getProblemCollector()
+ .reportProblem(new
org.apache.maven.impl.model.DefaultModelProblem(
+ message,
+ Severity.WARNING,
+ Version.V41,
+ context.project().getModel().getDelegate(),
+ -1,
+ -1,
+ null));
+ }
+ logger.debug(
Review Comment:
Maybe prepare a `StringBuilder` here, append the _"Adding {} resource root"_
messages of the loop into that buffer, then log a single message when we are
done? I think that `logger.debug` should not be used as a `println`, but that
we should rather send atomic messages when possible.
--
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]