You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/11/24 00:58:45 UTC
svn commit: r883551 - in /maven/maven-3/trunk/maven-model-builder/src:
main/java/org/apache/maven/model/validation/
test/java/org/apache/maven/model/validation/ test/resources/poms/validation/
Author: bentmann
Date: Mon Nov 23 23:58:44 2009
New Revision: 883551
URL: http://svn.apache.org/viewvc?rev=883551&view=rev
Log:
o Improved error message in case of empty plugin version (i.e. <version/>, not to be confused with a completely missing <version>)
Added:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml (with props)
Modified:
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=883551&r1=883550&r2=883551&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java Mon Nov 23 23:58:44 2009
@@ -261,10 +261,8 @@
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 @@
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 @@
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;
}
Modified: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=883551&r1=883550&r2=883551&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java Mon Nov 23 23:58:44 2009
@@ -286,6 +286,17 @@
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
{
Added: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml?rev=883551&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml (added)
+++ maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml Mon Nov 23 23:58:44 2009
@@ -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>
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/empty-plugin-version.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision