Skip to content

Commit

Permalink
mojohaus#632 Fixed lower and upper bounds to keep milestones and rcs …
Browse files Browse the repository at this point in the history
…in the right majors.
  • Loading branch information
sultan committed Sep 16, 2022
1 parent 44b8e87 commit c210ca2
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,15 @@ else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null )
{
sink.lineBreak();
}
boolean bold = equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.MINOR ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) )
boolean bold =
equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.MAJOR ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) );
|| equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.MINOR ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) )
|| equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) )
|| equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) );
if ( bold )
{
safeBold();
Expand All @@ -444,37 +445,37 @@ else if ( details.getOldestUpdate( UpdateScope.MAJOR ) != null )
safeBold_();
sink.nonBreakingSpace();
safeItalic();
if ( equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) )
if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) ) )
{
sink.text( getText( "report.nextVersion" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) )
{
sink.text( getText( "report.latestSubIncremental" ) );
sink.text( getText( "report.latestMajor" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) ) )
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.MAJOR ) ) )
{
sink.text( getText( "report.nextIncremental" ) );
sink.text( getText( "report.nextMajor" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) ) )
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) ) )
{
sink.text( getText( "report.latestIncremental" ) );
sink.text( getText( "report.latestMinor" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.MINOR ) ) )
{
sink.text( getText( "report.nextMinor" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MINOR ) ) )
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.INCREMENTAL ) ) )
{
sink.text( getText( "report.latestMinor" ) );
sink.text( getText( "report.latestIncremental" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.MAJOR ) ) )
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.INCREMENTAL ) ) )
{
sink.text( getText( "report.nextMajor" ) );
sink.text( getText( "report.nextIncremental" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.MAJOR ) ) )
else if ( equals( versions[i], details.getNewestUpdate( UpdateScope.SUBINCREMENTAL ) ) )
{
sink.text( getText( "report.latestMajor" ) );
sink.text( getText( "report.latestSubIncremental" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( UpdateScope.SUBINCREMENTAL ) ) )
{
sink.text( getText( "report.nextVersion" ) );
}

safeItalic_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection<Depen
}
try
{
// TODO check whether true can be passed as forceSnapshot parameter.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment ) : null;
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : 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 @@ -153,8 +153,9 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection<Depende
}
try
{
// TODO check whether true can be passed as forceSnapshot parameter.
ArtifactVersion upperBound =
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment ) : null;
segment >= 0 ? versionComparator.incrementSegment( lowerBound, segment, false ) : 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 @@ -267,7 +267,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 );
: getVersionComparator().incrementSegment( lowerBound, upperBoundSegment, true );

Restriction restriction = new Restriction( lowerBound, allowDowngrade, upperBound, allowDowngrade );
return getVersions( restriction, includeSnapshots );
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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 @@ -343,25 +342,25 @@ public ArtifactVersion getNewestVersion( String currentVersion, Property propert
? VersionRange.createFromVersionSpec( property.getVersion() ) : null;
helper.getLog().debug( "Property ${" + property.getName() + "}: Restricting results to " + range );

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

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

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

Expand Down Expand Up @@ -426,10 +425,9 @@ private ArtifactVersion getNewestVersion( String currentVersion, VersionsHelper
ArtifactVersion upperBound = null;
if ( segment != -1 )
{
upperBound = getVersionComparator().incrementSegment( lowerBound, segment );
upperBound = getVersionComparator().incrementSegment( lowerBound, segment, true );
}
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getNewestVersion( range, restriction, includeSnapshots );
return getNewestVersion( range, lowerBound, upperBound, includeSnapshots, false, false );
}

private final class PropertyVersionComparator
Expand Down Expand Up @@ -494,18 +492,19 @@ public int getSegmentCount( ArtifactVersion v )
return result;
}

public ArtifactVersion incrementSegment( ArtifactVersion v, int segment ) throws InvalidSegmentException
public ArtifactVersion incrementSegment( ArtifactVersion v, int segment, boolean forceSnapshot )
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 );
ArtifactVersion result = comparators[0].incrementSegment( v, segment, forceSnapshot );
for ( int i = 1; i < comparators.length; i++ )
{
ArtifactVersion alt = comparators[i].incrementSegment( v, segment );
ArtifactVersion alt = comparators[i].incrementSegment( v, segment, forceSnapshot );
if ( !result.toString().equals( alt.toString() ) )
{
throw new IllegalStateException(
Expand Down
Loading

0 comments on commit c210ca2

Please sign in to comment.