diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 074ac4a984..a234bb11b3 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.Repository; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.repository.RepositorySystem; @@ -128,7 +129,7 @@ public class DefaultMavenProjectBuilder .setLocalRepository( localRepository ) .setRemoteRepositories( remoteRepositories ); configuration.setProcessPlugins( false ); - configuration.setLenientValidation( true ); + configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); return buildFromRepository( artifact, configuration ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 48913a99c4..36e5299175 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -182,8 +182,7 @@ public class DefaultProjectBuilder configuration.getRemoteRepositories() ); ModelBuildingRequest request = new DefaultModelBuildingRequest(); - request.setValidationLevel( configuration.istLenientValidation() ? ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL - : ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + request.setValidationLevel( configuration.getValidationLevel() ); request.setProcessPlugins( configuration.isProcessPlugins() ); request.setProfiles( configuration.getProfiles() ); request.setActiveProfileIds( configuration.getActiveProfileIds() ); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java index 7b453986be..3d145fd2aa 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilderConfiguration.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.ModelEventListener; @Deprecated @@ -34,6 +35,7 @@ public class DefaultProjectBuilderConfiguration public DefaultProjectBuilderConfiguration() { setProcessPlugins( false ); + setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ); } public ProjectBuilderConfiguration setLocalRepository( ArtifactRepository localRepository ) @@ -66,9 +68,9 @@ public class DefaultProjectBuilderConfiguration return this; } - public ProjectBuilderConfiguration setLenientValidation( boolean lenientValidation ) + public ProjectBuilderConfiguration setValidationLevel( int validationLevel ) { - super.setLenientValidation( lenientValidation ); + super.setValidationLevel( validationLevel ); return this; } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java index 8c8e19df78..41dd23614b 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.ModelEventListener; import org.apache.maven.model.Profile; @@ -41,7 +42,7 @@ public class DefaultProjectBuildingRequest private MavenProject topProject; - private boolean lenientValidation; + private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT; private boolean processPlugins; @@ -167,15 +168,15 @@ public class DefaultProjectBuildingRequest return this; } - public ProjectBuildingRequest setLenientValidation( boolean lenientValidation ) + public ProjectBuildingRequest setValidationLevel( int validationLevel ) { - this.lenientValidation = lenientValidation; + this.validationLevel = validationLevel; return this; } - public boolean istLenientValidation() + public int getValidationLevel() { - return lenientValidation; + return validationLevel; } public List getActiveProfileIds() diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java index d2ad419902..c13374f8a9 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Properties; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.Profile; public interface ProjectBuildingRequest @@ -36,20 +37,18 @@ public interface ProjectBuildingRequest /** * Controls the level of validation to perform on processed models. By default, models are validated in strict mode. * - * @param lenientValidation A flag whether validation should be lenient instead of strict. For building of projects, - * strict validation should be used to ensure proper building. For the mere retrievel of dependencies - * during artifact resolution, lenient validation should be used to account for models of poor quality. + * @param validationLevel The level of validation to perform on processed models, e.g. + * {@link ModelBuildingRequest#VALIDATION_LEVEL_STRICT}. * @return This configuration, never {@code null}. */ - ProjectBuildingRequest setLenientValidation( boolean lenientValidation ); + ProjectBuildingRequest setValidationLevel( int validationLevel ); /** * Gets the level of validation to perform on processed models. * - * @return {@code true} if lenient validation is enabled and only the dependency information is to be validated, - * {@code false} if strict validation is enabled and the entire model is validated. + * @return The level of validation to perform on processed models. */ - boolean istLenientValidation(); + int getValidationLevel(); // Profiles diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 7583fc6f74..724e7f2d93 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -43,6 +43,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Dependency; import org.apache.maven.model.Exclusion; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; @@ -114,7 +115,7 @@ public class MavenMetadataSource ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); configuration.setLocalRepository( localRepository ); configuration.setRemoteRepositories( remoteRepositories ); - configuration.setLenientValidation( true ); + configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL ); // We don't care about processing plugins here, all we're interested in is the dependencies. configuration.setProcessPlugins( false ); // FIXME: We actually need the execution properties here... diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index 65996d4e12..773257b238 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -25,8 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.PluginExecution; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.RepositorySystem; @@ -1678,7 +1678,8 @@ public class PomConstructionTest config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) ); config.setActiveProfileIds( Arrays.asList( profileIds ) ); config.setExecutionProperties( executionProperties ); - config.setLenientValidation( lenientValidation ); + config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 + : ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) ); }