diff --git a/src/it/it-dependency-updates-report-001/verify.bsh b/src/it/it-dependency-updates-report-001/verify.bsh index cb1a4a8c77..289ca69b24 100644 --- a/src/it/it-dependency-updates-report-001/verify.bsh +++ b/src/it/it-dependency-updates-report-001/verify.bsh @@ -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 +"\"" ); diff --git a/src/it/it-plugin-updates-report-001/verify.bsh b/src/it/it-plugin-updates-report-001/verify.bsh index 67a272ca2f..003f5155ce 100644 --- a/src/it/it-plugin-updates-report-001/verify.bsh +++ b/src/it/it-plugin-updates-report-001/verify.bsh @@ -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" ); diff --git a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java index e79d29b6f6..7769801caf 100644 --- a/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReportRenderer.java @@ -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; @@ -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_(); } } @@ -707,25 +669,18 @@ 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 ) { @@ -733,39 +688,7 @@ else if ( versions.getOldestUpdate( of( MAJOR ) ) != null ) } 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_(); } } @@ -855,4 +778,42 @@ private Set 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; + } + } diff --git a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java index bf887b8a67..4b27527834 100644 --- a/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java +++ b/src/main/java/org/codehaus/mojo/versions/PluginUpdatesRenderer.java @@ -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_(); } } diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index 7d65fe0349..b024091392 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -187,8 +187,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 255db131e0..6abfad6047 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -169,8 +169,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 2bab33c80a..516439c0a3 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -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 ); @@ -506,7 +506,7 @@ protected Optional 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. */ @@ -539,10 +539,10 @@ protected Restriction restrictionFor( ArtifactVersion currentVersion, Optional 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 ); 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..3ad451e2a8 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java +++ b/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java @@ -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 ); @@ -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 ); @@ -494,7 +494,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 +503,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/VersionDetails.java b/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java index b7aa11b9fe..26e63e4fc1 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/VersionDetails.java @@ -213,7 +213,7 @@ ArtifactVersion getNewestVersion( ArtifactVersion lowerBound, ArtifactVersion up ArtifactVersion getOldestVersion( VersionRange versionRange, Restriction restriction, boolean includeSnapshots ); /** - * Returns the oldest version newer than the specified current version, but within the the specified update scope or + * Returns the oldest version newer than the specified current version, but within the specified update scope or * null if no such version exists. * * @param currentVersion the lower bound or null if the lower limit is unbounded. @@ -227,7 +227,7 @@ ArtifactVersion getOldestUpdate( ArtifactVersion currentVersion, Optionalnull if no such version exists. * * @param currentVersion the lower bound or null if the lower limit is unbounded. @@ -241,7 +241,7 @@ ArtifactVersion getNewestUpdate( ArtifactVersion currentVersion, Optionalnull if the lower limit is unbounded. * @param updateScope the update scope to include. @@ -289,7 +289,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optionalnull if no such version exists. * * @param updateScope the update scope to include. @@ -300,7 +300,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope ) throws InvalidSegmentException; /** - * Returns the newest version newer than the specified current version, but within the the specified update scope or + * Returns the newest version newer than the specified current version, but within the specified update scope or * null if no such version exists. * * @param updateScope the update scope to include. @@ -311,7 +311,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope ) throws InvalidSegmentException; /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. + * Returns the all versions newer than the specified current version, but within the specified update scope. * * @param updateScope the update scope to include. * @return the all versions after currentVersion within the specified update scope. @@ -320,7 +320,7 @@ ArtifactVersion[] getAllUpdates( ArtifactVersion currentVersion, Optional updateScope ) throws InvalidSegmentException; /** - * Returns the oldest version newer than the specified current version, but within the the specified update scope or + * Returns the oldest version newer than the specified current version, but within the specified update scope or * null if no such version exists. * * @param updateScope the update scope to include. @@ -333,7 +333,7 @@ ArtifactVersion getOldestUpdate( Optional updateScope, boolean includeS throws InvalidSegmentException; /** - * Returns the newest version newer than the specified current version, but within the the specified update scope or + * Returns the newest version newer than the specified current version, but within the specified update scope or * null if no such version exists. * * @param updateScope the update scope to include. @@ -346,7 +346,7 @@ ArtifactVersion getNewestUpdate( Optional updateScope, boolean includeS throws InvalidSegmentException; /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. + * Returns the all versions newer than the specified current version, but within the specified update scope. * * @param updateScope the update scope to include. * @param includeSnapshots true if snapshots are to be included. @@ -357,7 +357,7 @@ ArtifactVersion[] getAllUpdates( Optional updateScope, boolean includeS throws InvalidSegmentException; /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. + * Returns the all versions newer than the specified current version, but within the specified update scope. * * @param versionRange the version range to include. * @return the all versions after currentVersion within the specified update scope. @@ -366,7 +366,7 @@ ArtifactVersion[] getAllUpdates( Optional updateScope, boolean includeS ArtifactVersion[] getAllUpdates( VersionRange versionRange ); /** - * Returns the all versions newer than the specified current version, but within the the specified update scope. + * Returns the all versions newer than the specified current version, but within the specified update scope. * * @param versionRange the version range to include. * @param includeSnapshots true if snapshots are to be included. 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/ComparableVersion.java b/src/main/java/org/codehaus/mojo/versions/ordering/ComparableVersion.java index 6b944ce9af..9cb107f6a3 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/ComparableVersion.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/ComparableVersion.java @@ -127,7 +127,8 @@ public String toString() private static class StringItem implements Item { - private static final String[] QUALIFIERS = {"snapshot", "alpha", "beta", "milestone", "rc", "", "sp"}; + private static final String[] QUALIFIERS = { + "snapshot", "alpha", "beta", "milestone", "preview", "rc", "", "sp" }; private static final List QUALIFIERS_LIST = Arrays.asList( QUALIFIERS ); @@ -135,9 +136,10 @@ private static class StringItem static { - ALIASES.put( "ga", "" ); - ALIASES.put( "final", "" ); + ALIASES.put( "mr", "milestone" ); ALIASES.put( "cr", "rc" ); + ALIASES.put( "final", "" ); + ALIASES.put( "ga", "" ); } /** 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 11f2af07f3..7eda5129c9 100644 --- a/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java +++ b/src/main/java/org/codehaus/mojo/versions/ordering/VersionComparator.java @@ -43,9 +43,12 @@ 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 true 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) */ - ArtifactVersion incrementSegment( ArtifactVersion artifactVersion, int segment ) throws InvalidSegmentException; + 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 ); } }