[MNG-4957] Emit validation warning when project version uses irregular SNAPSHOT version string

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1054743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-01-03 20:45:41 +00:00
parent 469d0096fd
commit be26167029
3 changed files with 54 additions and 0 deletions

View File

@ -273,6 +273,7 @@ public class DefaultModelValidator
validateBannedCharacters( "version", problems, errOn31, model.getVersion(), null, model,
ILLEGAL_VERSION_CHARS );
validateProperSnapshotVersion( "version", problems, errOn31, model.getVersion(), null, model );
Build build = model.getBuild();
if ( build != null )
@ -789,6 +790,24 @@ public class DefaultModelValidator
return true;
}
private boolean validateProperSnapshotVersion( String fieldName, ModelProblemCollector problems, Severity severity,
String string, String sourceHint, InputLocationTracker tracker )
{
if ( string == null || string.length() <= 0 )
{
return true;
}
if ( string.endsWith( "SNAPSHOT" ) && !string.endsWith( "-SNAPSHOT" ) )
{
addViolation( problems, severity, fieldName, sourceHint, "uses an unsupported snapshot version format"
+ ", should be '*-SNAPSHOT' instead.", tracker );
return false;
}
return true;
}
private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string,
String sourceHint, InputLocationTracker tracker,
ModelBuildingRequest request )

View File

@ -526,6 +526,16 @@ public class DefaultModelValidatorTest
assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of these characters" );
}
public void testBadSnapshotVersion()
throws Exception
{
SimpleProblemCollector result = validate( "bad-snapshot-version.xml" );
assertViolations( result, 0, 0, 1 );
assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot version format" );
}
public void testBadRepositoryId()
throws Exception
{

View File

@ -0,0 +1,25 @@
<!--
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>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.2.3.SNAPSHOT</version>
</project>