-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Consumer POM of multi-module project should exclude <build> and <dependencies> elements #11639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c621620
52fc26b
e9b3e84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * 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.util.Collection; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.apache.maven.api.model.Source; | ||
|
|
||
| /** | ||
| * Utility methods for analyzing the {@code <source>} elements of a project. | ||
| * <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons. | ||
| * It is not part of the public <abbr>API</abbr>. In particular, this class can be changed or deleted without | ||
| * prior notice. | ||
| */ | ||
| public class ProjectSourcesHelper { | ||
| /** | ||
| * All sources of the project. | ||
| */ | ||
| protected final Collection<Source> sources; | ||
|
|
||
| /** | ||
| * Creates a new helper for the given project. | ||
| * | ||
| * @param project the Maven project from which to get the sources | ||
| */ | ||
| public ProjectSourcesHelper(final MavenProject project) { | ||
| sources = project.getBuild().getDelegate().getSources(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether the project declares at least one {@code <source>} element which is enabled. | ||
| * This is regardless if the source declares a module or not. | ||
| * | ||
| * @return whether the project declares at least one {@code <source>} element which is enabled | ||
| */ | ||
| public boolean hasEnabledSources() { | ||
| for (Source source : sources) { | ||
| if (source.isEnabled()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a stream of non-blank module names. | ||
| * The stream may contain duplicated values. | ||
| * This method does not filter disabled sources. | ||
| * | ||
| * @return a stream of non-blank module names | ||
| */ | ||
| private Stream<String> streamOfModuleNames() { | ||
| return sources.stream() | ||
| .map(org.apache.maven.api.model.Source::getModule) | ||
| .filter(Objects::nonNull) | ||
| .map(String::trim) | ||
| .filter(s -> !s.isBlank()); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts unique module names from the list of source elements. | ||
| * A project uses module source hierarchy if it has at least one module name. | ||
| * | ||
| * @return set of non-blank module names in declaration order | ||
| */ | ||
| public Set<String> getModuleNames() { | ||
| var modules = new LinkedHashSet<String>(); // Preferred to `Collectors.toSet()` for preserving order. | ||
| streamOfModuleNames().forEach(modules::add); | ||
| return modules; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the project uses module source hierarchy. This method returns {@code true} it at least one | ||
| * {@code <source>} element declares a Java modules. While modular and non-modular sources should not be mixed, | ||
| * this code is tolerant to such mixes because non-modular source elements may have been incorrectly generated | ||
| * by non module-aware codes. | ||
| * | ||
| * @return whether the project uses module source hierarchy | ||
| */ | ||
| public boolean useModuleSourceHierarchy() { | ||
| return streamOfModuleNames().findAny().isPresent(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,9 +37,7 @@ | |
|
|
||
| /** | ||
| * 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. | ||
| * This class uses a flexible set-based tracking mechanism that works for any language and scope combination. | ||
| * <p> | ||
| * Key features: | ||
| * <ul> | ||
|
|
@@ -51,7 +49,7 @@ | |
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| class SourceHandlingContext { | ||
| final class SourceHandlingContext extends ProjectSourcesHelper { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(SourceHandlingContext.class); | ||
|
|
||
|
|
@@ -67,19 +65,30 @@ record SourceKey(Language language, ProjectScope scope, String module, Path dire | |
| private final ModelBuilderResult result; | ||
| private final Set<SourceKey> declaredSources; | ||
|
|
||
| SourceHandlingContext( | ||
| MavenProject project, | ||
| Path baseDir, | ||
| Set<String> modules, | ||
| boolean modularProject, | ||
| ModelBuilderResult result) { | ||
| SourceHandlingContext(MavenProject project, Path baseDir, ModelBuilderResult result) { | ||
| super(project); | ||
| this.project = project; | ||
| this.baseDir = baseDir; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: PR #11702 (AC8/AC9 legacy directory handling) also modifies this constructor and
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I noticed that. I will do a rebase and conflict resolution after #11702 is merged. |
||
| this.modules = modules; | ||
| this.modularProject = modularProject; | ||
| this.modules = getModuleNames(); | ||
| this.modularProject = !modules.isEmpty(); | ||
| this.result = result; | ||
| // Each module typically has main, test, main resources, test resources = 4 sources | ||
| this.declaredSources = new HashSet<>(4 * modules.size()); | ||
| LOGGER.trace( | ||
| "Module detection for project {}: found {} module(s) {} - modular project: {}.", | ||
| project.getId(), | ||
| modules.size(), | ||
| modules, | ||
| modularProject); | ||
| } | ||
|
|
||
| /** | ||
| * Whether the project uses module source hierarchy. | ||
| * Overridden for returning the cached value. | ||
| */ | ||
| @Override | ||
| public boolean useModuleSourceHierarchy() { | ||
| return modularProject; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.