Skip to content

Commit

Permalink
#632 Fixed lower and upper bounds to keep milestones and rcs in the r…
Browse files Browse the repository at this point in the history
…ight majors.
  • Loading branch information
sultan committed Sep 18, 2022
1 parent 2fc0d46 commit 1c11ef6
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection<Depen
}
try
{
// TODO check whether true should be passed as forceSnapshot parameter in incrementSegment call.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : null;
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment ) : null;
getLog().info( "Upper bound: " + ( upperBound == null ? "none" : upperBound.toString() ) );
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
ArtifactVersion[] newer = versions.getVersions( restriction, true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection<Depende
}
try
{
// TODO check whether true should be passed as forceSnapshot parameter in incrementSegment call.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : null;
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment ) : null;
getLog().info( "Upper bound: " + ( upperBound == null ? "none" : upperBound.toString() ) );
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
ArtifactVersion[] newer = versions.getVersions( restriction, true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public final ArtifactVersion[] getNewerVersions( String versionString, int upper
ArtifactVersion lowerBound =
allowDowngrade ? getLowerBoundArtifactVersion( currentVersion, upperBoundSegment ) : currentVersion;
ArtifactVersion upperBound = upperBoundSegment == -1 ? null
: getVersionComparator().incrementSegment( lowerBound, upperBoundSegment, true );
: getVersionComparator().incrementSegment( lowerBound, upperBoundSegment );

Restriction restriction = new Restriction( lowerBound, allowDowngrade, upperBound, allowDowngrade );
return getVersions( restriction, includeSnapshots );
Expand Down Expand Up @@ -539,10 +539,10 @@ protected Restriction restrictionFor( ArtifactVersion currentVersion, Optional<S
{
VersionComparator versionComparator = getVersionComparator();
ArtifactVersion lowerBound = scope.isPresent() && scope.get().value() < Segment.SUBINCREMENTAL.value()
? versionComparator.incrementSegment( currentVersion, scope.get().value(), true )
? versionComparator.incrementSegment( currentVersion, scope.get().value() )
: currentVersion;
ArtifactVersion upperBound = scope.isPresent() && scope.get().value() > Segment.MAJOR.value()
? versionComparator.incrementSegment( currentVersion, scope.get().value() - 1, true )
? versionComparator.incrementSegment( currentVersion, scope.get().value() - 1 )
: null;
return new Restriction( lowerBound, lowerBound != currentVersion,
upperBound, false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public ArtifactVersion getNewestVersion( String currentVersion, Property propert
ArtifactVersion upperBound = null;
if ( unchangedSegment != -1 )
{
upperBound = getVersionComparator().incrementSegment( lowerBound, unchangedSegment, true );
upperBound = getVersionComparator().incrementSegment( lowerBound, unchangedSegment );
helper.getLog().debug( "Property ${" + property.getName() + "}: upperBound is: " + upperBound );
}
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
Expand Down Expand Up @@ -426,7 +426,7 @@ private ArtifactVersion getNewestVersion( String currentVersion, VersionsHelper
ArtifactVersion upperBound = null;
if ( segment != -1 )
{
upperBound = getVersionComparator().incrementSegment( lowerBound, segment, true );
upperBound = getVersionComparator().incrementSegment( lowerBound, segment );
}
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getNewestVersion( range, restriction, includeSnapshots );
Expand Down Expand Up @@ -494,19 +494,18 @@ public int getSegmentCount( ArtifactVersion v )
return result;
}

public ArtifactVersion incrementSegment( ArtifactVersion v, int segment, boolean forceSnapshot )
throws InvalidSegmentException
public ArtifactVersion incrementSegment( ArtifactVersion v, int segment ) throws InvalidSegmentException
{
if ( !isAssociated() )
{
throw new IllegalStateException( "Cannot compare versions for a property with no associations" );
}
VersionComparator[] comparators = lookupComparators();
assert comparators.length >= 1 : "we have at least one association => at least one comparator";
ArtifactVersion result = comparators[0].incrementSegment( v, segment, forceSnapshot );
ArtifactVersion result = comparators[0].incrementSegment( v, segment );
for ( int i = 1; i < comparators.length; i++ )
{
ArtifactVersion alt = comparators[i].incrementSegment( v, segment, forceSnapshot );
ArtifactVersion alt = comparators[i].incrementSegment( v, segment );
if ( !result.toString().equals( alt.toString() ) )
{
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,10 @@ public final int getSegmentCount( ArtifactVersion v )
/**
* {@inheritDoc}
*/
public final ArtifactVersion incrementSegment( ArtifactVersion v, int segment, boolean forceSnapshot )
throws InvalidSegmentException
public final ArtifactVersion incrementSegment( ArtifactVersion v, int segment ) throws InvalidSegmentException
{
if ( forceSnapshot || VersionComparators.isSnapshot( v ) )
{
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
segment ) );
}
return innerIncrementSegment( v, segment );
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
segment ) );
}

protected abstract ArtifactVersion innerIncrementSegment( ArtifactVersion v, int segment )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ public interface VersionComparator
*
* @param artifactVersion The artifact version to increment.
* @param segment The segment number to increment.
* @param forceSnapshot whether the target version must be snapshot regardless.
* send <code>true</code> value when creating version boundaries.
* @return An artifact version with the specified segment incremented.
* @since 1.0-beta-1
* @throws InvalidSegmentException if {@code segment} ∉ [0, segmentCount)
* @since 1.0-beta-1
*/
ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment, boolean forceSnapshot )
throws InvalidSegmentException;
ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment ) throws InvalidSegmentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public void testSegmentIncrementing()
assertIncrement( "5.alpha-1.2", "5.alpha-1.1", 0 );
assertIncrement( "5.alpha-1.ba", "5.alpha-1.az", 0 );
assertIncrement( "5.alpha-wins.2", "5.alpha-wins.1", 0 );
assertIncrement( "1.0-alpha-3-SNAPSHOT", "1.0-alpha-2-SNAPSHOT", 3 );
assertIncrement( "1.0-alpha-90-SNAPSHOT", "1.0-alpha-9-SNAPSHOT", 3 );
assertIncrement( "1.0-za-SNAPSHOT", "1.0-z-SNAPSHOT", 3 );
assertIncrement( "1.0-z90-SNAPSHOT", "1.0-z9-SNAPSHOT", 3 );
assertIncrement( "1.0-alpha-3", "1.0-alpha-2-SNAPSHOT", 3 );
assertIncrement( "1.0-alpha-90", "1.0-alpha-9-SNAPSHOT", 3 );
assertIncrement( "1.0-za", "1.0-z-SNAPSHOT", 3 );
assertIncrement( "1.0-z90", "1.0-z9-SNAPSHOT", 3 );
}

private void assertIncrement( String expected, String initial, int segment ) throws InvalidSegmentException
{
assertEquals( expected,
instance.incrementSegment( new DefaultArtifactVersion( initial ), segment, false ).toString() );
assertEquals( expected + "-SNAPSHOT",
instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,19 @@ public void testSegmentCounting()
public void testSegmentIncrementing()
throws Exception
{
assertEquals( new DefaultArtifactVersion( "6" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 2, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1, false )
.toString() );
assertIncrement( "6", "5", 0 );
assertIncrement( "6.0", "5.0", 0 );
assertIncrement( "5.1", "5.0", 1 );
assertIncrement( "5.1.0", "5.0.1", 1 );
assertIncrement( "5.beta.0", "5.alpha.1", 1 );
assertIncrement( "5.beta-0.0", "5.alpha-1.1", 1 );
assertIncrement( "5.alpha-2.0", "5.alpha-1.1", 2 );
assertIncrement( "5.beta-0.0", "5.alpha-wins.1", 1 );
}

private void assertIncrement( String expected, String initial, int segment ) throws InvalidSegmentException
{
assertEquals( expected + "-SNAPSHOT",
instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,19 @@ public void testSegmentCounting()
public void testSegmentIncrementing()
throws Exception
{
assertEquals( new DefaultArtifactVersion( "6" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "6.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.1" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 1, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.alpha-1.2" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), 2, false )
.toString() );
assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(),
instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1, false )
.toString() );
assertIncrement( "6", "5", 0 );
assertIncrement( "6.0", "5.0", 0 );
assertIncrement( "5.1", "5.0", 1 );
assertIncrement( "5.1.0", "5.0.1", 1 );
assertIncrement( "5.beta.0", "5.alpha.1", 1 );
assertIncrement( "5.alpha-2.0", "5.alpha-1.1", 1 );
assertIncrement( "5.alpha-1.2", "5.alpha-1.1", 2 );
assertIncrement( "5.beta.0", "5.alpha-wins.1", 1 );
}

private void assertIncrement( String expected, String initial, int segment ) throws InvalidSegmentException
{
assertEquals( expected + "-SNAPSHOT",
instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void assertLater( String version, VersionComparator instance ) throws Inv
int count = instance.getSegmentCount( v1 );
for ( int i = 0; i < count; i++ )
{
ArtifactVersion v2 = instance.incrementSegment( v1, i, false );
ArtifactVersion v2 = instance.incrementSegment( v1, i );
assertTrue( v1 + " < " + v2, instance.compare( v1, v2 ) < 0 );
}
}
Expand Down

0 comments on commit 1c11ef6

Please sign in to comment.