Skip to content

Commit abd933f

Browse files
committed
[MNG-7644] Fix version comparison ( .RC1 < -RC2 )
1 parent 7d45894 commit abd933f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,14 @@ else if ( Character.isDigit( c ) )
676676
{
677677
if ( !isDigit && i > startIndex )
678678
{
679+
// 1.0.0.RC1 < 1.0.0-RC2
680+
// treat .RC as -RC
681+
if ( !list.isEmpty() )
682+
{
683+
list.add( list = new ListItem() );
684+
stack.push( list );
685+
}
686+
679687
list.add( new StringItem( version.substring( startIndex, i ), true ) );
680688
startIndex = i;
681689

@@ -702,6 +710,14 @@ else if ( Character.isDigit( c ) )
702710

703711
if ( version.length() > startIndex )
704712
{
713+
// 1.0.0.RC1 < 1.0.0-RC2
714+
// treat .RC as -RC
715+
if ( !isDigit && !list.isEmpty() )
716+
{
717+
list.add( list = new ListItem() );
718+
stack.push( list );
719+
}
720+
705721
list.add( parseItem( isDigit, version.substring( startIndex ) ) );
706722
}
707723

maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private Comparable newComparable( String version )
5151
"1-1", "1-2", "1-123" };
5252

5353
private static final String[] VERSIONS_NUMBER =
54-
{ "2.0", "2-1", "2.0.a", "2.0.0.a", "2.0.2", "2.0.123", "2.1.0", "2.1-a", "2.1b", "2.1-c", "2.1-1", "2.1.0.1",
55-
"2.2", "2.123", "11.a2", "11.a11", "11.b2", "11.b11", "11.m2", "11.m11", "11", "11.a", "11b", "11c", "11m" };
54+
{ "2.0", "2.0.a", "2-1", "2.0.2", "2.0.123", "2.1.0", "2.1-a", "2.1b", "2.1-c", "2.1-1", "2.1.0.1", "2.2",
55+
"2.123", "11.a2", "11.a11", "11.b2", "11.b11", "11.m2", "11.m11", "11", "11.a", "11b", "11c", "11m" };
5656

5757
private void checkVersionsOrder( String[] versions )
5858
{
@@ -337,4 +337,14 @@ public void testReuse()
337337

338338
assertEquals( "reused instance should be equivalent to new instance", c1, c2 );
339339
}
340+
341+
/**
342+
* Test <a href="https://issues.apache.org/jira/browse/MNG-7644">MNG-7644</a> edge cases
343+
* 1.0.0.RC1 < 1.0.0-RC2
344+
*/
345+
public void testMng7644()
346+
{
347+
checkVersionsOrder( "1.0.0.RC1", "1.0.0-RC2" );
348+
checkVersionsEqual( "2.0.a", "2.0.0.a" ); // previously ordered, now equals
349+
}
340350
}

0 commit comments

Comments
 (0)