o Improved error message in case of empty plugin version (i.e. <version/>, not to be confused with a completely missing <version>)

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@883551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-11-23 23:58:44 +00:00
parent 6de5f3f3de
commit b1482a3cb4
3 changed files with 64 additions and 12 deletions

View File

@ -261,10 +261,8 @@ public class DefaultModelValidator
validateStringNotEmpty( "build.plugins.plugin.groupId", problems, Severity.ERROR, p.getGroupId() );
validateStringNotEmpty( "build.plugins.plugin.version", problems, errOn31, p.getVersion(),
p.getKey() );
validatePluginVersion( "build.plugins.plugin.version", problems, errOn30, p.getVersion(), p.getKey() );
validatePluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(),
request );
validateBoolean( "build.plugins.plugin.inherited", problems, errOn30, p.getInherited(),
p.getKey() );
@ -655,27 +653,31 @@ public class DefaultModelValidator
return false;
}
private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, Severity severity, String string,
String sourceHint )
private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string,
String sourceHint, ModelBuildingRequest request )
{
if ( string == null || string.length() <= 0 )
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 ) )
{
return true;
return false;
}
if ( !hasExpression( string ) && !"RELEASE".equals( string ) && !"LATEST".equals( string ) )
if ( string.length() > 0 && !hasExpression( string ) && !"RELEASE".equals( string )
&& !"LATEST".equals( string ) )
{
return true;
}
if ( sourceHint != null )
{
addViolation( problems, severity, "'" + fieldName + "' must be a valid version for " + sourceHint
addViolation( problems, errOn30, "'" + fieldName + "' must be a valid version for " + sourceHint
+ " but is '" + string + "'." );
}
else
{
addViolation( problems, severity, "'" + fieldName + "' must be a valid version but is '" + string + "'." );
addViolation( problems, errOn30, "'" + fieldName + "' must be a valid version but is '" + string + "'." );
}
return false;
@ -693,7 +695,12 @@ public class DefaultModelValidator
private static Severity getSeverity( ModelBuildingRequest request, int errorThreshold )
{
if ( request.getValidationLevel() < errorThreshold )
return getSeverity( request.getValidationLevel(), errorThreshold );
}
private static Severity getSeverity( int validationLevel, int errorThreshold )
{
if ( validationLevel < errorThreshold )
{
return Severity.WARNING;
}

View File

@ -286,6 +286,17 @@ public class DefaultModelValidatorTest
assertViolations( result, 0, 0, 1 );
}
public void testEmptyPluginVersion()
throws Exception
{
SimpleProblemCollector result = validate( "empty-plugin-version.xml" );
assertViolations( result, 0, 1, 0 );
assertEquals( "'build.plugins.plugin.version' must be a valid version "
+ "for org.apache.maven.plugins:maven-it-plugin but is ''.", result.getErrors().get( 0 ) );
}
public void testMissingRepositoryId()
throws Exception
{

View File

@ -0,0 +1,34 @@
<!--
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>foo</artifactId>
<groupId>bar</groupId>
<version>1.0</version>
<packaging>pack</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-it-plugin</artifactId>
<version></version>
</plugin>
</plugins>
</build>
</project>