mirror of https://github.com/apache/maven.git
if a version part has a leading 0, fallback to string comparison but to retain the extra 0.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@231016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
16bbbbdd91
commit
70eadfd14d
|
@ -163,7 +163,14 @@ public class DefaultArtifactVersion
|
|||
{
|
||||
try
|
||||
{
|
||||
buildNumber = Integer.valueOf( part2 );
|
||||
if ( part2.length() == 1 || !part2.startsWith( "0" ) )
|
||||
{
|
||||
buildNumber = Integer.valueOf( part2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
qualifier = part2;
|
||||
}
|
||||
}
|
||||
catch ( NumberFormatException e )
|
||||
{
|
||||
|
@ -185,37 +192,51 @@ public class DefaultArtifactVersion
|
|||
}
|
||||
else
|
||||
{
|
||||
boolean fallback = false;
|
||||
StringTokenizer tok = new StringTokenizer( part1, "." );
|
||||
try
|
||||
{
|
||||
majorVersion = Integer.valueOf( tok.nextToken() );
|
||||
majorVersion = getNextIntegerToken( tok );
|
||||
if ( tok.hasMoreTokens() )
|
||||
{
|
||||
minorVersion = Integer.valueOf( tok.nextToken() );
|
||||
minorVersion = getNextIntegerToken( tok );
|
||||
}
|
||||
if ( tok.hasMoreTokens() )
|
||||
{
|
||||
incrementalVersion = Integer.valueOf( tok.nextToken() );
|
||||
incrementalVersion = getNextIntegerToken( tok );
|
||||
}
|
||||
if ( tok.hasMoreTokens() )
|
||||
{
|
||||
// qualifier is the whole version, including "-"
|
||||
qualifier = version;
|
||||
majorVersion = null;
|
||||
minorVersion = null;
|
||||
incrementalVersion = null;
|
||||
fallback = true;
|
||||
}
|
||||
}
|
||||
catch ( NumberFormatException e )
|
||||
{
|
||||
fallback = true;
|
||||
}
|
||||
|
||||
if ( fallback )
|
||||
{
|
||||
// qualifier is the whole version, including "-"
|
||||
qualifier = version;
|
||||
majorVersion = null;
|
||||
minorVersion = null;
|
||||
incrementalVersion = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer getNextIntegerToken( StringTokenizer tok )
|
||||
{
|
||||
|
||||
String s = tok.nextToken();
|
||||
if ( s.length() > 1 && s.startsWith( "0" ) )
|
||||
{
|
||||
throw new NumberFormatException( "Number part has a leading 0: '" + s + "'" );
|
||||
}
|
||||
return Integer.valueOf( s );
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
|
|
@ -105,6 +105,13 @@ public class DefaultArtifactVersionTest
|
|||
assertEquals( "check incremental version", 0, version.getIncrementalVersion() );
|
||||
assertEquals( "check build number", 0, version.getBuildNumber() );
|
||||
assertEquals( "check qualifier", "1.7.3.0", version.getQualifier() );
|
||||
|
||||
version = new DefaultArtifactVersion( "0.09" );
|
||||
assertEquals( "check major version", 0, version.getMajorVersion() );
|
||||
assertEquals( "check minor version", 0, version.getMinorVersion() );
|
||||
assertEquals( "check incremental version", 0, version.getIncrementalVersion() );
|
||||
assertEquals( "check build number", 0, version.getBuildNumber() );
|
||||
assertEquals( "check qualifier", "0.09", version.getQualifier() );
|
||||
}
|
||||
|
||||
public void testVersionComparing()
|
||||
|
|
Loading…
Reference in New Issue