This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new 9c77221cbc [MNG-8393] Enable consumer pom by default for 4.1.0 model version only (#1963) 9c77221cbc is described below commit 9c77221cbc382947ac6cbc2a63647efe60ebaa3e Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Thu Dec 12 09:07:12 2024 +0100 [MNG-8393] Enable consumer pom by default for 4.1.0 model version only (#1963) --- .../src/main/java/org/apache/maven/api/feature/Features.java | 12 ++---------- .../src/main/java/org/apache/maven/ReactorReader.java | 10 ---------- .../transformation/ConsumerPomArtifactTransformer.java | 4 ++++ .../impl/DefaultConsumerPomArtifactTransformer.java | 12 +++++------- .../src/test/resources/mng-7228-leaky-model/pom.xml | 4 ++-- .../mng-7836-alternative-pom-syntax/simple/pom.hocon | 2 +- 6 files changed, 14 insertions(+), 30 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/feature/Features.java b/api/maven-api-core/src/main/java/org/apache/maven/api/feature/Features.java index c88b239f28..3318a895d7 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/feature/Features.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/feature/Features.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Properties; import org.apache.maven.api.Constants; -import org.apache.maven.api.Session; import org.apache.maven.api.annotations.Nullable; /** @@ -45,15 +44,8 @@ public final class Features { /** * Check if the consumer POM feature is active. */ - public static boolean consumerPom(@Nullable Map<String, String> userProperties) { - return doGet(userProperties, Constants.MAVEN_CONSUMER_POM, true); - } - - /** - * Check if the consumer POM feature is active. - */ - public static boolean consumerPom(@Nullable Session session) { - return consumerPom(session != null ? session.getUserProperties() : null); + public static boolean consumerPom(@Nullable Map<String, String> userProperties, boolean def) { + return doGet(userProperties, Constants.MAVEN_CONSUMER_POM, def); } private static boolean doGet(Properties userProperties, String key, boolean def) { diff --git a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java index ea4af1e986..fcabbf4d72 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -43,7 +43,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.maven.api.feature.Features; import org.apache.maven.api.model.Model; import org.apache.maven.api.services.Lookup; import org.apache.maven.eventspy.EventSpy; @@ -415,15 +414,6 @@ class ReactorReader implements MavenWorkspaceReader { private void installIntoProjectLocalRepository(Artifact artifact) { String extension = artifact.getExtension(); String classifier = artifact.getClassifier(); - if (Features.consumerPom(session.getUserProperties())) { - if ("pom".equals(extension)) { - if (classifier == null || classifier.isEmpty()) { - classifier = "build"; - } else if (classifier.equals("consumer")) { - classifier = null; - } - } - } Path target = getArtifactPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), classifier, extension); diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java index ef2901a652..94be78f680 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java @@ -32,6 +32,10 @@ import org.eclipse.aether.installation.InstallRequest; */ public interface ConsumerPomArtifactTransformer { + String CONSUMER_POM_CLASSIFIER = "consumer"; + + String BUILD_POM_CLASSIFIER = "build"; + InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request); DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request); diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomArtifactTransformer.java b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomArtifactTransformer.java index 60865274a0..60ab919f5a 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomArtifactTransformer.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomArtifactTransformer.java @@ -36,6 +36,7 @@ import java.util.concurrent.CopyOnWriteArraySet; import org.apache.maven.api.feature.Features; import org.apache.maven.api.model.Model; +import org.apache.maven.api.services.ModelBuilder; import org.apache.maven.api.services.ModelBuilderException; import org.apache.maven.internal.transformation.ConsumerPomArtifactTransformer; import org.apache.maven.model.v4.MavenStaxWriter; @@ -57,10 +58,6 @@ import org.eclipse.sisu.PreDestroy; @Named("consumer-pom") class DefaultConsumerPomArtifactTransformer implements ConsumerPomArtifactTransformer { - private static final String CONSUMER_POM_CLASSIFIER = "consumer"; - - private static final String BUILD_POM_CLASSIFIER = "build"; - private static final String NAMESPACE_FORMAT = "http://maven.apache.org/POM/%s"; private static final String SCHEMA_LOCATION_FORMAT = "https://maven.apache.org/xsd/maven-%s.xsd"; @@ -80,7 +77,8 @@ class DefaultConsumerPomArtifactTransformer implements ConsumerPomArtifactTransf // If there is no build POM there is no reason to inject artifacts for the consumer POM. return; } - if (Features.consumerPom(session.getUserProperties())) { + boolean isModel40 = ModelBuilder.MODEL_VERSION_4_0_0.equals(project.getModelVersion()); + if (Features.consumerPom(session.getUserProperties(), !isModel40)) { Path buildDir = project.getBuild() != null ? Paths.get(project.getBuild().getDirectory()) : null; if (buildDir != null) { @@ -133,14 +131,14 @@ class DefaultConsumerPomArtifactTransformer implements ConsumerPomArtifactTransf } public InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request) { - if (Features.consumerPom(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) { + if (consumerPomPresent(request.getArtifacts())) { request.setArtifacts(replacePom(request.getArtifacts())); } return request; } public DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request) { - if (Features.consumerPom(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) { + if (consumerPomPresent(request.getArtifacts())) { request.setArtifacts(replacePom(request.getArtifacts())); } return request; diff --git a/its/core-it-suite/src/test/resources/mng-7228-leaky-model/pom.xml b/its/core-it-suite/src/test/resources/mng-7228-leaky-model/pom.xml index c5527bac5b..2d620dc7e9 100644 --- a/its/core-it-suite/src/test/resources/mng-7228-leaky-model/pom.xml +++ b/its/core-it-suite/src/test/resources/mng-7228-leaky-model/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project xmlns="http://maven.apache.org/POM/4.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd"> + <modelVersion>4.1.0</modelVersion> <groupId>org.apache.maven.its.mng7228</groupId> <artifactId>test</artifactId> diff --git a/its/core-it-suite/src/test/resources/mng-7836-alternative-pom-syntax/simple/pom.hocon b/its/core-it-suite/src/test/resources/mng-7836-alternative-pom-syntax/simple/pom.hocon index 4a7f1970fd..c5760addb3 100644 --- a/its/core-it-suite/src/test/resources/mng-7836-alternative-pom-syntax/simple/pom.hocon +++ b/its/core-it-suite/src/test/resources/mng-7836-alternative-pom-syntax/simple/pom.hocon @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. # -modelVersion = 4.0.0 +modelVersion = 4.1.0 groupId = org.apache.maven.its.mng-7836 artifactId = hocon-simple version = 1.0.0-SNAPSHOT