Author: bentmann Date: Thu Aug 27 10:57:11 2009 New Revision: 808364 URL: http://svn.apache.org/viewvc?rev=808364&view=rev Log: [MNG-3991] POM validator allows <scope>optional</scope> but it is not valid
Added: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-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=808364&r1=808363&r2=808364&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 Thu Aug 27 10:57:11 2009 @@ -138,6 +138,7 @@ validateStringNotEmpty( "version", problems, false, model.getVersion() ); boolean warnOnBadBoolean = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; + boolean warnOnBadDependencyScope = request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0; for ( Dependency d : model.getDependencies() ) { @@ -177,6 +178,9 @@ { validateBoolean( "dependencies.dependency.optional", problems, warnOnBadBoolean, d.getOptional(), d.getManagementKey() ); + + validateEnum( "dependencies.dependency.scope", problems, warnOnBadDependencyScope, d.getScope(), + d.getManagementKey(), "provided", "compile", "runtime", "test", "system" ); } } @@ -228,9 +232,6 @@ 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 ) { @@ -252,7 +253,7 @@ for ( Dependency d : p.getDependencies() ) { validateEnum( "build.plugins.plugin[" + p.getKey() + "].dependencies.dependency.scope", - problems, warnOnBadPluginDependencyScope, d.getScope(), d.getManagementKey(), + problems, warnOnBadDependencyScope, d.getScope(), d.getManagementKey(), "compile", "runtime", "system" ); } } 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=808364&r1=808363&r2=808364&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 Thu Aug 27 10:57:11 2009 @@ -352,4 +352,16 @@ assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) ); } + public void testBadDependencyScope() + throws Exception + { + SimpleProblemCollector result = validate( "bad-dependency-scope.xml" ); + + assertViolations( result, 2, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:f" ) ); + + assertTrue( result.getErrors().get( 1 ).contains( "test:g" ) ); + } + } Added: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml?rev=808364&view=auto ============================================================================== --- maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml (added) +++ maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml Thu Aug 27 10:57:11 2009 @@ -0,0 +1,69 @@ +<!-- +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> + + <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> + <dependency> + <groupId>test</groupId> + <artifactId>g</artifactId> + <version>0.2</version> + <scope>optional</scope> + </dependency> + </dependencies> +</project> Propchange: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/maven-model-builder/src/test/resources/poms/validation/bad-dependency-scope.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision