Skip to content
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

[MNG-8393] Enable consumer pom by default for 4.1.0 model version only #1963

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Properties;

import org.apache.maven.api.Constants;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Nullable;

/**
Expand All @@ -45,15 +44,8 @@ public static boolean consumerPom(@Nullable Properties userProperties) {
/**
* 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) {
Expand Down
10 changes: 0 additions & 10 deletions impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
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;
Expand Down Expand Up @@ -415,15 +414,6 @@ private boolean isRegularFile(Artifact artifact) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
*/
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

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;
Expand All @@ -57,10 +58,6 @@
@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";
Expand All @@ -80,7 +77,8 @@ public void injectTransformedArtifacts(RepositorySystemSession session, MavenPro
// 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) {
Expand Down Expand Up @@ -133,14 +131,14 @@ private void doDeleteFiles() {
}

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading