Grokbase Groups Maven dev August 2005
FAQ
Author: brett
Date: Tue Aug 9 02:18:08 2005
New Revision: 231016

URL: http://svn.apache.org/viewcvs?rev=231016&view=rev
Log:
if a version part has a leading 0, fallback to string comparison but to retain the extra 0.

Modified:
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java
maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java

Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java?rev=231016&r1=231015&r2=231016&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java Tue Aug 9 02:18:08 2005
@@ -163,7 +163,14 @@
{
try
{
- buildNumber = Integer.valueOf( part2 );
+ if ( part2.length() == 1 || !part2.startsWith( "0" ) )
+ {
+ buildNumber = Integer.valueOf( part2 );
+ }
+ else
+ {
+ qualifier = part2;
+ }
}
catch ( NumberFormatException e )
{
@@ -185,35 +192,49 @@
}
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()

Modified: maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java?rev=231016&r1=231015&r2=231016&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java (original)
+++ maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java Tue Aug 9 02:18:08 2005
@@ -105,6 +105,13 @@
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()



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriesmaven
postedAug 9, '05 at 9:18a
activeAug 9, '05 at 9:18a
posts1
users1
websitemaven.apache.org
irc#maven

1 user in discussion

Brett: 1 post

People

Translate

site design / logo © 2021 Grokbase