Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundArtifactVersion.toString() to work with NumericVersionComparator #930

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String[]>() {
{
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()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>default-group</groupId>
<artifactId>default-artifact</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<artifact-version>6.2.5.Final</artifact-version>
</properties>

<dependencies>
<dependency>
<groupId>default-group</groupId>
<artifactId>artifactA</artifactId>
<version>${artifact-version}</version>
</dependency>
</dependencies>

</project>