From 5aa2078ab17c4c8e9f4c552597a2ab228b9fc7fa Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sun, 4 Apr 2010 17:25:00 +0000 Subject: [PATCH] o Improved model validation to ignore super POM for plugin version check git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@930720 13f79535-47bb-0310-9956-ffa450edef68 --- .../model/building/DefaultModelBuilder.java | 55 +++++++++++++++++++ .../validation/DefaultModelValidator.java | 6 +- .../validation/DefaultModelValidatorTest.java | 16 ------ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 9852cd0e36..09d4735ab2 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -30,10 +30,13 @@ import java.util.Map; import java.util.HashMap; import java.util.Properties; +import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Profile; import org.apache.maven.model.Repository; import org.apache.maven.model.building.ModelProblem.Severity; @@ -219,6 +222,9 @@ public class DefaultModelBuilder } } + problems.setSource( inputModel ); + checkPluginVersions( lineage, request, problems ); + assembleInheritance( lineage, request, problems ); Model resultModel = resultData.getModel(); @@ -444,6 +450,55 @@ public class DefaultModelBuilder } } + private void checkPluginVersions( List lineage, ModelBuildingRequest request, + ModelProblemCollector problems ) + { + if ( request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ) + { + return; + } + + Map versions = new HashMap(); + Map managedVersions = new HashMap(); + + for ( int i = 0, n = lineage.size() - 1; i < n; i++ ) + { + Model model = lineage.get( i ).getModel(); + Build build = model.getBuild(); + if ( build != null ) + { + for ( Plugin plugin : build.getPlugins() ) + { + String key = plugin.getKey(); + if ( versions.get( key ) == null ) + { + versions.put( key, plugin.getVersion() ); + } + } + PluginManagement mngt = build.getPluginManagement(); + if ( mngt != null ) + { + for ( Plugin plugin : mngt.getPlugins() ) + { + String key = plugin.getKey(); + if ( managedVersions.get( key ) == null ) + { + managedVersions.put( key, plugin.getVersion() ); + } + } + } + } + } + + for ( String key : versions.keySet() ) + { + if ( versions.get( key ) == null && managedVersions.get( key ) == null ) + { + problems.add( Severity.WARNING, "'build.plugins.plugin.version' for " + key + " is missing.", null ); + } + } + } + private void assembleInheritance( List lineage, ModelBuildingRequest request, ModelProblemCollector problems ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index cda85cd4b6..20c6064bbc 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -671,11 +671,11 @@ public class DefaultModelValidator String sourceHint, ModelBuildingRequest request ) { Severity errOn30 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); - Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ); - if ( !validateNotNull( fieldName, problems, errOn31, string, sourceHint ) ) + if ( string == null ) { - return false; + // NOTE: The check for missing plugin versions is handled directly by the model builder + return true; } if ( string.length() > 0 && !hasExpression( string ) && !"RELEASE".equals( string ) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 9472ffb4af..76297c6e41 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -273,22 +273,6 @@ public class DefaultModelValidatorTest assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) ); } - public void testMissingPluginVersion() - throws Exception - { - SimpleProblemCollector result = - validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 ); - - assertViolations( result, 0, 1, 0 ); - - assertEquals( "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin is missing.", - result.getErrors().get( 0 ) ); - - result = validateEffective( "missing-plugin-version-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 ); - - assertViolations( result, 0, 0, 1 ); - } - public void testEmptyPluginVersion() throws Exception {