Skip to content
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 @@ -273,5 +273,13 @@ public final class Constants {
@Config(type = "java.lang.Integer", defaultValue = "cores/2 + 1")
public static final String MAVEN_PROJECT_BUILDER_PARALLELISM = "maven.projectBuilder.parallelism";

/**
* User property for enabling/disabling the consumer POM feature.
*
* @since 4.0.0
*/
@Config(type = "java.lang.Boolean", defaultValue = "true")
public static final String MAVEN_CONSUMER_POM = "maven.consumer.pom";

private Constants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;

Expand All @@ -32,32 +33,27 @@
*/
public final class Features {

/**
* Name of the Maven user property to enable or disable the build/consumer POM feature.
*/
public static final String BUILDCONSUMER = "maven.buildconsumer";

private Features() {}

/**
* Check if the build/consumer POM feature is active.
* Check if the consumer POM feature is active.
*/
public static boolean buildConsumer(@Nullable Properties userProperties) {
return doGet(userProperties, BUILDCONSUMER, true);
public static boolean consumerPom(@Nullable Properties userProperties) {
return doGet(userProperties, Constants.MAVEN_CONSUMER_POM, true);
}

/**
* Check if the build/consumer POM feature is active.
* Check if the consumer POM feature is active.
*/
public static boolean buildConsumer(@Nullable Map<String, String> userProperties) {
return doGet(userProperties, BUILDCONSUMER, true);
public static boolean consumerPom(@Nullable Map<String, String> userProperties) {
return doGet(userProperties, Constants.MAVEN_CONSUMER_POM, true);
}

/**
* Check if the build/consumer POM feature is active.
* Check if the consumer POM feature is active.
*/
public static boolean buildConsumer(@Nullable Session session) {
return buildConsumer(session != null ? session.getUserProperties() : null);
public static boolean consumerPom(@Nullable Session session) {
return consumerPom(session != null ? session.getUserProperties() : null);
}

private static boolean doGet(Properties userProperties, String key, boolean def) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.feature.Features;
import org.apache.maven.api.model.Activation;
import org.apache.maven.api.model.ActivationFile;
import org.apache.maven.api.model.Build;
Expand Down Expand Up @@ -302,7 +301,8 @@ private Model readEffectiveModel(
problems.setRootModel(inputModel);

ModelData resultData = new ModelData(request.getSource(), inputModel);
String superModelVersion = inputModel.getModelVersion() != null ? inputModel.getModelVersion() : "4.0.0";
String superModelVersion =
inputModel.getModelVersion() != null ? inputModel.getModelVersion() : MODEL_VERSION_4_0_0;
if (!VALID_MODEL_VERSIONS.contains(superModelVersion)) {
// Maven 3.x is always using 4.0.0 version to load the supermodel, so
// do the same when loading a dependency. The model validator will also
Expand Down Expand Up @@ -790,7 +790,7 @@ private ModelData doReadRawModel(
ModelSource modelSource, ModelBuilderRequest request, DefaultModelProblemCollector problems)
throws ModelBuilderException {
Model rawModel = readFileModel(request, problems);
if (Features.buildConsumer(request.getUserProperties()) && modelSource.getPath() != null) {
if (!MODEL_VERSION_4_0_0.equals(rawModel.getModelVersion()) && modelSource.getPath() != null) {
Path pomFile = modelSource.getPath();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ 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.buildConsumer(session.getUserProperties())) {
if (Features.consumerPom(session.getUserProperties())) {
Path buildDir =
project.getBuild() != null ? Paths.get(project.getBuild().getDirectory()) : null;
if (buildDir != null) {
Expand Down Expand Up @@ -133,14 +133,14 @@ private void doDeleteFiles() {
}

public InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request) {
if (Features.buildConsumer(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
if (Features.consumerPom(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
request.setArtifacts(replacePom(request.getArtifacts()));
}
return request;
}

public DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request) {
if (Features.buildConsumer(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
if (Features.consumerPom(session.getUserProperties()) && consumerPomPresent(request.getArtifacts())) {
request.setArtifacts(replacePom(request.getArtifacts()));
}
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.apache.maven.api.Constants;
import org.apache.maven.api.Session;
import org.apache.maven.api.SessionData;
import org.apache.maven.api.feature.Features;
import org.apache.maven.api.model.Build;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.DependencyManagement;
Expand Down Expand Up @@ -541,11 +540,9 @@ List<ProjectBuildingResult> doBuild(List<File> pomFiles, boolean recursive) {
// Phase 2: get effective models from the reactor
List<ProjectBuildingResult> results = build(projectIndex, interimResults);

if (Features.buildConsumer(request.getUserProperties())) {
request.getRepositorySession()
.getData()
.set(ModelTransformerContext.KEY, transformerContextBuilder.build());
}
request.getRepositorySession()
.getData()
.set(ModelTransformerContext.KEY, transformerContextBuilder.build());

return results;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void visitEnd() {
: "java.lang.String")) {
case "java.lang.String" -> "String";
case "java.lang.Integer" -> "Integer";
case "java.lang.Boolean" -> "Boolean";
default -> throw new IllegalStateException();
};
discoveredKeys.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.stream.Stream;

import org.apache.maven.api.VersionRange;
import org.apache.maven.api.feature.Features;
import org.apache.maven.api.model.ActivationFile;
import org.apache.maven.api.model.Exclusion;
import org.apache.maven.api.model.InputSource;
Expand Down Expand Up @@ -97,6 +96,7 @@
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.eclipse.sisu.Nullable;

import static org.apache.maven.api.services.ModelBuilder.MODEL_VERSION_4_0_0;
import static org.apache.maven.model.building.Result.error;
import static org.apache.maven.model.building.Result.newResult;

Expand Down Expand Up @@ -774,12 +774,13 @@ private Model readEffectiveModel(
problems.setRootModel(inputModel);

ModelData resultData = new ModelData(request.getModelSource(), inputModel);
String superModelVersion = inputModel.getModelVersion() != null ? inputModel.getModelVersion() : "4.0.0";
String superModelVersion =
inputModel.getModelVersion() != null ? inputModel.getModelVersion() : MODEL_VERSION_4_0_0;
if (!DefaultModelValidator.VALID_MODEL_VERSIONS.contains(superModelVersion)) {
// Maven 3.x is always using 4.0.0 version to load the supermodel, so
// do the same when loading a dependency. The model validator will also
// check that field later.
superModelVersion = "4.0.0";
superModelVersion = MODEL_VERSION_4_0_0;
}
ModelData superData = new ModelData(null, getSuperModel(superModelVersion));

Expand Down Expand Up @@ -1251,19 +1252,22 @@ private ModelData doReadRawModel(
ModelSource modelSource, ModelBuildingRequest request, DefaultModelProblemCollector problems)
throws ModelBuildingException {
Model rawModel;
if (Features.buildConsumer(request.getUserProperties()) && modelSource instanceof FileModelSource) {
if (modelSource instanceof FileModelSource) {
rawModel = readFileModel(request, problems);
File pomFile = ((FileModelSource) modelSource).getFile();

try {
if (request.getTransformerContextBuilder() != null) {
TransformerContext context =
request.getTransformerContextBuilder().initialize(request, problems);
transformer.transform(pomFile.toPath(), context, rawModel);
if (!MODEL_VERSION_4_0_0.equals(rawModel.getModelVersion())) {
File pomFile = ((FileModelSource) modelSource).getFile();

try {
if (request.getTransformerContextBuilder() != null) {
TransformerContext context =
request.getTransformerContextBuilder().initialize(request, problems);
transformer.transform(pomFile.toPath(), context, rawModel);
}
} catch (TransformerException e) {
problems.add(
new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
}
} catch (TransformerException e) {
problems.add(
new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
}
} else if (request.getFileModel() == null) {
rawModel = readFileModel(request, problems);
Expand Down
Loading