desruisseaux commented on code in PR #11505: URL: https://github.com/apache/maven/pull/11505#discussion_r2642603029
########## impl/maven-core/src/main/java/org/apache/maven/project/ResourceHandlingContext.java: ########## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.project; + +import java.nio.file.Path; +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.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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Handles resource configuration for Maven projects. + * Groups parameters shared between main and test resource handling. + */ +class ResourceHandlingContext { + + private static final Logger LOGGER = LoggerFactory.getLogger(ResourceHandlingContext.class); + + private final MavenProject project; + private final Path baseDir; + private final Set<String> modules; + private final boolean modularProject; + private final ModelBuilderResult result; + + ResourceHandlingContext( + MavenProject project, + Path baseDir, + Set<String> modules, + boolean modularProject, + ModelBuilderResult result) { + this.project = project; + this.baseDir = baseDir; + this.modules = modules; + this.modularProject = modularProject; + this.result = 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 scope the project scope (MAIN or TEST) + * @param hasResourcesInSources whether resources are configured via {@code <sources>} + */ + void handleResourceConfiguration(ProjectScope scope, boolean hasResourcesInSources) { + List<Resource> resources = scope == ProjectScope.MAIN + ? project.getBuild().getDelegate().getResources() + : project.getBuild().getDelegate().getTestResources(); + + 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 (modularProject) { + if (hasResourcesInSources) { + // Modular project with resources configured via <sources> - already added above + if (hasExplicitLegacyResources(resources, scopeId)) { + LOGGER.warn( + "Legacy {} element is ignored because {} resources are configured via {} in <sources>.", + legacyElement, + scopeId, + sourcesConfig); + } else { + LOGGER.trace( Review Comment: It is nice to reduce the amount of logging, but I think that in the particular case of `handleResourceConfiguration`, we can keep the debug level as it was before. The rational is that other loggings (now removed or reduced to trace level) were a little bit trivial. But the loggings in this `handleResourceConfiguration` method are the result of a more elaborated analysis. Would you mind switching back to debug level all the logging at the trace level in this `handleResourceConfiguration` method, but only in this method? -- 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]
