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 18, 2022
1 parent a54e87f commit c2a23ed
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/it/it-dependency-updates-report-001/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try
System.out.println( "Result = \"" + result +"\"" );
return false;
}
if ( result.indexOf( "1.1.0-2 Next Version" ) < 0)
if ( result.indexOf( "1.1.0-2 Latest Subincremental" ) < 0)
{
System.out.println( "Did not identify next version" );
System.out.println( "Result = \"" + result +"\"" );
Expand Down
2 changes: 1 addition & 1 deletion src/it/it-plugin-updates-report-001/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ try
return false;
}
if ( result.indexOf( "Group Id localhost Artifact Id dummy-api Current Version 1.1 Classifier Type jar Newer "
+ "versions 1.1.0-2 Next Version 1.1.1 Next Incremental 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 Next "
+ "versions 1.1.0-2 Latest Subincremental 1.1.1 Next Incremental 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 Next "
+ "Minor 1.2.1 1.2.2 1.3 Latest Minor 2.0 Next Major 2.1 3.0 Latest Major" ) < 0)
{
System.out.println( "Did not identify dependency next versions" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.apache.maven.model.Dependency;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.codehaus.mojo.versions.api.AbstractVersionDetails;
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.PropertyVersions;
Expand Down Expand Up @@ -432,57 +433,18 @@ else if ( details.getOldestUpdate( of( MAJOR ) ) != null )
{
sink.lineBreak();
}
boolean bold = equals( versions[i], details.getOldestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( versions[i], details.getNewestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( versions[i], details.getOldestUpdate( of( INCREMENTAL ) ) )
|| equals( versions[i], details.getNewestUpdate( of( INCREMENTAL ) ) )
|| equals( versions[i], details.getOldestUpdate( of( MINOR ) ) )
|| equals( versions[i], details.getNewestUpdate( of( MINOR ) ) )
|| equals( versions[i], details.getOldestUpdate( of( MAJOR ) ) )
|| equals( versions[i], details.getNewestUpdate( of( MAJOR ) ) );
if ( bold )
String label = getLabel( versions[i], details );
if ( label != null )
{
safeBold();
}
sink.text( versions[i].toString() );
if ( bold )
if ( label != null )
{
safeBold_();
sink.nonBreakingSpace();
safeItalic();
if ( equals( versions[i], details.getOldestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextVersion" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestSubIncremental" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextIncremental" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestIncremental" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.nextMinor" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.latestMinor" ) );
}
else if ( equals( versions[i], details.getOldestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.nextMajor" ) );
}
else if ( equals( versions[i], details.getNewestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.latestMajor" ) );
}

sink.text( label );
safeItalic_();
}
}
Expand Down Expand Up @@ -707,65 +669,26 @@ else if ( versions.getOldestUpdate( of( MAJOR ) ) != null )
sink.lineBreak();
}
boolean allowed = ( rangeVersions.contains( artifactVersions[i].toString() ) );
boolean bold = equals( artifactVersions[i], versions.getOldestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( artifactVersions[i], versions.getNewestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( artifactVersions[i], versions.getOldestUpdate( of( INCREMENTAL ) ) )
|| equals( artifactVersions[i], versions.getNewestUpdate( of( INCREMENTAL ) ) )
|| equals( artifactVersions[i], versions.getOldestUpdate( of( MINOR ) ) )
|| equals( artifactVersions[i], versions.getNewestUpdate( of( MINOR ) ) )
|| equals( artifactVersions[i], versions.getOldestUpdate( of( MAJOR ) ) )
|| equals( artifactVersions[i], versions.getNewestUpdate( of( MAJOR ) ) );
String label = getLabel( artifactVersions[i], versions );
if ( !allowed )
{
sink.text( "* " );
someNotAllowed = true;
}
if ( allowed && bold )
if ( allowed && label != null )
{
safeBold();
}
sink.text( artifactVersions[i].toString() );
if ( bold )
if ( label != null )
{
if ( allowed )
{
safeBold_();
}
sink.nonBreakingSpace();
safeItalic();
if ( equals( artifactVersions[i], versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextVersion" ) );
}
else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestSubIncremental" ) );
}
else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextIncremental" ) );
}
else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestIncremental" ) );
}
else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.nextMinor" ) );
}
else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.latestMinor" ) );
}
else if ( equals( artifactVersions[i], versions.getOldestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.nextMajor" ) );
}
else if ( equals( artifactVersions[i], versions.getNewestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.latestMajor" ) );
}

sink.text( label );
safeItalic_();
}
}
Expand Down Expand Up @@ -855,4 +778,42 @@ private Set<String> getVersionsInRange( Property property, PropertyVersions vers
return rangeVersions;
}

protected String getLabel( ArtifactVersion version, AbstractVersionDetails versions )
{
String label = null;
if ( equals( version, versions.getNewestUpdate( of( MAJOR ) ) ) )
{
label = getText( "report.latestMajor" );
}
else if ( equals( version, versions.getOldestUpdate( of( MAJOR ) ) ) )
{
label = getText( "report.nextMajor" );
}
else if ( equals( version, versions.getNewestUpdate( of( MINOR ) ) ) )
{
label = getText( "report.latestMinor" );
}
else if ( equals( version, versions.getOldestUpdate( of( MINOR ) ) ) )
{
label = getText( "report.nextMinor" );
}
else if ( equals( version, versions.getNewestUpdate( of( INCREMENTAL ) ) ) )
{
label = getText( "report.latestIncremental" );
}
else if ( equals( version, versions.getOldestUpdate( of( INCREMENTAL ) ) ) )
{
label = getText( "report.nextIncremental" );
}
else if ( equals( version, versions.getNewestUpdate( of( SUBINCREMENTAL ) ) ) )
{
label = getText( "report.latestSubIncremental" );
}
else if ( equals( version, versions.getOldestUpdate( of( SUBINCREMENTAL ) ) ) )
{
label = getText( "report.nextVersion" );
}
return label;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -436,67 +436,18 @@ else if ( details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) != null )
{
sink.lineBreak();
}
boolean bold = equals(
versions[i], details.getArtifactVersions().getOldestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( versions[i],
details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ) )
|| equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( INCREMENTAL ) ) )
|| equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ) )
|| equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( MINOR ) ) )
|| equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( MINOR ) ) )
|| equals( versions[i], details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) )
|| equals( versions[i], details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ) );
if ( bold )
String label = getLabel( versions[i], details.getArtifactVersions());
if ( label != null )
{
safeBold();
}
sink.text( versions[i].toString() );
if ( bold )
if ( label != null )
{
safeBold_();
sink.nonBreakingSpace();
safeItalic();
if ( equals( versions[i],
details.getArtifactVersions().getOldestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextVersion" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getNewestUpdate( of( SUBINCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestSubIncremental" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getOldestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.nextIncremental" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getNewestUpdate( of( INCREMENTAL ) ) ) )
{
sink.text( getText( "report.latestIncremental" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getOldestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.nextMinor" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getNewestUpdate( of( MINOR ) ) ) )
{
sink.text( getText( "report.latestMinor" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getOldestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.nextMajor" ) );
}
else if ( equals( versions[i],
details.getArtifactVersions().getNewestUpdate( of( MAJOR ) ) ) )
{
sink.text( getText( "report.latestMajor" ) );
}

sink.text( label );
safeItalic_();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ 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 ) : 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 @@ -169,8 +169,9 @@ 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 ) : 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 @@ -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 );
: getVersionComparator().incrementSegment( lowerBound, upperBoundSegment, true );

Restriction restriction = new Restriction( lowerBound, allowDowngrade, upperBound, allowDowngrade );
return getVersions( restriction, includeSnapshots );
Expand Down Expand Up @@ -506,7 +506,7 @@ protected Optional<String> getLowerBound( ArtifactVersion version, int unchanged
* Checks if the candidate version is in the range of the restriction.
* a custom comparator is/can be used to have milestones and rcs before final releases,
* which is not yet possible with {@link Restriction#containsVersion(ArtifactVersion)}.
* @PARAM RESTRICTION THE RANGE TO CHECK AGAINST.
* @param restriction the range to check against.
* @param candidate the version to check.
* @return true if the candidate version is within the range of the restriction parameter.
*/
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() )
? versionComparator.incrementSegment( currentVersion, scope.get().value(), true )
: currentVersion;
ArtifactVersion upperBound = scope.isPresent() && scope.get().value() > Segment.MAJOR.value()
? versionComparator.incrementSegment( currentVersion, scope.get().value() - 1 )
? versionComparator.incrementSegment( currentVersion, scope.get().value() - 1, true )
: 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 );
upperBound = getVersionComparator().incrementSegment( lowerBound, unchangedSegment, true );
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 );
upperBound = getVersionComparator().incrementSegment( lowerBound, segment, true );
}
Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
return getNewestVersion( range, restriction, includeSnapshots );
Expand Down Expand Up @@ -494,18 +494,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 c2a23ed

Please sign in to comment.