mirror of https://github.com/apache/maven.git
o Added validation error upon bad scope for plugin dependencies
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@808182 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
640380eb49
commit
8ce8b462d0
|
@ -20,6 +20,7 @@ package org.apache.maven.model.validation;
|
|||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -227,6 +228,9 @@ 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 )
|
||||
{
|
||||
|
@ -244,6 +248,13 @@ public class DefaultModelValidator
|
|||
|
||||
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 @@ public class DefaultModelValidator
|
|||
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 )
|
||||
|
|
|
@ -338,4 +338,18 @@ public class DefaultModelValidatorTest
|
|||
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" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue