mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '3.1.x'
Closes gh-37202
This commit is contained in:
commit
f2112459c2
@ -28,24 +28,19 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
|
|||||||
public enum UpgradePolicy implements BiPredicate<DependencyVersion, DependencyVersion> {
|
public enum UpgradePolicy implements BiPredicate<DependencyVersion, DependencyVersion> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All versions more recent than the current version will be suggested as possible
|
* Any version.
|
||||||
* upgrades.
|
|
||||||
*/
|
*/
|
||||||
ANY((candidate, current) -> current.compareTo(candidate) < 0),
|
ANY((candidate, current) -> true),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New minor versions of the current major version will be suggested as possible
|
* Minor versions of the current major version.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
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
|
* Patch versions of the current minor version.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
SAME_MINOR_VERSION(DependencyVersion::isSameMinorAndNewerThan);
|
SAME_MINOR_VERSION((candidate, current) -> candidate.isSameMinor(current));
|
||||||
|
|
||||||
private final BiPredicate<DependencyVersion, DependencyVersion> delegate;
|
private final BiPredicate<DependencyVersion, DependencyVersion> delegate;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public abstract class MoveToSnapshots extends UpgradeDependencies {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MoveToSnapshots(BomExtension bom) {
|
public MoveToSnapshots(BomExtension bom) {
|
||||||
super(bom);
|
super(bom, true);
|
||||||
getRepositoryUris().add(this.REPOSITORY_URI);
|
getRepositoryUris().add(this.REPOSITORY_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +48,13 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver {
|
|||||||
|
|
||||||
private final UpgradePolicy upgradePolicy;
|
private final UpgradePolicy upgradePolicy;
|
||||||
|
|
||||||
StandardLibraryUpdateResolver(VersionResolver versionResolver, UpgradePolicy upgradePolicy) {
|
private final boolean movingToSnapshots;
|
||||||
|
|
||||||
|
StandardLibraryUpdateResolver(VersionResolver versionResolver, UpgradePolicy upgradePolicy,
|
||||||
|
boolean movingToSnapshots) {
|
||||||
this.versionResolver = versionResolver;
|
this.versionResolver = versionResolver;
|
||||||
this.upgradePolicy = upgradePolicy;
|
this.upgradePolicy = upgradePolicy;
|
||||||
|
this.movingToSnapshots = movingToSnapshots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,6 +151,7 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver {
|
|||||||
DependencyVersion currentVersion) {
|
DependencyVersion currentVersion) {
|
||||||
SortedSet<DependencyVersion> versions = this.versionResolver.resolveVersions(groupId, artifactId);
|
SortedSet<DependencyVersion> versions = this.versionResolver.resolveVersions(groupId, artifactId);
|
||||||
versions.removeIf((candidate) -> !this.upgradePolicy.test(candidate, currentVersion));
|
versions.removeIf((candidate) -> !this.upgradePolicy.test(candidate, currentVersion));
|
||||||
|
versions.removeIf((candidate) -> !currentVersion.isUpgrade(candidate, this.movingToSnapshots));
|
||||||
return versions;
|
return versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,9 +61,16 @@ public abstract class UpgradeDependencies extends DefaultTask {
|
|||||||
|
|
||||||
private final BomExtension bom;
|
private final BomExtension bom;
|
||||||
|
|
||||||
|
private final boolean movingToSnapshots;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UpgradeDependencies(BomExtension bom) {
|
public UpgradeDependencies(BomExtension bom) {
|
||||||
|
this(bom, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected UpgradeDependencies(BomExtension bom, boolean movingToSnapshots) {
|
||||||
this.bom = bom;
|
this.bom = bom;
|
||||||
|
this.movingToSnapshots = movingToSnapshots;
|
||||||
getThreads().convention(2);
|
getThreads().convention(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +217,7 @@ public abstract class UpgradeDependencies extends DefaultTask {
|
|||||||
List<Upgrade> upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class),
|
List<Upgrade> upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class),
|
||||||
new MultithreadedLibraryUpdateResolver(getThreads().get(),
|
new MultithreadedLibraryUpdateResolver(getThreads().get(),
|
||||||
new StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()),
|
new StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()),
|
||||||
this.bom.getUpgrade().getPolicy())))
|
this.bom.getUpgrade().getPolicy(), this.movingToSnapshots)))
|
||||||
.resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
|
.resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
|
||||||
return upgrades;
|
return upgrades;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,14 @@ abstract class AbstractDependencyVersion implements DependencyVersion {
|
|||||||
return this.comparableVersion.compareTo(otherComparable);
|
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
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
|
@ -23,6 +23,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
|
|||||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link DependencyVersion} backed by an {@link ArtifactVersion}.
|
* A {@link DependencyVersion} backed by an {@link ArtifactVersion}.
|
||||||
*
|
*
|
||||||
@ -33,47 +35,75 @@ class ArtifactVersionDependencyVersion extends AbstractDependencyVersion {
|
|||||||
private final ArtifactVersion artifactVersion;
|
private final ArtifactVersion artifactVersion;
|
||||||
|
|
||||||
protected ArtifactVersionDependencyVersion(ArtifactVersion artifactVersion) {
|
protected ArtifactVersionDependencyVersion(ArtifactVersion artifactVersion) {
|
||||||
super(new ComparableVersion(artifactVersion.toString()));
|
super(new ComparableVersion(toNormalizedString(artifactVersion)));
|
||||||
this.artifactVersion = 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) {
|
protected ArtifactVersionDependencyVersion(ArtifactVersion artifactVersion, ComparableVersion comparableVersion) {
|
||||||
super(comparableVersion);
|
super(comparableVersion);
|
||||||
this.artifactVersion = artifactVersion;
|
this.artifactVersion = artifactVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNewerThan(DependencyVersion other) {
|
public boolean isSameMajor(DependencyVersion other) {
|
||||||
if (other instanceof ReleaseTrainDependencyVersion) {
|
if (other instanceof ReleaseTrainDependencyVersion) {
|
||||||
return false;
|
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
|
@Override
|
||||||
public boolean isSameMajorAndNewerThan(DependencyVersion other) {
|
public boolean isSameMinor(DependencyVersion other) {
|
||||||
if (other instanceof ReleaseTrainDependencyVersion) {
|
if (other instanceof ReleaseTrainDependencyVersion) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return extractArtifactVersionDependencyVersion(other).map(this::isSameMajorAndNewerThan).orElse(true);
|
return extractArtifactVersionDependencyVersion(other).map(this::isSameMinor).orElse(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSameMajorAndNewerThan(ArtifactVersionDependencyVersion other) {
|
private boolean isSameMinor(ArtifactVersionDependencyVersion other) {
|
||||||
return this.artifactVersion.getMajorVersion() == other.artifactVersion.getMajorVersion() && isNewerThan(other);
|
return isSameMajor(other) && this.artifactVersion.getMinorVersion() == other.artifactVersion.getMinorVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameMinorAndNewerThan(DependencyVersion other) {
|
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
|
||||||
if (other instanceof ReleaseTrainDependencyVersion) {
|
if (!(candidate instanceof ArtifactVersionDependencyVersion)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return extractArtifactVersionDependencyVersion(other).map(this::isSameMinorAndNewerThan).orElse(true);
|
ArtifactVersion other = ((ArtifactVersionDependencyVersion) candidate).artifactVersion;
|
||||||
}
|
if (this.artifactVersion.equals(other)) {
|
||||||
|
return false;
|
||||||
private boolean isSameMinorAndNewerThan(ArtifactVersionDependencyVersion other) {
|
}
|
||||||
return this.artifactVersion.getMajorVersion() == other.artifactVersion.getMajorVersion()
|
if (this.artifactVersion.getMajorVersion() == other.getMajorVersion()
|
||||||
&& this.artifactVersion.getMinorVersion() == other.artifactVersion.getMinorVersion()
|
&& this.artifactVersion.getMinorVersion() == other.getMinorVersion()
|
||||||
&& isNewerThan(other);
|
&& 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
|
@Override
|
||||||
|
@ -41,14 +41,6 @@ class CalendarVersionDependencyVersion extends ArtifactVersionDependencyVersion
|
|||||||
super(artifactVersion, comparableVersion);
|
super(artifactVersion, comparableVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNewerThan(DependencyVersion other) {
|
|
||||||
if (other instanceof ReleaseTrainDependencyVersion) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.isNewerThan(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
static CalendarVersionDependencyVersion parse(String version) {
|
static CalendarVersionDependencyVersion parse(String version) {
|
||||||
if (!CALENDAR_VERSION_PATTERN.matcher(version).matches()) {
|
if (!CALENDAR_VERSION_PATTERN.matcher(version).matches()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -28,29 +28,30 @@ import java.util.function.Function;
|
|||||||
public interface DependencyVersion extends Comparable<DependencyVersion> {
|
public interface DependencyVersion extends Comparable<DependencyVersion> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this version is newer than the given {@code other} version.
|
* Returns whether this version has the same major and minor versions as the
|
||||||
* @param other version to test
|
* {@code other} version.
|
||||||
* @return {@code true} if this version is newer, otherwise {@code false}
|
* @param other the version to test
|
||||||
*/
|
* @return {@code true} if this version has the same major and minor, otherwise
|
||||||
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
|
|
||||||
* {@code false}
|
* {@code false}
|
||||||
*/
|
*/
|
||||||
boolean isSameMajorAndNewerThan(DependencyVersion other);
|
boolean isSameMinor(DependencyVersion other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this version has the same major and minor versions as the
|
* Returns whether this version has the same major version as the {@code other}
|
||||||
* {@code other} version while also being newer.
|
* version.
|
||||||
* @param other version to test
|
* @param other the version to test
|
||||||
* @return {@code true} if this version has the same major and minor and is newer,
|
* @return {@code true} if this version has the same major, otherwise {@code false}
|
||||||
* 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) {
|
static DependencyVersion parse(String version) {
|
||||||
List<Function<String, DependencyVersion>> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse,
|
List<Function<String, DependencyVersion>> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse,
|
||||||
|
@ -28,7 +28,8 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
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;
|
private final String releaseTrain;
|
||||||
|
|
||||||
@ -62,30 +63,44 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNewerThan(DependencyVersion other) {
|
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
|
||||||
if (other instanceof CalendarVersionDependencyVersion) {
|
if (!(candidate instanceof ReleaseTrainDependencyVersion)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return otherReleaseTrain.compareTo(this) < 0;
|
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
|
@Override
|
||||||
public boolean isSameMajorAndNewerThan(DependencyVersion other) {
|
public boolean isSameMajor(DependencyVersion other) {
|
||||||
return isNewerThan(other);
|
return isSameReleaseTrain(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameMinorAndNewerThan(DependencyVersion other) {
|
public boolean isSameMinor(DependencyVersion other) {
|
||||||
|
return isSameReleaseTrain(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSameReleaseTrain(DependencyVersion other) {
|
||||||
if (other instanceof CalendarVersionDependencyVersion) {
|
if (other instanceof CalendarVersionDependencyVersion) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
|
if (other instanceof ReleaseTrainDependencyVersion otherReleaseTrain) {
|
||||||
return true;
|
return otherReleaseTrain.releaseTrain.equals(this.releaseTrain);
|
||||||
}
|
}
|
||||||
return otherReleaseTrain.releaseTrain.equals(this.releaseTrain) && isNewerThan(other);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -121,8 +136,9 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
|||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ReleaseTrainDependencyVersion(matcher.group(1), matcher.group(2),
|
return new ReleaseTrainDependencyVersion(matcher.group(1),
|
||||||
(StringUtils.hasLength(matcher.group(3))) ? Integer.parseInt(matcher.group(3)) : 0, input);
|
StringUtils.hasLength(matcher.group(3)) ? matcher.group(3) : matcher.group(4),
|
||||||
|
(StringUtils.hasLength(matcher.group(5))) ? Integer.parseInt(matcher.group(5)) : 0, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,18 +34,13 @@ final class UnstructuredDependencyVersion extends AbstractDependencyVersion impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNewerThan(DependencyVersion other) {
|
public boolean isSameMajor(DependencyVersion other) {
|
||||||
return compareTo(other) > 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameMajorAndNewerThan(DependencyVersion other) {
|
public boolean isSameMinor(DependencyVersion other) {
|
||||||
return compareTo(other) > 0;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSameMinorAndNewerThan(DependencyVersion other) {
|
|
||||||
return compareTo(other) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,83 +38,28 @@ class ArtifactVersionDependencyVersionTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsOlderMajorShouldReturnTrue() {
|
void isSameMajorWhenSameMajorAndMinorShouldReturnTrue() {
|
||||||
assertThat(version("2.1.2").isNewerThan(version("1.9.0"))).isTrue();
|
assertThat(version("1.10.2").isSameMajor(version("1.10.0"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsOlderMinorShouldReturnTrue() {
|
void isSameMajorWhenSameMajorShouldReturnTrue() {
|
||||||
assertThat(version("2.1.2").isNewerThan(version("2.0.2"))).isTrue();
|
assertThat(version("1.10.2").isSameMajor(version("1.9.0"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsOlderPatchShouldReturnTrue() {
|
void isSameMajorWhenDifferentMajorShouldReturnFalse() {
|
||||||
assertThat(version("2.1.2").isNewerThan(version("2.1.1"))).isTrue();
|
assertThat(version("2.0.2").isSameMajor(version("1.9.0"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsNewerMajorShouldReturnFalse() {
|
void isSameMinorWhenSameMinorShouldReturnTrue() {
|
||||||
assertThat(version("2.1.2").isNewerThan(version("3.2.1"))).isFalse();
|
assertThat(version("1.10.2").isSameMinor(version("1.10.1"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isSameMajorAndNewerThanWhenMinorIsOlderShouldReturnTrue() {
|
void isSameMinorWhenDifferentMinorShouldReturnFalse() {
|
||||||
assertThat(version("1.10.2").isSameMajorAndNewerThan(version("1.9.0"))).isTrue();
|
assertThat(version("1.10.2").isSameMinor(version("1.9.1"))).isFalse();
|
||||||
}
|
|
||||||
|
|
||||||
@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 isSameMinorAndNewerThanWhenSameSnapshotsShouldReturnFalse() {
|
|
||||||
assertThat(version("3.1.2-SNAPSHOT").isSameMinorAndNewerThan(version("3.1.2-SNAPSHOT"))).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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArtifactVersionDependencyVersion version(String version) {
|
private ArtifactVersionDependencyVersion version(String version) {
|
||||||
|
@ -38,93 +38,38 @@ class CalendarVersionDependencyVersionTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsEarlierYearShouldReturnTrue() {
|
void isSameMajorWhenSameMajorAndMinorShouldReturnTrue() {
|
||||||
assertThat(version("2020.1.2").isNewerThan(version("2019.9.0"))).isTrue();
|
assertThat(version("2020.0.0").isSameMajor(version("2020.0.1"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsOlderMinorShouldReturnTrue() {
|
void isSameMajorWhenSameMajorShouldReturnTrue() {
|
||||||
assertThat(version("2020.1.2").isNewerThan(version("2020.0.2"))).isTrue();
|
assertThat(version("2020.0.0").isSameMajor(version("2020.1.0"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsOlderMicroShouldReturnTrue() {
|
void isSameMajorWhenDifferentMajorShouldReturnFalse() {
|
||||||
assertThat(version("2020.1.2").isNewerThan(version("2020.1.1"))).isTrue();
|
assertThat(version("2020.0.0").isSameMajor(version("2021.0.0"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenInputIsLaterYearShouldReturnFalse() {
|
void isSameMinorWhenSameMinorShouldReturnTrue() {
|
||||||
assertThat(version("2020.1.2").isNewerThan(version("2021.2.1"))).isFalse();
|
assertThat(version("2020.0.0").isSameMinor(version("2020.0.1"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isSameMajorAndNewerThanWhenMinorIsOlderShouldReturnTrue() {
|
void isSameMinorWhenDifferentMinorShouldReturnFalse() {
|
||||||
assertThat(version("2020.10.2").isSameMajorAndNewerThan(version("2020.9.0"))).isTrue();
|
assertThat(version("2020.0.0").isSameMinor(version("2020.1.0"))).isFalse();
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void calendarVersionIsNotSameMajorAsReleaseTrainVersion() {
|
void calendarVersionIsNotSameMajorAsReleaseTrainVersion() {
|
||||||
assertThat(version("2020.0.0").isSameMajorAndNewerThan(releaseTrainVersion("Aluminium-RELEASE"))).isFalse();
|
assertThat(version("2020.0.0").isSameMajor(releaseTrainVersion("Aluminium-RELEASE"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void calendarVersionIsNotSameMinorAsReleaseTrainVersion() {
|
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) {
|
private ReleaseTrainDependencyVersion releaseTrainVersion(String version) {
|
||||||
|
@ -68,9 +68,4 @@ class DependencyVersionTests {
|
|||||||
assertThat(DependencyVersion.parse("2020.0.0-M1")).isInstanceOf(CalendarVersionDependencyVersion.class);
|
assertThat(DependencyVersion.parse("2020.0.0-M1")).isInstanceOf(CalendarVersionDependencyVersion.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void calendarVersionShouldBeNewerThanAReleaseCalendarVersion() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
|
||||||
|
Method testMethod = context.getRequiredTestMethod();
|
||||||
|
Stream<Arguments> artifactVersions = artifactVersions(testMethod)
|
||||||
|
.map((artifactVersion) -> Arguments.of(VersionType.ARTIFACT_VERSION.parse(artifactVersion.current()),
|
||||||
|
VersionType.ARTIFACT_VERSION.parse(artifactVersion.candidate())));
|
||||||
|
Stream<Arguments> releaseTrains = releaseTrains(testMethod)
|
||||||
|
.map((releaseTrain) -> Arguments.of(VersionType.RELEASE_TRAIN.parse(releaseTrain.current()),
|
||||||
|
VersionType.RELEASE_TRAIN.parse(releaseTrain.candidate())));
|
||||||
|
Stream<Arguments> 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<ArtifactVersion> artifactVersions(Method testMethod) {
|
||||||
|
ArtifactVersions artifactVersions = testMethod.getAnnotation(ArtifactVersions.class);
|
||||||
|
if (artifactVersions != null) {
|
||||||
|
return Stream.of(artifactVersions.value());
|
||||||
|
}
|
||||||
|
return versions(testMethod, ArtifactVersion.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<ReleaseTrain> releaseTrains(Method testMethod) {
|
||||||
|
return versions(testMethod, ReleaseTrain.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<CalendarVersion> calendarVersions(Method testMethod) {
|
||||||
|
return versions(testMethod, CalendarVersion.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Annotation> Stream<T> versions(Method testMethod, Class<T> 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<String, DependencyVersion> parser;
|
||||||
|
|
||||||
|
VersionType(Function<String, DependencyVersion> parser) {
|
||||||
|
this.parser = parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
DependencyVersion parse(String version) {
|
||||||
|
return this.parser.apply(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -29,43 +29,23 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
class MultipleComponentsDependencyVersionTests {
|
class MultipleComponentsDependencyVersionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanOnVersionWithNumericQualifierWhenInputHasNoQualifierShouldReturnTrue() {
|
void isSameMajorOfFiveComponentVersionWithSameMajorShouldReturnTrue() {
|
||||||
assertThat(version("2.9.9.20190806").isNewerThan(DependencyVersion.parse("2.9.9"))).isTrue();
|
assertThat(version("21.4.0.0.1").isSameMajor(version("21.1.0.0"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanOnVersionWithNumericQualifierWhenInputHasOlderQualifierShouldReturnTrue() {
|
void isSameMajorOfFiveComponentVersionWithDifferentMajorShouldReturnFalse() {
|
||||||
assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190805"))).isTrue();
|
assertThat(version("21.4.0.0.1").isSameMajor(version("22.1.0.0"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanOnVersionWithNumericQualifierWhenInputHasNewerQualifierShouldReturnFalse() {
|
void isSameMinorOfFiveComponentVersionWithSameMinorShouldReturnTrue() {
|
||||||
assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190807"))).isFalse();
|
assertThat(version("21.4.0.0.1").isSameMinor(version("21.4.0.0"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanOnVersionWithNumericQualifierWhenInputHasSameQualifierShouldReturnFalse() {
|
void isSameMinorOfFiveComponentVersionWithDifferentMinorShouldReturnFalse() {
|
||||||
assertThat(version("2.9.9.20190806").isNewerThan(version("2.9.9.20190806"))).isFalse();
|
assertThat(version("21.4.0.0.1").isSameMinor(version("21.5.0.0"))).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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MultipleComponentsDependencyVersion version(String version) {
|
private MultipleComponentsDependencyVersion version(String version) {
|
||||||
|
@ -38,81 +38,33 @@ class ReleaseTrainDependencyVersionTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenReleaseTrainIsNewerShouldReturnTrue() {
|
void isSameMajorWhenReleaseTrainIsDifferentShouldReturnFalse() {
|
||||||
assertThat(version("Lovelace-RELEASE").isNewerThan(version("Kay-SR5"))).isTrue();
|
assertThat(version("Lovelace-RELEASE").isSameMajor(version("Kay-SR5"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenVersionIsNewerShouldReturnTrue() {
|
void isSameMajorWhenReleaseTrainIsTheSameShouldReturnTrue() {
|
||||||
assertThat(version("Kay-SR10").isNewerThan(version("Kay-SR5"))).isTrue();
|
assertThat(version("Lovelace-RELEASE").isSameMajor(version("Lovelace-SR5"))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenVersionIsOlderShouldReturnFalse() {
|
void isSameMinorWhenReleaseTrainIsDifferentShouldReturnFalse() {
|
||||||
assertThat(version("Kay-RELEASE").isNewerThan(version("Kay-SR5"))).isFalse();
|
assertThat(version("Lovelace-RELEASE").isSameMajor(version("Kay-SR5"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void isNewerThanWhenReleaseTrainIsOlderShouldReturnFalse() {
|
void isSameMinorWhenReleaseTrainIsTheSameShouldReturnTrue() {
|
||||||
assertThat(version("Ingalls-RELEASE").isNewerThan(version("Kay-SR5"))).isFalse();
|
assertThat(version("Lovelace-RELEASE").isSameMajor(version("Lovelace-SR5"))).isTrue();
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void releaseTrainVersionIsNotSameMajorAsCalendarTrainVersion() {
|
void releaseTrainVersionIsNotSameMajorAsCalendarTrainVersion() {
|
||||||
assertThat(version("Kay-SR6").isSameMajorAndNewerThan(calendarVersion("2020.0.0"))).isFalse();
|
assertThat(version("Kay-SR6").isSameMajor(calendarVersion("2020.0.0"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void releaseTrainVersionIsNotSameMinorAsCalendarVersion() {
|
void releaseTrainVersionIsNotSameMinorAsCalendarVersion() {
|
||||||
assertThat(version("Kay-SR6").isSameMinorAndNewerThan(calendarVersion("2020.0.0"))).isFalse();
|
assertThat(version("Kay-SR6").isSameMinor(calendarVersion("2020.0.0"))).isFalse();
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void whenComparedWithADifferentDependencyVersionTypeThenTheResultsAreNonZero() {
|
|
||||||
DependencyVersion dysprosium = ReleaseTrainDependencyVersion.parse("Dysprosium-SR16");
|
|
||||||
DependencyVersion twentyTwenty = ArtifactVersionDependencyVersion.parse("2020.0.0");
|
|
||||||
assertThat(dysprosium).isLessThan(twentyTwenty);
|
|
||||||
assertThat(twentyTwenty).isGreaterThan(dysprosium);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReleaseTrainDependencyVersion version(String input) {
|
private static ReleaseTrainDependencyVersion version(String input) {
|
||||||
|
Loading…
Reference in New Issue
Block a user