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 16, 2022
1 parent c0ecc66 commit 9a0a4de
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection<Depen
}
try
{
// TODO check whether true can be passed as forceSnapshot parameter.
// TODO check whether true should be passed as forceSnapshot parameter in incrementSegment call.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : null;
getLog().info( "Upper bound: " + ( upperBound == null ? "none" : upperBound.toString() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection<Depende
}
try
{
// TODO check whether true can be passed as forceSnapshot parameter.
// TODO check whether true should be passed as forceSnapshot parameter in incrementSegment call.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : null;
getLog().info( "Upper bound: " + ( upperBound == null ? "none" : upperBound.toString() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ public final ArtifactVersion getOldestVersion( ArtifactVersion lowerBound, Artif
return getOldestVersion( restriction, includeSnapshots );
}

public final ArtifactVersion getOldestVersion( Restriction restriction,
boolean includeSnapshots )
public final ArtifactVersion getOldestVersion( Restriction restriction, boolean includeSnapshots )
{
return getOldestVersion( null, restriction, includeSnapshots );
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.Property;
Expand Down Expand Up @@ -342,25 +343,25 @@ public ArtifactVersion getNewestVersion( String currentVersion, Property propert
? VersionRange.createFromVersionSpec( property.getVersion() ) : null;
helper.getLog().debug( "Property ${" + property.getName() + "}: Restricting results to " + range );

ArtifactVersion lowerBoundArtifactVersion = helper.createArtifactVersion( currentVersion );
ArtifactVersion lowerBound = helper.createArtifactVersion( currentVersion );
if ( allowDowngrade )
{
Optional<String> updatedVersion = getLowerBound( lowerBoundArtifactVersion, unchangedSegment );
lowerBoundArtifactVersion = updatedVersion.map( helper::createArtifactVersion ).orElse( null );
Optional<String> updatedVersion = getLowerBound( lowerBound, unchangedSegment );
lowerBound = updatedVersion.map( helper::createArtifactVersion ).orElse( null );
}
if ( helper.getLog().isDebugEnabled() )
{
helper.getLog().debug( "lowerBoundArtifactVersion: " + lowerBoundArtifactVersion );
helper.getLog().debug( "lowerBoundArtifactVersion: " + lowerBound );
}

ArtifactVersion upperBound = null;
if ( unchangedSegment != -1 )
{
upperBound = getVersionComparator().incrementSegment( lowerBoundArtifactVersion, unchangedSegment, true );
upperBound = getVersionComparator().incrementSegment( lowerBound, unchangedSegment, true );
helper.getLog().debug( "Property ${" + property.getName() + "}: upperBound is: " + upperBound );
}
ArtifactVersion result =
getNewestVersion( range, lowerBoundArtifactVersion, upperBound, includeSnapshots, false, false );
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
ArtifactVersion result = getNewestVersion( range, restriction, includeSnapshots );

helper.getLog().debug( "Property ${" + property.getName() + "}: Current winner is: " + result );

Expand Down Expand Up @@ -427,7 +428,8 @@ private ArtifactVersion getNewestVersion( String currentVersion, VersionsHelper
{
upperBound = getVersionComparator().incrementSegment( lowerBound, segment, true );
}
return getNewestVersion( range, lowerBound, upperBound, includeSnapshots, false, false );
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getNewestVersion( range, restriction, includeSnapshots );
}

private final class PropertyVersionComparator
Expand Down
51 changes: 31 additions & 20 deletions src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;

import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.Restriction;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.ordering.VersionComparator;

Expand Down Expand Up @@ -58,9 +59,9 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV
{
return null;
}
ArtifactVersion lowerBound = currentVersion;
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true );
return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, upperBound, false );
return versionDetails.getOldestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -79,9 +80,9 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV
{
return null;
}
ArtifactVersion lowerBound = currentVersion;
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true );
return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, upperBound, false );
return versionDetails.getNewestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -100,9 +101,9 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV
{
return null;
}
ArtifactVersion lowerBound = currentVersion;
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true );
return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, upperBound, false );
return versionDetails.getVersions( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand Down Expand Up @@ -133,7 +134,8 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true );
return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getOldestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -154,7 +156,8 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true );
return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getNewestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -175,7 +178,8 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true );
return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getVersions( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand Down Expand Up @@ -206,7 +210,8 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getOldestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -227,7 +232,8 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getNewestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -248,7 +254,8 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true );
ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, upperBound, false );
return versionDetails.getVersions( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand Down Expand Up @@ -278,7 +285,8 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV
return null;
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getOldestVersion( lowerBound, null, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, null, false );
return versionDetails.getOldestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -298,7 +306,8 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV
return null;
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getNewestVersion( lowerBound, null, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, null, false );
return versionDetails.getNewestVersion( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -318,7 +327,8 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV
return null;
}
ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true );
return versionDetails.getVersions( lowerBound, null, includeSnapshots, true, false );
Restriction restriction = new Restriction( lowerBound, true, null, false );
return versionDetails.getVersions( restriction, includeSnapshots );
}
catch ( InvalidSegmentException e )
{
Expand All @@ -339,21 +349,24 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV
public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion,
boolean includeSnapshots )
{
return versionDetails.getOldestVersion( currentVersion, null, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, null, false );
return versionDetails.getOldestVersion( restriction, includeSnapshots );
}

/** {@inheritDoc} */
public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion,
boolean includeSnapshots )
{
return versionDetails.getNewestVersion( currentVersion, null, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, null, false );
return versionDetails.getNewestVersion( restriction, includeSnapshots );
}

/** {@inheritDoc} */
public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion,
boolean includeSnapshots )
{
return versionDetails.getVersions( currentVersion, null, includeSnapshots, false, false );
Restriction restriction = new Restriction( currentVersion, false, null, false );
return versionDetails.getVersions( restriction, includeSnapshots );
}

};
Expand Down Expand Up @@ -564,8 +577,6 @@ public static UpdateScope classifyUpdate( VersionComparator comparator, Artifact
for ( int segment =
Math.min( comparator.getSegmentCount( from ), comparator.getSegmentCount( to ) ); segment > 0; segment-- )
{
// TODO check whether true can be passed as forceSnapshot parameter.
// but, can't test since classifyUpdate method is never called
ArtifactVersion f = comparator.incrementSegment( from, segment - 1, false );
f = comparator.incrementSegment( f, segment - 1, false );
ArtifactVersion t = comparator.incrementSegment( to, segment - 1, false );
Expand Down

0 comments on commit 9a0a4de

Please sign in to comment.