[MNG-3991] POM validator allows <scope>optional</scope> but it is not valid

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@808364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-27 10:57:11 +00:00
parent 5ab104e063
commit 3badf71251
3 changed files with 86 additions and 4 deletions

View File

@ -138,6 +138,7 @@ public class DefaultModelValidator
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 @@ public class DefaultModelValidator
{
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 @@ public class DefaultModelValidator
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 @@ public class DefaultModelValidator
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" );
}
}

View File

@ -352,4 +352,16 @@ public class DefaultModelValidatorTest
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" ) );
}
}

View File

@ -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>