From 6b7d3b8b96604c65a1dd909d58dc753c4867e3fd Mon Sep 17 00:00:00 2001 From: Swell <5782559+sultan@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:17:29 +0200 Subject: [PATCH] #632 Fixed lower and upper bounds to keep milestones and rcs in the right majors. --- .../verify.bsh | 2 +- .../it-plugin-updates-report-001/verify.bsh | 2 +- .../AbstractVersionsReportRenderer.java | 133 +++++++----------- .../mojo/versions/PluginUpdatesRenderer.java | 57 +------- .../versions/api/AbstractVersionDetails.java | 2 +- .../mojo/versions/api/VersionDetails.java | 22 +-- .../versions/ordering/ComparableVersion.java | 8 +- .../ordering/MavenVersionComparator.java | 2 +- .../ordering/MavenVersionComparatorTest.java | 15 +- .../MercuryVersionComparatorTest.java | 39 +++-- .../NumericVersionComparatorTest.java | 35 +++-- 11 files changed, 112 insertions(+), 205 deletions(-) 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..819cf38d8f 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/api/AbstractVersionDetails.java b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java index e846a20914..8f0fff4f1f 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java +++ b/src/main/java/org/codehaus/mojo/versions/api/AbstractVersionDetails.java @@ -507,7 +507,7 @@ protected Optional getLowerBound( ArtifactVersion version, Optionalnull 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/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 db6444ff49..c0bc1c2682 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 extends AbstractVersionComparator */ 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/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java index 4aed2cf78b..4b520f7c28 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/MavenVersionComparatorTest.java @@ -45,8 +45,7 @@ public void testSegmentCounting() } @Test - public void testSegmentIncrementing() - throws InvalidSegmentException + public void testSegmentIncrementing() throws InvalidSegmentException { assertIncrement( "6", "5", MAJOR ); assertIncrement( "6.0", "5.0", MAJOR ); @@ -56,15 +55,15 @@ public void testSegmentIncrementing() assertIncrement( "5.alpha-1.2", "5.alpha-1.1", MAJOR ); assertIncrement( "5.alpha-1.ba", "5.alpha-1.az", MAJOR ); assertIncrement( "5.alpha-wins.2", "5.alpha-wins.1", MAJOR ); - assertIncrement( "1.0-alpha-3-SNAPSHOT", "1.0-alpha-2-SNAPSHOT", SUBINCREMENTAL ); - assertIncrement( "1.0-alpha-90-SNAPSHOT", "1.0-alpha-9-SNAPSHOT", SUBINCREMENTAL ); - assertIncrement( "1.0-za-SNAPSHOT", "1.0-z-SNAPSHOT", SUBINCREMENTAL ); - assertIncrement( "1.0-z90-SNAPSHOT", "1.0-z9-SNAPSHOT", SUBINCREMENTAL ); + assertIncrement( "1.0-alpha-3", "1.0-alpha-2-SNAPSHOT", SUBINCREMENTAL ); + assertIncrement( "1.0-alpha-90", "1.0-alpha-9-SNAPSHOT", SUBINCREMENTAL ); + assertIncrement( "1.0-za", "1.0-z-SNAPSHOT", SUBINCREMENTAL ); + assertIncrement( "1.0-z90", "1.0-z9-SNAPSHOT", SUBINCREMENTAL ); } private void assertIncrement( String expected, String initial, Segment segment ) throws InvalidSegmentException { - assertEquals( expected, + assertEquals( expected + "-SNAPSHOT", instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).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 a9dcfe8680..4d64da3a24 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/MercuryVersionComparatorTest.java @@ -20,6 +20,7 @@ */ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.codehaus.mojo.versions.api.Segment; import org.junit.Test; import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; @@ -32,8 +33,7 @@ public class MercuryVersionComparatorTest private MercuryVersionComparator instance = new MercuryVersionComparator(); @Test - public void testSegmentCounting() - throws Exception + public void testSegmentCounting() throws Exception { assertEquals( 1, instance.getSegmentCount( new DefaultArtifactVersion( "5" ) ) ); assertEquals( 2, instance.getSegmentCount( new DefaultArtifactVersion( "5.0" ) ) ); @@ -44,24 +44,21 @@ public void testSegmentCounting() } @Test - public void testSegmentIncrementing() - throws Exception + public void testSegmentIncrementing() throws Exception { - assertEquals( new DefaultArtifactVersion( "6" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "6.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.1" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.beta-0.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() ); + assertIncrement( "6", "5", MAJOR ); + assertIncrement( "6.0", "5.0", MAJOR ); + assertIncrement( "5.1", "5.0", MINOR ); + assertIncrement( "5.1.0", "5.0.1", MINOR ); + assertIncrement( "5.beta.0", "5.alpha.1", MINOR ); + assertIncrement( "5.beta-0.0", "5.alpha-1.1", MINOR ); + assertIncrement( "5.alpha-2.0", "5.alpha-1.1", INCREMENTAL ); + assertIncrement( "5.beta-0.0", "5.alpha-wins.1", MINOR ); } -} \ No newline at end of file + + private void assertIncrement( String expected, String initial, Segment segment ) throws InvalidSegmentException + { + assertEquals( expected + "-SNAPSHOT", + instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() ); + } +} 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 e7a58949be..d437aa62ca 100644 --- a/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java +++ b/src/test/java/org/codehaus/mojo/versions/ordering/NumericVersionComparatorTest.java @@ -20,6 +20,7 @@ */ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.codehaus.mojo.versions.api.Segment; import org.junit.Test; import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL; @@ -103,25 +104,21 @@ public void testSegmentCounting() } @Test - public void testSegmentIncrementing() - throws Exception + public void testSegmentIncrementing() throws Exception + { + assertIncrement( "6", "5", MAJOR ); + assertIncrement( "6.0", "5.0", MAJOR ); + assertIncrement( "5.1", "5.0", MINOR ); + assertIncrement( "5.1.0", "5.0.1", MINOR ); + assertIncrement( "5.beta.0", "5.alpha.1", MINOR ); + assertIncrement( "5.alpha-2.0", "5.alpha-1.1", MINOR ); + assertIncrement( "5.alpha-1.2", "5.alpha-1.1", INCREMENTAL ); + assertIncrement( "5.beta.0", "5.alpha-wins.1", MINOR ); + } + + private void assertIncrement( String expected, String initial, Segment segment ) throws InvalidSegmentException { - assertEquals( new DefaultArtifactVersion( "6" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5" ), MAJOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "6.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MAJOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.1" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.1.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.0.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.alpha-2.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), MINOR ).toString() ); - assertEquals( new DefaultArtifactVersion( "5.alpha-1.2" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-1.1" ), INCREMENTAL ) - .toString() ); - assertEquals( new DefaultArtifactVersion( "5.beta.0" ).toString(), - instance.incrementSegment( new DefaultArtifactVersion( "5.alpha-wins.1" ), MINOR ).toString() ); + assertEquals( expected + "-SNAPSHOT", + instance.incrementSegment( new DefaultArtifactVersion( initial ), segment ).toString() ); } }