diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersion.java b/versions-common/src/main/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersion.java index f7f1279139..5612d05bf5 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersion.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/ordering/BoundArtifactVersion.java @@ -183,4 +183,15 @@ public String getQualifier() { public void parseVersion(String version) { throw new UnsupportedOperationException(); } + + /** + * {@inheritDoc} + * + * Quasi-contract: {@link #toString()} must produce the textual representation of the version, without any + * additional items, this is required by the implementation of {@link NumericVersionComparator}. + */ + @Override + public String toString() { + return comparable.toString(); + } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java index 372397d024..81721fb07d 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/ordering/VersionComparatorTestBase.java @@ -19,10 +19,12 @@ */ import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; /** @@ -87,4 +89,10 @@ public void testVersionComparatorRow7() { assertThat(instance.compare(version("1-alpha-1"), version("2-alpha-1")), lessThan(0)); assertThat(instance.compare(version("1-alpha-1"), version("1-alpha-2")), lessThan(0)); } + + @Test + public void testBoundArtifactVersion() { + assertThat( + instance.compare(new BoundArtifactVersion("1.0.0", Segment.MAJOR), version("1.9.9")), greaterThan(0)); + } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java index 4c413fccdb..220840edfd 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java @@ -17,13 +17,16 @@ import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; +import org.codehaus.mojo.versions.model.RuleSet; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.codehaus.mojo.versions.utils.TestUtils; import org.junit.Test; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -88,4 +91,24 @@ public void testChangesNotRegisteredIfNoUpdatesInPom() throws Exception { mojo.execute(); assertThat(changeRecorder.getChanges(), is(empty())); } + + @Test + public void testIssue929() throws Exception { + TestUtils.copyDir(Paths.get("src/test/resources/org/codehaus/mojo/update-properties/issue-929"), pomDir); + UpdatePropertiesMojo mojo = setUpMojo("update-properties"); + mojo.allowMajorUpdates = false; + mojo.aetherRepositorySystem = mockAetherRepositorySystem(new HashMap() { + { + put("artifactA", new String[] {"6.2.5.Final", "8.0.0.Final"}); + } + }); + mojo.ruleSet = new RuleSet() { + { + setComparisonMethod("numeric"); + } + }; + + mojo.execute(); + assertThat(changeRecorder.getChanges(), is(empty())); + } } diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-929/pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-929/pom.xml new file mode 100644 index 0000000000..8ff13d9d66 --- /dev/null +++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-929/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + default-group + default-artifact + 1.0.0 + pom + + + 6.2.5.Final + + + + + default-group + artifactA + ${artifact-version} + + + +