Author: bentmann Date: Wed Aug 26 20:48:48 2009 New Revision: 808182 URL: http://svn.apache.org/viewvc?rev=808182&view=rev Log: o Added validation error upon bad scope for plugin dependencies
Added: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml (with props) Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=808182&r1=808181&r2=808182&view=diff ============================================================================== --- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java (original) +++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java Wed Aug 26 20:48:48 2009 @@ -20,6 +20,7 @@ */ import java.io.File; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -227,6 +228,9 @@ boolean warnOnMissingPluginVersion = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1; + boolean warnOnBadPluginDependencyScope = + request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; + Build build = model.getBuild(); if ( build != null ) { @@ -244,6 +248,13 @@ validateBoolean( "build.plugins.plugin.extensions", problems, warnOnBadBoolean, p.getExtensions(), p.getKey() ); + + for ( Dependency d : p.getDependencies() ) + { + validateEnum( "build.plugins.plugin[" + p.getKey() + "].dependencies.dependency.scope", + problems, warnOnBadPluginDependencyScope, d.getScope(), d.getManagementKey(), + "compile", "runtime", "system" ); + } } validateResources( problems, build.getResources(), "build.resources.resource", request ); @@ -542,6 +553,33 @@ return false; } + private boolean validateEnum( String fieldName, ModelProblemCollector problems, boolean warning, String string, + String sourceHint, String... validValues ) + { + if ( string == null || string.length() <= 0 ) + { + return true; + } + + List<String> values = Arrays.asList( validValues ); + + if ( values.contains( string ) ) + { + return true; + } + + if ( sourceHint != null ) + { + addViolation( problems, warning, "'" + fieldName + "' must be one of " + values + " for " + sourceHint ); + } + else + { + addViolation( problems, warning, "'" + fieldName + "' must be one of " + values ); + } + + return false; + } + private void addViolation( ModelProblemCollector problems, boolean warning, String message ) { if ( warning ) Modified: maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=808182&r1=808181&r2=808182&view=diff ============================================================================== --- maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java (original) +++ maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java Wed Aug 26 20:48:48 2009 @@ -338,4 +338,18 @@ assertEquals( "'build.testResources.testResource.directory' is missing.", result.getErrors().get( 1 ) ); } + public void testBadPluginDependencyScope() + throws Exception + { + SimpleProblemCollector result = validate( "bad-plugin-dependency-scope.xml" ); + + assertViolations( result, 3, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:d" ) ); + + assertTrue( result.getErrors().get( 1 ).contains( "test:e" ) ); + + assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) ); + } + } Added: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml?rev=808182&view=auto ============================================================================== --- maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml (added) +++ maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml Wed Aug 26 20:48:48 2009 @@ -0,0 +1,70 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + <artifactId>aid</artifactId> + <groupId>gid</groupId> + <version>0.1</version> + <build> + <plugins> + <plugin> + <artifactId>maven-it-plugin</artifactId> + <version>0.1</version> + <dependencies> + <dependency> + <groupId>test</groupId> + <artifactId>a</artifactId> + <version>0.2</version> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>b</artifactId> + <version>0.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>c</artifactId> + <version>0.2</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>d</artifactId> + <version>0.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>e</artifactId> + <version>0.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>test</groupId> + <artifactId>f</artifactId> + <version>0.2</version> + <scope>import</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> Propchange: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-scope.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision