mirror of https://github.com/apache/maven.git
[MNG-3046] Applying patch to fix compareTo when buildNumber == 0.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@565809 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b1517c1421
commit
219afd51b1
|
@ -60,11 +60,7 @@ public class DefaultArtifactVersion
|
|||
}
|
||||
if ( result == 0 )
|
||||
{
|
||||
if ( buildNumber != null || otherVersion.buildNumber != null )
|
||||
{
|
||||
result = compareIntegers( buildNumber, otherVersion.buildNumber );
|
||||
}
|
||||
else if ( qualifier != null )
|
||||
if ( qualifier != null )
|
||||
{
|
||||
if ( otherVersion.qualifier != null )
|
||||
{
|
||||
|
@ -96,6 +92,10 @@ public class DefaultArtifactVersion
|
|||
// otherVersion has a qualifier but we don't, we're newer
|
||||
result = 1;
|
||||
}
|
||||
else if ( buildNumber != null || otherVersion.buildNumber != null )
|
||||
{
|
||||
result = compareIntegers( buildNumber, otherVersion.buildNumber );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -234,4 +234,32 @@ public class DefaultArtifactVersionTest
|
|||
assertTrue( left + " should be equal to " + right, new DefaultArtifactVersion( left ).compareTo( new DefaultArtifactVersion( right ) ) == 0 );
|
||||
assertTrue( right + " should be equal to " + left, new DefaultArtifactVersion( right ).compareTo( new DefaultArtifactVersion( left ) ) == 0 );
|
||||
}
|
||||
|
||||
public void testVersionComparingWithBuildNumberZero()
|
||||
{
|
||||
DefaultArtifactVersion v1 = new DefaultArtifactVersion("2.0");
|
||||
DefaultArtifactVersion v2 = new DefaultArtifactVersion("2.0-0");
|
||||
DefaultArtifactVersion v3 = new DefaultArtifactVersion("2.0-alpha1");
|
||||
DefaultArtifactVersion v4 = new DefaultArtifactVersion("2.0-1");
|
||||
|
||||
// v1 and v2 are equal
|
||||
assertTrue( v1.compareTo(v2) == 0 );
|
||||
assertTrue( v2.compareTo(v1) == 0 );
|
||||
|
||||
// v1 is newer than v3
|
||||
assertTrue( v1.compareTo(v3) > 0 );
|
||||
assertTrue( v3.compareTo(v1) < 0 );
|
||||
|
||||
// ergo, v2 should also be newer than v3
|
||||
assertTrue( v2.compareTo(v3) > 0 );
|
||||
assertTrue( v3.compareTo(v1) < 0 );
|
||||
|
||||
// nonzero build numbers still respected
|
||||
assertTrue( v1.compareTo(v4) < 0 ); // build number one is always newer
|
||||
assertTrue( v4.compareTo(v1) > 0 );
|
||||
assertTrue( v2.compareTo(v4) < 0 ); // same results as v1
|
||||
assertTrue( v4.compareTo(v2) > 0 );
|
||||
assertTrue( v3.compareTo(v4) < 0 ); // qualifier is always older
|
||||
assertTrue( v4.compareTo(v3) > 0 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue