Fix comparision of identical snapshots

Closes gh-35860
pull/36038/head
Andy Wilkinson 1 year ago
parent 1955139b72
commit 50a5e31873

@ -16,6 +16,7 @@
package org.springframework.boot.build.bom.bomr.version; package org.springframework.boot.build.bom.bomr.version;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
@ -79,7 +80,8 @@ class ArtifactVersionDependencyVersion extends AbstractDependencyVersion {
public int compareTo(DependencyVersion other) { public int compareTo(DependencyVersion other) {
if (other instanceof ArtifactVersionDependencyVersion otherArtifactDependencyVersion) { if (other instanceof ArtifactVersionDependencyVersion otherArtifactDependencyVersion) {
ArtifactVersion otherArtifactVersion = otherArtifactDependencyVersion.artifactVersion; ArtifactVersion otherArtifactVersion = otherArtifactDependencyVersion.artifactVersion;
if ("snapshot".equalsIgnoreCase(otherArtifactVersion.getQualifier()) if ((!Objects.equals(this.artifactVersion.getQualifier(), otherArtifactVersion.getQualifier()))
&& "snapshot".equalsIgnoreCase(otherArtifactVersion.getQualifier())
&& otherArtifactVersion.getMajorVersion() == this.artifactVersion.getMajorVersion() && otherArtifactVersion.getMajorVersion() == this.artifactVersion.getMajorVersion()
&& otherArtifactVersion.getMinorVersion() == this.artifactVersion.getMinorVersion() && otherArtifactVersion.getMinorVersion() == this.artifactVersion.getMinorVersion()
&& otherArtifactVersion.getIncrementalVersion() == this.artifactVersion.getIncrementalVersion()) { && otherArtifactVersion.getIncrementalVersion() == this.artifactVersion.getIncrementalVersion()) {

@ -97,6 +97,11 @@ class ArtifactVersionDependencyVersionTests {
assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.2"))).isFalse(); assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.2"))).isFalse();
} }
@Test
void isSameMinorAndNewerThanWhenSameSnapshotsShouldReturnFalse() {
assertThat(version("3.1.2-SNAPSHOT").isSameMinorAndNewerThan(version("3.1.2-SNAPSHOT"))).isFalse();
}
@Test @Test
void isSameMinorAndNewerThanWhenPatchIsNewerShouldReturnFalse() { void isSameMinorAndNewerThanWhenPatchIsNewerShouldReturnFalse() {
assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.3"))).isFalse(); assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.3"))).isFalse();

Loading…
Cancel
Save