diff --git a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java index 470f9c4a1f..5b5ab86e7a 100644 --- a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java @@ -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(); @@ -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_(); diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index 16e9d87558..7e843fc7d3 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -171,8 +171,9 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection= 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 ); diff --git a/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java index b13960609f..abdc1d4e43 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -153,8 +153,9 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection= 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 ); diff --git a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index 1f5a9b71e0..64fdd9efbb 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -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 ); diff --git a/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java b/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java index 6292349644..a121d4ae43 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java +++ b/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java @@ -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; @@ -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 updatedVersion = getLowerBound( lowerBound, unchangedSegment ); - lowerBound = updatedVersion.map( helper::createArtifactVersion ).orElse( null ); + Optional 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 ); @@ -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 @@ -494,7 +492,8 @@ 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() ) { @@ -502,10 +501,10 @@ public ArtifactVersion incrementSegment( ArtifactVersion v, int segment ) throws } 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( diff --git a/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java b/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java index 5dbdb2eb3f..32ca0a5cf7 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java +++ b/src/main/java/org/codehaus/mojo/versions/api/UpdateScope.java @@ -26,7 +26,6 @@ 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; @@ -59,9 +58,9 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = currentVersion; + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true ); + return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, false, false ); } catch ( InvalidSegmentException e ) { @@ -80,9 +79,9 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = currentVersion; + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true ); + return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, false, false ); } catch ( InvalidSegmentException e ) { @@ -101,9 +100,9 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2 ); - Restriction restriction = new Restriction( currentVersion, false, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); + ArtifactVersion lowerBound = currentVersion; + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 2, true ); + return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, false, false ); } catch ( InvalidSegmentException e ) { @@ -132,10 +131,9 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true ); + return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -154,10 +152,9 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true ); + return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -176,10 +173,9 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 2, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 1, true ); + return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -208,10 +204,9 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getOldestVersion( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -230,10 +225,9 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getNewestVersion( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -252,10 +246,9 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1 ); - ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, upperBound, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 1, true ); + ArtifactVersion upperBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getVersions( lowerBound, upperBound, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -284,9 +277,8 @@ public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getOldestVersion( lowerBound, null, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -305,9 +297,8 @@ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getNewestVersion( lowerBound, null, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -326,9 +317,8 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV { return null; } - ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0 ); - Restriction restriction = new Restriction( lowerBound, true, null, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); + ArtifactVersion lowerBound = versionComparator.incrementSegment( currentVersion, 0, true ); + return versionDetails.getVersions( lowerBound, null, includeSnapshots, true, false ); } catch ( InvalidSegmentException e ) { @@ -349,24 +339,21 @@ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactV public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, boolean includeSnapshots ) { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getOldestVersion( restriction, includeSnapshots ); + return versionDetails.getOldestVersion( currentVersion, null, includeSnapshots, false, false ); } /** {@inheritDoc} */ public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion, boolean includeSnapshots ) { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getNewestVersion( restriction, includeSnapshots ); + return versionDetails.getNewestVersion( currentVersion, null, includeSnapshots, false, false ); } /** {@inheritDoc} */ public ArtifactVersion[] getAllUpdates( VersionDetails versionDetails, ArtifactVersion currentVersion, boolean includeSnapshots ) { - Restriction restriction = new Restriction( currentVersion, false, null, false ); - return versionDetails.getVersions( restriction, includeSnapshots ); + return versionDetails.getVersions( currentVersion, null, includeSnapshots, false, false ); } }; @@ -577,9 +564,11 @@ public static UpdateScope classifyUpdate( VersionComparator comparator, Artifact for ( int segment = Math.min( comparator.getSegmentCount( from ), comparator.getSegmentCount( to ) ); segment > 0; segment-- ) { - ArtifactVersion f = comparator.incrementSegment( from, segment - 1 ); - f = comparator.incrementSegment( f, segment - 1 ); - ArtifactVersion t = comparator.incrementSegment( to, segment - 1 ); + // 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 ); if ( f.toString().equals( t.toString() ) ) { matchSegment = segment; diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java index afed874df2..a3e9170fd9 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java @@ -56,9 +56,10 @@ public final int getSegmentCount( ArtifactVersion v ) /** * {@inheritDoc} */ - public final ArtifactVersion incrementSegment( ArtifactVersion v, int segment ) throws InvalidSegmentException + public final ArtifactVersion incrementSegment( ArtifactVersion v, int segment, boolean forceSnapshot ) + throws InvalidSegmentException { - if ( VersionComparators.isSnapshot( v ) ) + if ( forceSnapshot || VersionComparators.isSnapshot( v ) ) { return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ), segment ) ); diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/MavenVersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/MavenVersionComparator.java index b0ee00c9cc..21db8cb024 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/MavenVersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/MavenVersionComparator.java @@ -38,7 +38,7 @@ public class MavenVersionComparator */ public int compare( ArtifactVersion o1, ArtifactVersion o2 ) { - return o1.compareTo( o2 ); + return new ComparableVersion( o1.toString() ).compareTo( new ComparableVersion( o2.toString() ) ); } /** diff --git a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java index fbf6fb14e6..bef472cdf9 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java @@ -45,6 +45,23 @@ public interface VersionComparator * @param segment The segment number to increment. * @return An artifact version with the specified segment incremented. * @since 1.0-beta-1 + * @deprecated use {@link #incrementSegment(ArtifactVersion, int, boolean)} instead. */ - ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment ) throws InvalidSegmentException; + default ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment ) + throws InvalidSegmentException + { + return incrementSegment( artifactVersion, segment, false ); + } + + /** + * Increment the specified segment of the supplied version. + * + * @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 true value when creating version boundaries. + * @return An artifact version with the specified segment incremented. + */ + ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment, boolean forceSnapshot ) + throws InvalidSegmentException; } diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java index d691557152..2d4dc259d2 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java @@ -61,6 +61,6 @@ public void testSegmentIncrementing() private void assertIncrement( String expected, String initial, int segment ) throws InvalidSegmentException { assertEquals( expected, - instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( initial ), segment, false ).toString() ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java index deeb70c8ea..4c9493c796 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java @@ -45,20 +45,28 @@ public void testSegmentIncrementing() throws Exception { assertEquals( new DefaultArtifactVersion( "6" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0, false ) + .toString() ); assertEquals( new DefaultArtifactVersion( "6.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0, false ) + .toString() ); assertEquals( new DefaultArtifactVersion( "5.1" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 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 ).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 ).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 ).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 ).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 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1, false ) + .toString() ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java index fc0ac1498d..0b8a19119a 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java @@ -104,20 +104,28 @@ public void testSegmentIncrementing() throws Exception { assertEquals( new DefaultArtifactVersion( "6" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5" ), 0, false ) + .toString() ); assertEquals( new DefaultArtifactVersion( "6.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 0, false ) + .toString() ); assertEquals( new DefaultArtifactVersion( "5.1" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), 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 ).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 ).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 ).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 ).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 ).toString() ); + instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), 1, false ) + .toString() ); } } diff --git a/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java index 06bdbf7f3d..a948ed6187 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorsTest.java @@ -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 ); + ArtifactVersion v2 = instance.incrementSegment( v1, i, false ); assertTrue( v1 + " < " + v2, instance.compare( v1, v2 ) < 0 ); } }