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 @@ -87,6 +87,7 @@
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.model.resolution.WorkspaceModelResolver;
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.model.validation.DefaultModelValidator;
import org.apache.maven.model.validation.ModelValidator;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
Expand Down Expand Up @@ -747,6 +748,12 @@ private Model readEffectiveModel(

ModelData resultData = new ModelData(request.getModelSource(), inputModel);
String superModelVersion = inputModel.getModelVersion() != null ? inputModel.getModelVersion() : "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";
}
ModelData superData = new ModelData(null, getSuperModel(superModelVersion));

// profile activation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -67,6 +68,9 @@
@Singleton
public class DefaultModelValidator implements ModelValidator {

public static final List<String> VALID_MODEL_VERSIONS =
Collections.unmodifiableList(Arrays.asList("4.0.0", "4.1.0"));

private static final Pattern EXPRESSION_NAME_PATTERN = Pattern.compile("\\$\\{(.+?)}");
private static final Pattern EXPRESSION_PROJECT_NAME_PATTERN = Pattern.compile("\\$\\{(project.+?)}");

Expand Down Expand Up @@ -147,7 +151,7 @@ public void validateFileModel(Model ma, ModelBuildingRequest request, ModelProbl
// The file pom may not contain the modelVersion yet, as it may be set later by the
// ModelVersionXMLFilter.
if (m.getModelVersion() != null && !m.getModelVersion().isEmpty()) {
validateModelVersion(problems, m.getModelVersion(), m, "4.0.0", "4.1.0");
validateModelVersion(problems, m.getModelVersion(), m, VALID_MODEL_VERSIONS);
}

validateStringNoExpression("groupId", problems, Severity.WARNING, Version.V20, m.getGroupId(), m);
Expand Down Expand Up @@ -261,7 +265,7 @@ public void validateRawModel(Model ma, ModelBuildingRequest request, ModelProble
// models without a version starting with 3.4.
validateStringNotEmpty("modelVersion", problems, Severity.ERROR, Version.V20, m.getModelVersion(), m);

validateModelVersion(problems, m.getModelVersion(), m, "4.0.0", "4.1.0");
validateModelVersion(problems, m.getModelVersion(), m, VALID_MODEL_VERSIONS);

String minVersion = new MavenModelVersion().getModelVersion(m);
if (m.getModelVersion() != null && compareModelVersions(minVersion, m.getModelVersion()) > 0) {
Expand Down Expand Up @@ -1478,14 +1482,12 @@ private boolean validateEnum(

@SuppressWarnings("checkstyle:parameternumber")
private boolean validateModelVersion(
ModelProblemCollector problems, String string, InputLocationTracker tracker, String... validVersions) {
ModelProblemCollector problems, String string, InputLocationTracker tracker, List<String> validVersions) {
if (string == null || string.length() <= 0) {
return true;
}

List<String> values = Arrays.asList(validVersions);

if (values.contains(string)) {
if (validVersions.contains(string)) {
return true;
}

Expand All @@ -1504,8 +1506,8 @@ private boolean validateModelVersion(
Version.V20,
"modelVersion",
null,
"of '" + string + "' is newer than the versions supported by this version of Maven: " + values
+ ". Building this project requires a newer version of Maven.",
"of '" + string + "' is newer than the versions supported by this version of Maven: "
+ validVersions + ". Building this project requires a newer version of Maven.",
tracker);

} else if (olderThanAll) {
Expand All @@ -1516,8 +1518,8 @@ private boolean validateModelVersion(
Version.V20,
"modelVersion",
null,
"of '" + string + "' is older than the versions supported by this version of Maven: " + values
+ ". Building this project requires an older version of Maven.",
"of '" + string + "' is older than the versions supported by this version of Maven: "
+ validVersions + ". Building this project requires an older version of Maven.",
tracker);

} else {
Expand All @@ -1527,7 +1529,7 @@ private boolean validateModelVersion(
Version.V20,
"modelVersion",
null,
"must be one of " + values + " but is '" + string + "'.",
"must be one of " + validVersions + " but is '" + string + "'.",
tracker);
}

Expand Down