From 2d6f4368937e5ebd26f27f9c17172767d163136b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 5 Sep 2023 11:39:04 +0100 Subject: [PATCH] Improve handling and comparison of snapshot versions Closes gh-36197 --- .../boot/build/bom/UpgradePolicy.java | 17 +- .../boot/build/bom/bomr/MoveToSnapshots.java | 2 +- .../bomr/StandardLibraryUpdateResolver.java | 7 +- .../build/bom/bomr/UpgradeDependencies.java | 9 +- .../version/AbstractDependencyVersion.java | 8 + .../ArtifactVersionDependencyVersion.java | 62 +++- .../CalendarVersionDependencyVersion.java | 8 - .../bom/bomr/version/DependencyVersion.java | 37 +-- .../ReleaseTrainDependencyVersion.java | 59 ++-- .../UnstructuredDependencyVersion.java | 13 +- ...ArtifactVersionDependencyVersionTests.java | 72 +---- ...CalendarVersionDependencyVersionTests.java | 79 +---- .../bomr/version/DependencyVersionTests.java | 5 - .../DependencyVersionUpgradeTests.java | 304 ++++++++++++++++++ ...tipleComponentsDependencyVersionTests.java | 36 +-- .../ReleaseTrainDependencyVersionTests.java | 70 +--- 16 files changed, 481 insertions(+), 307 deletions(-) create mode 100644 buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java index c74bee8223f..af2341a8c1a 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java @@ -28,24 +28,19 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion; public enum UpgradePolicy implements BiPredicate { /** - * All versions more recent than the current version will be suggested as possible - * upgrades. + * Any version. */ - ANY((candidate, current) -> current.compareTo(candidate) < 0), + ANY((candidate, current) -> true), /** - * New minor versions of the current major version will be suggested as possible - * upgrades. For example, if the current version is 1.2.3, all 1.x.y versions after - * 1.2.3 will be suggested. 2.x versions will not be offered. + * Minor versions of the current major version. */ - SAME_MAJOR_VERSION(DependencyVersion::isSameMajorAndNewerThan), + SAME_MAJOR_VERSION((candidate, current) -> candidate.isSameMajor(current)), /** - * New patch versions of the current minor version will be offered as possible - * upgrades. For example, if the current version is 1.2.3, all 1.2.x versions after - * 1.2.3 will be suggested. 1.x versions will not be offered. + * Patch versions of the current minor version. */ - SAME_MINOR_VERSION(DependencyVersion::isSameMinorAndNewerThan); + SAME_MINOR_VERSION((candidate, current) -> candidate.isSameMinor(current)); private final BiPredicate delegate; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java index e839c871257..f0927d866b7 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java @@ -36,7 +36,7 @@ public abstract class MoveToSnapshots extends UpgradeDependencies { @Inject public MoveToSnapshots(BomExtension bom) { - super(bom); + super(bom, true); getRepositoryUris().add(this.REPOSITORY_URI); } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java index 31d6da0bc3f..fee704f19a0 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java @@ -50,9 +50,13 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver { private final UpgradePolicy upgradePolicy; - StandardLibraryUpdateResolver(VersionResolver versionResolver, UpgradePolicy upgradePolicy) { + private final boolean movingToSnapshots; + + StandardLibraryUpdateResolver(VersionResolver versionResolver, UpgradePolicy upgradePolicy, + boolean movingToSnapshots) { this.versionResolver = versionResolver; this.upgradePolicy = upgradePolicy; + this.movingToSnapshots = movingToSnapshots; } @Override @@ -154,6 +158,7 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver { DependencyVersion currentVersion) { SortedSet versions = this.versionResolver.resolveVersions(groupId, artifactId); versions.removeIf((candidate) -> !this.upgradePolicy.test(candidate, currentVersion)); + versions.removeIf((candidate) -> !currentVersion.isUpgrade(candidate, this.movingToSnapshots)); return versions; } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java index e1a456f3ef1..0ac7d343c2e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java @@ -62,9 +62,16 @@ public abstract class UpgradeDependencies extends DefaultTask { private final BomExtension bom; + private final boolean movingToSnapshots; + @Inject public UpgradeDependencies(BomExtension bom) { + this(bom, false); + } + + protected UpgradeDependencies(BomExtension bom, boolean movingToSnapshots) { this.bom = bom; + this.movingToSnapshots = movingToSnapshots; getThreads().convention(2); } @@ -211,7 +218,7 @@ public abstract class UpgradeDependencies extends DefaultTask { List upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class), new MultithreadedLibraryUpdateResolver(getThreads().get(), new StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()), - this.bom.getUpgrade().getPolicy()))) + this.bom.getUpgrade().getPolicy(), this.movingToSnapshots))) .resolveUpgrades(matchingLibraries(), this.bom.getLibraries()); return upgrades; } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java index 0192c64f6f5..89860306c16 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java @@ -38,6 +38,14 @@ abstract class AbstractDependencyVersion implements DependencyVersion { return this.comparableVersion.compareTo(otherComparable); } + @Override + public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) { + ComparableVersion comparableCandidate = (candidate instanceof AbstractDependencyVersion) + ? ((AbstractDependencyVersion) candidate).comparableVersion + : new ComparableVersion(candidate.toString()); + return comparableCandidate.compareTo(this.comparableVersion) > 0; + } + @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java index 4c2b9df6d3c..219ff7aca66 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java @@ -22,6 +22,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ComparableVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.springframework.util.StringUtils; + /** * A {@link DependencyVersion} backed by an {@link ArtifactVersion}. * @@ -32,47 +34,75 @@ class ArtifactVersionDependencyVersion extends AbstractDependencyVersion { private final ArtifactVersion artifactVersion; protected ArtifactVersionDependencyVersion(ArtifactVersion artifactVersion) { - super(new ComparableVersion(artifactVersion.toString())); + super(new ComparableVersion(toNormalizedString(artifactVersion))); this.artifactVersion = artifactVersion; } + private static String toNormalizedString(ArtifactVersion artifactVersion) { + String versionString = artifactVersion.toString(); + if (versionString.endsWith(".RELEASE")) { + return versionString.substring(0, versionString.length() - 8); + } + if (versionString.endsWith(".BUILD-SNAPSHOT")) { + return versionString.substring(0, versionString.length() - 15) + "-SNAPSHOT"; + } + return versionString; + } + protected ArtifactVersionDependencyVersion(ArtifactVersion artifactVersion, ComparableVersion comparableVersion) { super(comparableVersion); this.artifactVersion = artifactVersion; } @Override - public boolean isNewerThan(DependencyVersion other) { + public boolean isSameMajor(DependencyVersion other) { if (other instanceof ReleaseTrainDependencyVersion) { return false; } - return compareTo(other) > 0; + return extractArtifactVersionDependencyVersion(other).map(this::isSameMajor).orElse(true); + } + + private boolean isSameMajor(ArtifactVersionDependencyVersion other) { + return this.artifactVersion.getMajorVersion() == other.artifactVersion.getMajorVersion(); } @Override - public boolean isSameMajorAndNewerThan(DependencyVersion other) { + public boolean isSameMinor(DependencyVersion other) { if (other instanceof ReleaseTrainDependencyVersion) { return false; } - return extractArtifactVersionDependencyVersion(other).map(this::isSameMajorAndNewerThan).orElse(true); + return extractArtifactVersionDependencyVersion(other).map(this::isSameMinor).orElse(true); } - private boolean isSameMajorAndNewerThan(ArtifactVersionDependencyVersion other) { - return this.artifactVersion.getMajorVersion() == other.artifactVersion.getMajorVersion() && isNewerThan(other); + private boolean isSameMinor(ArtifactVersionDependencyVersion other) { + return isSameMajor(other) && this.artifactVersion.getMinorVersion() == other.artifactVersion.getMinorVersion(); } @Override - public boolean isSameMinorAndNewerThan(DependencyVersion other) { - if (other instanceof ReleaseTrainDependencyVersion) { + public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) { + if (!(candidate instanceof ArtifactVersionDependencyVersion)) { return false; } - return extractArtifactVersionDependencyVersion(other).map(this::isSameMinorAndNewerThan).orElse(true); - } - - private boolean isSameMinorAndNewerThan(ArtifactVersionDependencyVersion other) { - return this.artifactVersion.getMajorVersion() == other.artifactVersion.getMajorVersion() - && this.artifactVersion.getMinorVersion() == other.artifactVersion.getMinorVersion() - && isNewerThan(other); + ArtifactVersion other = ((ArtifactVersionDependencyVersion) candidate).artifactVersion; + if (this.artifactVersion.equals(other)) { + return false; + } + if (this.artifactVersion.getMajorVersion() == other.getMajorVersion() + && this.artifactVersion.getMinorVersion() == other.getMinorVersion() + && this.artifactVersion.getIncrementalVersion() == other.getIncrementalVersion()) { + if (!StringUtils.hasLength(this.artifactVersion.getQualifier()) + || "RELEASE".equals(this.artifactVersion.getQualifier())) { + return false; + } + if ("SNAPSHOT".equals(this.artifactVersion.getQualifier()) + || "BUILD".equals(this.artifactVersion.getQualifier())) { + return true; + } + else if ("SNAPSHOT".equals(other.getQualifier()) || "BUILD".equals(other.getQualifier())) { + return movingToSnapshots; + } + } + return super.isUpgrade(candidate, movingToSnapshots); } @Override diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java index a237ac3af4c..59c685fd23f 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java @@ -41,14 +41,6 @@ class CalendarVersionDependencyVersion extends ArtifactVersionDependencyVersion super(artifactVersion, comparableVersion); } - @Override - public boolean isNewerThan(DependencyVersion other) { - if (other instanceof ReleaseTrainDependencyVersion) { - return true; - } - return super.isNewerThan(other); - } - static CalendarVersionDependencyVersion parse(String version) { if (!CALENDAR_VERSION_PATTERN.matcher(version).matches()) { return null; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java index dde4ff0dbb0..11a3a88ff58 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/DependencyVersion.java @@ -28,29 +28,30 @@ import java.util.function.Function; public interface DependencyVersion extends Comparable { /** - * Returns whether this version is newer than the given {@code other} version. - * @param other version to test - * @return {@code true} if this version is newer, otherwise {@code false} - */ - boolean isNewerThan(DependencyVersion other); - - /** - * Returns whether this version has the same major versions as the {@code other} - * version while also being newer. - * @param other version to test - * @return {@code true} if this version has the same major and is newer, otherwise + * Returns whether this version has the same major and minor versions as the + * {@code other} version. + * @param other the version to test + * @return {@code true} if this version has the same major and minor, otherwise * {@code false} */ - boolean isSameMajorAndNewerThan(DependencyVersion other); + boolean isSameMinor(DependencyVersion other); /** - * Returns whether this version has the same major and minor versions as the - * {@code other} version while also being newer. - * @param other version to test - * @return {@code true} if this version has the same major and minor and is newer, - * otherwise {@code false} + * Returns whether this version has the same major version as the {@code other} + * version. + * @param other the version to test + * @return {@code true} if this version has the same major, otherwise {@code false} */ - boolean isSameMinorAndNewerThan(DependencyVersion other); + boolean isSameMajor(DependencyVersion other); + + /** + * Returns whether the given {@code candidate} is an upgrade of this version. + * @param candidate the version the consider + * @param movingToSnapshots whether the upgrade is to be considered as part of moving + * to snaphots + * @return {@code true} if the candidate is an upgrade, otherwise false + */ + boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots); static DependencyVersion parse(String version) { List> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse, diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java index 0fbb7703ba7..dc620d2083c 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java @@ -28,7 +28,8 @@ import org.springframework.util.StringUtils; */ final class ReleaseTrainDependencyVersion implements DependencyVersion { - private static final Pattern VERSION_PATTERN = Pattern.compile("([A-Z][a-z]+)-([A-Z]+)([0-9]*)"); + private static final Pattern VERSION_PATTERN = Pattern + .compile("([A-Z][a-z]+)-((BUILD-SNAPSHOT)|([A-Z-]+)([0-9]*))"); private final String releaseTrain; @@ -63,7 +64,37 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion { } @Override - public boolean isNewerThan(DependencyVersion other) { + public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) { + if (!(candidate instanceof ReleaseTrainDependencyVersion)) { + return true; + } + ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate; + int comparison = this.releaseTrain.compareTo(candidateReleaseTrain.releaseTrain); + if (comparison != 0) { + return comparison < 0; + } + if (movingToSnapshots && !"BUILD-SNAPSHOT".equals(this.type) + && "BUILD-SNAPSHOT".equals(candidateReleaseTrain.type)) { + return true; + } + comparison = this.type.compareTo(candidateReleaseTrain.type); + if (comparison != 0) { + return comparison < 0; + } + return Integer.compare(this.version, candidateReleaseTrain.version) < 0; + } + + @Override + public boolean isSameMajor(DependencyVersion other) { + return isSameReleaseTrain(other); + } + + @Override + public boolean isSameMinor(DependencyVersion other) { + return isSameReleaseTrain(other); + } + + private boolean isSameReleaseTrain(DependencyVersion other) { if (other instanceof CalendarVersionDependencyVersion) { return false; } @@ -71,24 +102,7 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion { return true; } ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other; - return otherReleaseTrain.compareTo(this) < 0; - } - - @Override - public boolean isSameMajorAndNewerThan(DependencyVersion other) { - return isNewerThan(other); - } - - @Override - public boolean isSameMinorAndNewerThan(DependencyVersion other) { - if (other instanceof CalendarVersionDependencyVersion) { - return false; - } - if (!(other instanceof ReleaseTrainDependencyVersion)) { - return true; - } - ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other; - return otherReleaseTrain.releaseTrain.equals(this.releaseTrain) && isNewerThan(other); + return otherReleaseTrain.releaseTrain.equals(this.releaseTrain); } @Override @@ -124,8 +138,9 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion { if (!matcher.matches()) { return null; } - return new ReleaseTrainDependencyVersion(matcher.group(1), matcher.group(2), - (StringUtils.hasLength(matcher.group(3))) ? Integer.parseInt(matcher.group(3)) : 0, input); + return new ReleaseTrainDependencyVersion(matcher.group(1), + StringUtils.hasLength(matcher.group(3)) ? matcher.group(3) : matcher.group(4), + (StringUtils.hasLength(matcher.group(5))) ? Integer.parseInt(matcher.group(5)) : 0, input); } } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java index a39d8a3843f..e23a6e5ed71 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java @@ -34,18 +34,13 @@ final class UnstructuredDependencyVersion extends AbstractDependencyVersion impl } @Override - public boolean isNewerThan(DependencyVersion other) { - return compareTo(other) > 0; + public boolean isSameMajor(DependencyVersion other) { + return true; } @Override - public boolean isSameMajorAndNewerThan(DependencyVersion other) { - return compareTo(other) > 0; - } - - @Override - public boolean isSameMinorAndNewerThan(DependencyVersion other) { - return compareTo(other) > 0; + public boolean isSameMinor(DependencyVersion other) { + return true; } @Override diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java index 8672866a7ce..639fb06d49c 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,78 +38,28 @@ class ArtifactVersionDependencyVersionTests { } @Test - void isNewerThanWhenInputIsOlderMajorShouldReturnTrue() { - assertThat(version("2.1.2").isNewerThan(version("1.9.0"))).isTrue(); + void isSameMajorWhenSameMajorAndMinorShouldReturnTrue() { + assertThat(version("1.10.2").isSameMajor(version("1.10.0"))).isTrue(); } @Test - void isNewerThanWhenInputIsOlderMinorShouldReturnTrue() { - assertThat(version("2.1.2").isNewerThan(version("2.0.2"))).isTrue(); + void isSameMajorWhenSameMajorShouldReturnTrue() { + assertThat(version("1.10.2").isSameMajor(version("1.9.0"))).isTrue(); } @Test - void isNewerThanWhenInputIsOlderPatchShouldReturnTrue() { - assertThat(version("2.1.2").isNewerThan(version("2.1.1"))).isTrue(); + void isSameMajorWhenDifferentMajorShouldReturnFalse() { + assertThat(version("2.0.2").isSameMajor(version("1.9.0"))).isFalse(); } @Test - void isNewerThanWhenInputIsNewerMajorShouldReturnFalse() { - assertThat(version("2.1.2").isNewerThan(version("3.2.1"))).isFalse(); + void isSameMinorWhenSameMinorShouldReturnTrue() { + assertThat(version("1.10.2").isSameMinor(version("1.10.1"))).isTrue(); } @Test - void isSameMajorAndNewerThanWhenMinorIsOlderShouldReturnTrue() { - assertThat(version("1.10.2").isSameMajorAndNewerThan(version("1.9.0"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWhenMajorIsOlderShouldReturnFalse() { - assertThat(version("2.0.2").isSameMajorAndNewerThan(version("1.9.0"))).isFalse(); - } - - @Test - void isSameMajorAndNewerThanWhenPatchIsNewerShouldReturnTrue() { - assertThat(version("2.1.2").isSameMajorAndNewerThan(version("2.1.1"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWhenMinorIsNewerShouldReturnFalse() { - assertThat(version("2.1.2").isSameMajorAndNewerThan(version("2.2.1"))).isFalse(); - } - - @Test - void isSameMajorAndNewerThanWhenMajorIsNewerShouldReturnFalse() { - assertThat(version("2.1.2").isSameMajorAndNewerThan(version("3.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenPatchIsOlderShouldReturnTrue() { - assertThat(version("1.10.2").isSameMinorAndNewerThan(version("1.10.1"))).isTrue(); - } - - @Test - void isSameMinorAndNewerThanWhenMinorIsOlderShouldReturnFalse() { - assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenVersionsAreTheSameShouldReturnFalse() { - assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.2"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenPatchIsNewerShouldReturnFalse() { - assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.3"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMinorIsNewerShouldReturnFalse() { - assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMajorIsNewerShouldReturnFalse() { - assertThat(version("3.1.2").isSameMinorAndNewerThan(version("2.0.1"))).isFalse(); + void isSameMinorWhenDifferentMinorShouldReturnFalse() { + assertThat(version("1.10.2").isSameMinor(version("1.9.1"))).isFalse(); } private ArtifactVersionDependencyVersion version(String version) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java index 279016c7af2..023b64b0bd3 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java @@ -38,93 +38,38 @@ class CalendarVersionDependencyVersionTests { } @Test - void isNewerThanWhenInputIsEarlierYearShouldReturnTrue() { - assertThat(version("2020.1.2").isNewerThan(version("2019.9.0"))).isTrue(); + void isSameMajorWhenSameMajorAndMinorShouldReturnTrue() { + assertThat(version("2020.0.0").isSameMajor(version("2020.0.1"))).isTrue(); } @Test - void isNewerThanWhenInputIsOlderMinorShouldReturnTrue() { - assertThat(version("2020.1.2").isNewerThan(version("2020.0.2"))).isTrue(); + void isSameMajorWhenSameMajorShouldReturnTrue() { + assertThat(version("2020.0.0").isSameMajor(version("2020.1.0"))).isTrue(); } @Test - void isNewerThanWhenInputIsOlderMicroShouldReturnTrue() { - assertThat(version("2020.1.2").isNewerThan(version("2020.1.1"))).isTrue(); + void isSameMajorWhenDifferentMajorShouldReturnFalse() { + assertThat(version("2020.0.0").isSameMajor(version("2021.0.0"))).isFalse(); } @Test - void isNewerThanWhenInputIsLaterYearShouldReturnFalse() { - assertThat(version("2020.1.2").isNewerThan(version("2021.2.1"))).isFalse(); + void isSameMinorWhenSameMinorShouldReturnTrue() { + assertThat(version("2020.0.0").isSameMinor(version("2020.0.1"))).isTrue(); } @Test - void isSameMajorAndNewerThanWhenMinorIsOlderShouldReturnTrue() { - assertThat(version("2020.10.2").isSameMajorAndNewerThan(version("2020.9.0"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWhenMajorIsOlderShouldReturnFalse() { - assertThat(version("2020.0.2").isSameMajorAndNewerThan(version("2019.9.0"))).isFalse(); - } - - @Test - void isSameMajorAndNewerThanWhenMicroIsNewerShouldReturnTrue() { - assertThat(version("2020.1.2").isSameMajorAndNewerThan(version("2020.1.1"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWhenMinorIsNewerShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMajorAndNewerThan(version("2020.2.1"))).isFalse(); - } - - @Test - void isSameMajorAndNewerThanWhenMajorIsNewerShouldReturnFalse() { - assertThat(version("2019.1.2").isSameMajorAndNewerThan(version("2020.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMicroIsOlderShouldReturnTrue() { - assertThat(version("2020.10.2").isSameMinorAndNewerThan(version("2020.10.1"))).isTrue(); - } - - @Test - void isSameMinorAndNewerThanWhenMinorIsOlderShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMinorAndNewerThan(version("2020.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenVersionsAreTheSameShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMinorAndNewerThan(version("2020.1.2"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMicroIsNewerShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMinorAndNewerThan(version("2020.1.3"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMinorIsNewerShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMinorAndNewerThan(version("2020.0.1"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenMajorIsNewerShouldReturnFalse() { - assertThat(version("2020.1.2").isSameMinorAndNewerThan(version("2019.0.1"))).isFalse(); - } - - @Test - void calendarVersionIsNewerThanReleaseTrainVersion() { - assertThat(version("2020.0.0").isNewerThan(releaseTrainVersion("Aluminium-RELEASE"))).isTrue(); + void isSameMinorWhenDifferentMinorShouldReturnFalse() { + assertThat(version("2020.0.0").isSameMinor(version("2020.1.0"))).isFalse(); } @Test void calendarVersionIsNotSameMajorAsReleaseTrainVersion() { - assertThat(version("2020.0.0").isSameMajorAndNewerThan(releaseTrainVersion("Aluminium-RELEASE"))).isFalse(); + assertThat(version("2020.0.0").isSameMajor(releaseTrainVersion("Aluminium-RELEASE"))).isFalse(); } @Test void calendarVersionIsNotSameMinorAsReleaseTrainVersion() { - assertThat(version("2020.0.0").isSameMinorAndNewerThan(releaseTrainVersion("Aluminium-RELEASE"))).isFalse(); + assertThat(version("2020.0.0").isSameMinor(releaseTrainVersion("Aluminium-RELEASE"))).isFalse(); } private ReleaseTrainDependencyVersion releaseTrainVersion(String version) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java index 64e5f7b2a32..06dc3e6fb3d 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionTests.java @@ -68,9 +68,4 @@ class DependencyVersionTests { assertThat(DependencyVersion.parse("2020.0.0-M1")).isInstanceOf(CalendarVersionDependencyVersion.class); } - @Test - void calendarVersionShouldBeNewerThanAReleaseCalendarVersion() { - - } - } diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java new file mode 100644 index 00000000000..f51b9eea9e7 --- /dev/null +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java @@ -0,0 +1,304 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.build.bom.bomr.version; + +import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.util.function.Function; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link DependencyVersion#isUpgrade} of {@link DependencyVersion} + * implementations. + * + * @author Andy Wilkinson + */ +public class DependencyVersionUpgradeTests { + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.3") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.3.RELEASE") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.0") + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-RELEASE") + void isUpgradeWhenSameVersionShouldReturnFalse(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-SNAPSHOT", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.BUILD-SNAPSHOT", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-SNAPSHOT", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-BUILD-SNAPSHOT", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenSameSnapshotVersionShouldReturnFalse(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-SNAPSHOT", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.BUILD-SNAPSHOT", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-SNAPSHOT", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-BUILD-SNAPSHOT", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenSameSnapshotVersionAndMovingToSnapshotsShouldReturnFalse(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.4") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.4.RELEASE") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.1") + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-SR1") + void isUpgradeWhenLaterPatchReleaseShouldReturnTrue(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.4-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.4.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.1-SNAPSHOT") + void isUpgradeWhenSnapshotOfLaterPatchReleaseShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.4-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.4.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.1-SNAPSHOT") + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenSnapshotOfLaterPatchReleaseAndMovingToSnapshotsShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenSnapshotOfSameVersionShouldReturnFalse(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-SNAPSHOT", candidate = "1.2.3-M2") + @ArtifactVersion(current = "1.2.3.BUILD-SNAPSHOT", candidate = "1.2.3.M2") + @CalendarVersion(current = "2023.0.0-SNAPSHOT", candidate = "2023.0.0-M2") + @ReleaseTrain(current = "Kay-BUILD-SNAPSHOT", candidate = "Kay-M2") + void isUpgradeWhenSnapshotToMilestoneShouldReturnTrue(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-SNAPSHOT", candidate = "1.2.3-RC1") + @ArtifactVersion(current = "1.2.3.BUILD-SNAPSHOT", candidate = "1.2.3.RC1") + @CalendarVersion(current = "2023.0.0-SNAPSHOT", candidate = "2023.0.0-RC1") + @ReleaseTrain(current = "Kay-BUILD-SNAPSHOT", candidate = "Kay-RC1") + void isUpgradeWhenSnapshotToReleaseCandidateShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-SNAPSHOT", candidate = "1.2.3") + @ArtifactVersion(current = "1.2.3.BUILD-SNAPSHOT", candidate = "1.2.3.RELEASE") + @CalendarVersion(current = "2023.0.0-SNAPSHOT", candidate = "2023.0.0") + @ReleaseTrain(current = "Kay-BUILD-SNAPSHOT", candidate = "Kay-RELEASE") + void isUpgradeWhenSnapshotToReleaseShouldReturnTrue(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-M1", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.M1", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-M1", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-M1", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenMilestoneToSnapshotShouldReturnFalse(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-RC1", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RC1", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-RC1", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-RC1", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenReleaseCandidateToSnapshotShouldReturnFalse(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenReleaseToSnapshotShouldReturnFalse(DependencyVersion current, DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, false)).isFalse(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-M1", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.M1", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-M1", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-M1", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenMilestoneToSnapshotAndMovingToSnapshotsShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3-RC1", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RC1", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0-RC1", candidate = "2023.0.0-SNAPSHOT") + @ReleaseTrain(current = "Kay-RC1", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenReleaseCandidateToSnapshotAndMovingToSnapshotsShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isTrue(); + } + + @ParameterizedTest + @ArtifactVersion(current = "1.2.3", candidate = "1.2.3-SNAPSHOT") + @ArtifactVersion(current = "1.2.3.RELEASE", candidate = "1.2.3.BUILD-SNAPSHOT") + @CalendarVersion(current = "2023.0.0", candidate = "2023.0.0-SNAPSHOT") + void isUpgradeWhenReleaseToSnapshotAndMovingToSnapshotsShouldReturnFalse(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isFalse(); + } + + @ParameterizedTest + @ReleaseTrain(current = "Kay-RELEASE", candidate = "Kay-BUILD-SNAPSHOT") + void isUpgradeWhenReleaseTrainToSnapshotAndMovingToSnapshotsShouldReturnTrue(DependencyVersion current, + DependencyVersion candidate) { + assertThat(current.isUpgrade(candidate, true)).isTrue(); + } + + @Repeatable(ArtifactVersions.class) + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @ArgumentsSource(InputProvider.class) + @interface ArtifactVersion { + + String current(); + + String candidate(); + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @interface ArtifactVersions { + + ArtifactVersion[] value(); + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @ArgumentsSource(InputProvider.class) + @interface ReleaseTrain { + + String current(); + + String candidate(); + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @ArgumentsSource(InputProvider.class) + @interface CalendarVersion { + + String current(); + + String candidate(); + + } + + static class InputProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) throws Exception { + Method testMethod = context.getRequiredTestMethod(); + Stream artifactVersions = artifactVersions(testMethod) + .map((artifactVersion) -> Arguments.of(VersionType.ARTIFACT_VERSION.parse(artifactVersion.current()), + VersionType.ARTIFACT_VERSION.parse(artifactVersion.candidate()))); + Stream releaseTrains = releaseTrains(testMethod) + .map((releaseTrain) -> Arguments.of(VersionType.RELEASE_TRAIN.parse(releaseTrain.current()), + VersionType.RELEASE_TRAIN.parse(releaseTrain.candidate()))); + Stream calendarVersions = calendarVersions(testMethod) + .map((calendarVersion) -> Arguments.of(VersionType.CALENDAR_VERSION.parse(calendarVersion.current()), + VersionType.CALENDAR_VERSION.parse(calendarVersion.candidate()))); + return Stream.concat(Stream.concat(artifactVersions, releaseTrains), calendarVersions); + } + + private Stream artifactVersions(Method testMethod) { + ArtifactVersions artifactVersions = testMethod.getAnnotation(ArtifactVersions.class); + if (artifactVersions != null) { + return Stream.of(artifactVersions.value()); + } + return versions(testMethod, ArtifactVersion.class); + } + + private Stream releaseTrains(Method testMethod) { + return versions(testMethod, ReleaseTrain.class); + } + + private Stream calendarVersions(Method testMethod) { + return versions(testMethod, CalendarVersion.class); + } + + private Stream versions(Method testMethod, Class type) { + T annotation = testMethod.getAnnotation(type); + return (annotation != null) ? Stream.of(annotation) : Stream.empty(); + } + + } + + enum VersionType { + + ARTIFACT_VERSION(ArtifactVersionDependencyVersion::parse), + + CALENDAR_VERSION(CalendarVersionDependencyVersion::parse), + + RELEASE_TRAIN(ReleaseTrainDependencyVersion::parse); + + private final Function parser; + + VersionType(Function parser) { + this.parser = parser; + } + + DependencyVersion parse(String version) { + return this.parser.apply(version); + } + + } + +} diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java index 8602a5982a3..ad8b814cd48 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/MultipleComponentsDependencyVersionTests.java @@ -29,43 +29,23 @@ import static org.assertj.core.api.Assertions.assertThat; class MultipleComponentsDependencyVersionTests { @Test - void isNewerThanOnVersionWithNumericQualifierWhenInputHasNoQualifierShouldReturnTrue() { - assertThat(version("2.9.9.20190806").isNewerThan(DependencyVersion.parse("2.9.9"))).isTrue(); + void isSameMajorOfFiveComponentVersionWithSameMajorShouldReturnTrue() { + assertThat(version("21.4.0.0.1").isSameMajor(version("21.1.0.0"))).isTrue(); } @Test - void isNewerThanOnVersionWithNumericQualifierWhenInputHasOlderQualifierShouldReturnTrue() { - assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190805"))).isTrue(); + void isSameMajorOfFiveComponentVersionWithDifferentMajorShouldReturnFalse() { + assertThat(version("21.4.0.0.1").isSameMajor(version("22.1.0.0"))).isFalse(); } @Test - void isNewerThanOnVersionWithNumericQualifierWhenInputHasNewerQualifierShouldReturnFalse() { - assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190807"))).isFalse(); + void isSameMinorOfFiveComponentVersionWithSameMinorShouldReturnTrue() { + assertThat(version("21.4.0.0.1").isSameMinor(version("21.4.0.0"))).isTrue(); } @Test - void isNewerThanOnVersionWithNumericQualifierWhenInputHasSameQualifierShouldReturnFalse() { - assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190806"))).isFalse(); - } - - @Test - void isNewerThanWorksWith5Components() { - assertThat(version("21.4.0.0.1").isNewerThan(version("21.1.0.0"))).isTrue(); - } - - @Test - void isNewerThanWorksWith5ComponentsAndLastComponentIsConsidered() { - assertThat(version("21.1.0.0.1").isNewerThan(version("21.1.0.0"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWorksWith5Components() { - assertThat(version("21.4.0.0.1").isSameMajorAndNewerThan(version("21.1.0.0"))).isTrue(); - } - - @Test - void isSameMinorAndNewerThanWorksWith5Components() { - assertThat(version("21.4.0.0.1").isSameMinorAndNewerThan(version("21.1.0.0"))).isFalse(); + void isSameMinorOfFiveComponentVersionWithDifferentMinorShouldReturnFalse() { + assertThat(version("21.4.0.0.1").isSameMinor(version("21.5.0.0"))).isFalse(); } private MultipleComponentsDependencyVersion version(String version) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersionTests.java index 74556b01fec..8aa9b922de7 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,81 +38,33 @@ class ReleaseTrainDependencyVersionTests { } @Test - void isNewerThanWhenReleaseTrainIsNewerShouldReturnTrue() { - assertThat(version("Lovelace-RELEASE").isNewerThan(version("Kay-SR5"))).isTrue(); + void isSameMajorWhenReleaseTrainIsDifferentShouldReturnFalse() { + assertThat(version("Lovelace-RELEASE").isSameMajor(version("Kay-SR5"))).isFalse(); } @Test - void isNewerThanWhenVersionIsNewerShouldReturnTrue() { - assertThat(version("Kay-SR10").isNewerThan(version("Kay-SR5"))).isTrue(); + void isSameMajorWhenReleaseTrainIsTheSameShouldReturnTrue() { + assertThat(version("Lovelace-RELEASE").isSameMajor(version("Lovelace-SR5"))).isTrue(); } @Test - void isNewerThanWhenVersionIsOlderShouldReturnFalse() { - assertThat(version("Kay-RELEASE").isNewerThan(version("Kay-SR5"))).isFalse(); + void isSameMinorWhenReleaseTrainIsDifferentShouldReturnFalse() { + assertThat(version("Lovelace-RELEASE").isSameMajor(version("Kay-SR5"))).isFalse(); } @Test - void isNewerThanWhenReleaseTrainIsOlderShouldReturnFalse() { - assertThat(version("Ingalls-RELEASE").isNewerThan(version("Kay-SR5"))).isFalse(); - } - - @Test - void isSameMajorAndNewerWhenWhenReleaseTrainIsNewerShouldReturnTrue() { - assertThat(version("Lovelace-RELEASE").isSameMajorAndNewerThan(version("Kay-SR5"))).isTrue(); - } - - @Test - void isSameMajorAndNewerThanWhenReleaseTrainIsOlderShouldReturnFalse() { - assertThat(version("Ingalls-RELEASE").isSameMajorAndNewerThan(version("Kay-SR5"))).isFalse(); - } - - @Test - void isSameMajorAndNewerThanWhenVersionIsNewerShouldReturnTrue() { - assertThat(version("Kay-SR6").isSameMajorAndNewerThan(version("Kay-SR5"))).isTrue(); - } - - @Test - void isSameMinorAndNewerThanWhenReleaseTrainIsNewerShouldReturnFalse() { - assertThat(version("Lovelace-RELEASE").isSameMinorAndNewerThan(version("Kay-SR5"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenReleaseTrainIsTheSameAndVersionIsNewerShouldReturnTrue() { - assertThat(version("Kay-SR6").isSameMinorAndNewerThan(version("Kay-SR5"))).isTrue(); - } - - @Test - void isSameMinorAndNewerThanWhenReleaseTrainAndVersionAreTheSameShouldReturnFalse() { - assertThat(version("Kay-SR6").isSameMinorAndNewerThan(version("Kay-SR6"))).isFalse(); - } - - @Test - void isSameMinorAndNewerThanWhenReleaseTrainIsTheSameAndVersionIsOlderShouldReturnFalse() { - assertThat(version("Kay-SR6").isSameMinorAndNewerThan(version("Kay-SR7"))).isFalse(); - } - - @Test - void releaseTrainVersionIsNotNewerThanCalendarVersion() { - assertThat(version("Kay-SR6").isNewerThan(calendarVersion("2020.0.0"))).isFalse(); + void isSameMinorWhenReleaseTrainIsTheSameShouldReturnTrue() { + assertThat(version("Lovelace-RELEASE").isSameMajor(version("Lovelace-SR5"))).isTrue(); } @Test void releaseTrainVersionIsNotSameMajorAsCalendarTrainVersion() { - assertThat(version("Kay-SR6").isSameMajorAndNewerThan(calendarVersion("2020.0.0"))).isFalse(); + assertThat(version("Kay-SR6").isSameMajor(calendarVersion("2020.0.0"))).isFalse(); } @Test void releaseTrainVersionIsNotSameMinorAsCalendarVersion() { - assertThat(version("Kay-SR6").isSameMinorAndNewerThan(calendarVersion("2020.0.0"))).isFalse(); - } - - @Test - void whenComparedWithADifferentDependencyVersionTypeThenTheResultsAreNonZero() { - ReleaseTrainDependencyVersion dysprosium = ReleaseTrainDependencyVersion.parse("Dysprosium-SR16"); - ArtifactVersionDependencyVersion twentyTwenty = ArtifactVersionDependencyVersion.parse("2020.0.0"); - assertThat(dysprosium.compareTo(twentyTwenty)).isLessThan(0); - assertThat(twentyTwenty.compareTo(dysprosium)).isGreaterThan(0); + assertThat(version("Kay-SR6").isSameMinor(calendarVersion("2020.0.0"))).isFalse(); } private static ReleaseTrainDependencyVersion version(String input) {