Skip to content

Commit

Permalink
[MNG-4957] Emit validation warning when project version uses irregula…
Browse files Browse the repository at this point in the history
…r SNAPSHOT version string

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1054743 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bentmann committed Jan 3, 2011
1 parent 469d009 commit be26167
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public void validateEffectiveModel( Model model, ModelBuildingRequest request, M

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 )
Expand Down Expand Up @@ -789,6 +790,24 @@ private boolean validateVersion( String fieldName, ModelProblemCollector problem
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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ public void testBadVersion()
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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit be26167

Please sign in to comment.