From 0a5b7985f64ee169c949f394e860cd2b821fb596 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 25 May 2009 14:27:46 +0000 Subject: [PATCH] [MNG-4173] Remove automatic version resolution for POM plugins o Strengthended model validator to bark with a nice error message before down stream code bubbles up with ugly exceptions. The new validation step applies only to local builds and not to dependency resolution via the metadata source to accept existing POMs git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@778426 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 70 +++++++++---------- .../validation/DefaultModelValidatorTest.java | 11 +++ .../pom.xml | 1 + .../wo-plugin-mngt/pom.xml | 1 + .../wo-plugin-mngt/pom.xml | 1 + .../profile-plugins/pom.xml | 2 + .../missing-plugin-artifactId-pom.xml | 2 +- .../validation/missing-plugin-version-pom.xml | 33 +++++++++ 8 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 maven-core/src/test/resources/validation/missing-plugin-version-pom.xml diff --git a/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index 6d65e98160..5924c1f4a0 100644 --- a/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -153,51 +153,51 @@ public class DefaultModelValidator } } - Build build = model.getBuild(); - if ( build != null ) + if ( !lenient ) { - for ( Plugin p : build.getPlugins() ) + Build build = model.getBuild(); + if ( build != null ) { - validateStringNotEmpty( "build.plugins.plugin.artifactId", result, p.getArtifactId() ); + for ( Plugin p : build.getPlugins() ) + { + validateStringNotEmpty( "build.plugins.plugin.artifactId", result, p.getArtifactId() ); - validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() ); - - /* - * FIXME: Enforce the existence of a version, no more guessing but reproducibility. We can't do this - * right now as it would affect dependency resolution via the metadata source. As a prerequisite, we - * need to tell the validator which level of strictness we want or alternatively disable validation - * completely for the metadata source. - */ + validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() ); + + validateStringNotEmpty( "build.plugins.plugin.version", result, p.getVersion(), p.getKey() ); + } + + for ( Resource r : build.getResources() ) + { + validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() ); + } + + for ( Resource r : build.getTestResources() ) + { + validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() ); + } } - for ( Resource r : build.getResources() ) + Reporting reporting = model.getReporting(); + if ( reporting != null ) { - validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() ); + for ( ReportPlugin p : reporting.getPlugins() ) + { + validateStringNotEmpty( "reporting.plugins.plugin.artifactId", result, p.getArtifactId() ); + + validateStringNotEmpty( "reporting.plugins.plugin.groupId", result, p.getGroupId() ); + + validateStringNotEmpty( "reporting.plugins.plugin.version", result, p.getVersion(), p.getKey() ); + } } - for ( Resource r : build.getTestResources() ) - { - validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() ); - } + validateRepositories( result, model.getRepositories(), "repositories.repository" ); + + // validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" ); + + forcePluginExecutionIdCollision( model, result ); } - Reporting reporting = model.getReporting(); - if ( reporting != null ) - { - for ( ReportPlugin p : reporting.getPlugins()) - { - validateStringNotEmpty( "reporting.plugins.plugin.artifactId", result, p.getArtifactId() ); - - validateStringNotEmpty( "reporting.plugins.plugin.groupId", result, p.getGroupId() ); - } - } - - validateRepositories( result, model.getRepositories(), "repositories.repository" ); - -// validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" ); - - forcePluginExecutionIdCollision( model, result ); - return result; } diff --git a/maven-core/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-core/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index 6049633464..35c48cf262 100644 --- a/maven-core/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -188,6 +188,17 @@ public class DefaultModelValidatorTest assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getMessage( 0 ) ); } + public void testMissingPluginVersion() + throws Exception + { + ModelValidationResult result = validate( "missing-plugin-version-pom.xml" ); + + assertEquals( 1, result.getMessageCount() ); + + assertEquals( "'build.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-it-plugin", + result.getMessage( 0 ) ); + } + public void testMissingRepositoryId() throws Exception { diff --git a/maven-core/src/test/resources-project-builder/execution-configuration-subcollections/pom.xml b/maven-core/src/test/resources-project-builder/execution-configuration-subcollections/pom.xml index 5b65ea6501..e5b19d4ebd 100644 --- a/maven-core/src/test/resources-project-builder/execution-configuration-subcollections/pom.xml +++ b/maven-core/src/test/resources-project-builder/execution-configuration-subcollections/pom.xml @@ -12,6 +12,7 @@ maven-enforcer-plugin + 1.0 diff --git a/maven-core/src/test/resources-project-builder/plugin-config-order/wo-plugin-mngt/pom.xml b/maven-core/src/test/resources-project-builder/plugin-config-order/wo-plugin-mngt/pom.xml index 22a2b810f6..a28796f9e3 100644 --- a/maven-core/src/test/resources-project-builder/plugin-config-order/wo-plugin-mngt/pom.xml +++ b/maven-core/src/test/resources-project-builder/plugin-config-order/wo-plugin-mngt/pom.xml @@ -37,6 +37,7 @@ under the License. org.apache.maven.its.plugins maven-it-plugin-configuration + 1.0 one diff --git a/maven-core/src/test/resources-project-builder/plugin-exec-config-order/wo-plugin-mngt/pom.xml b/maven-core/src/test/resources-project-builder/plugin-exec-config-order/wo-plugin-mngt/pom.xml index 5a5f4c726b..b7a3c31dde 100644 --- a/maven-core/src/test/resources-project-builder/plugin-exec-config-order/wo-plugin-mngt/pom.xml +++ b/maven-core/src/test/resources-project-builder/plugin-exec-config-order/wo-plugin-mngt/pom.xml @@ -37,6 +37,7 @@ under the License. org.apache.maven.its.plugins maven-it-plugin-configuration + 1.0 validate diff --git a/maven-core/src/test/resources-project-builder/profile-plugins/pom.xml b/maven-core/src/test/resources-project-builder/profile-plugins/pom.xml index cc305f9788..24e17530be 100644 --- a/maven-core/src/test/resources-project-builder/profile-plugins/pom.xml +++ b/maven-core/src/test/resources-project-builder/profile-plugins/pom.xml @@ -27,6 +27,7 @@ org.apache.maven.plugins maven-surefire-plugin + 2.4.3 @@ -42,6 +43,7 @@ org.apache.maven.plugins maven-assembly2-plugin + 2.0 diff --git a/maven-core/src/test/resources/validation/missing-plugin-artifactId-pom.xml b/maven-core/src/test/resources/validation/missing-plugin-artifactId-pom.xml index a70205f152..27e27d6b83 100644 --- a/maven-core/src/test/resources/validation/missing-plugin-artifactId-pom.xml +++ b/maven-core/src/test/resources/validation/missing-plugin-artifactId-pom.xml @@ -26,7 +26,7 @@ under the License. - + 1.0 diff --git a/maven-core/src/test/resources/validation/missing-plugin-version-pom.xml b/maven-core/src/test/resources/validation/missing-plugin-version-pom.xml new file mode 100644 index 0000000000..b0ea7aa7f5 --- /dev/null +++ b/maven-core/src/test/resources/validation/missing-plugin-version-pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + foo + foo + 99.44 + bleh + + + + maven-it-plugin + + + +