Merge branch '3.0.x' into 3.1.x
Closes gh-37201
This commit is contained in:
@@ -28,24 +28,19 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
|
||||
public enum UpgradePolicy implements BiPredicate<DependencyVersion, DependencyVersion> {
|
||||
|
||||
/**
|
||||
* 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<DependencyVersion, DependencyVersion> delegate;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<DependencyVersion> versions = this.versionResolver.resolveVersions(groupId, artifactId);
|
||||
versions.removeIf((candidate) -> !this.upgradePolicy.test(candidate, currentVersion));
|
||||
versions.removeIf((candidate) -> !currentVersion.isUpgrade(candidate, this.movingToSnapshots));
|
||||
return versions;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,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);
|
||||
}
|
||||
|
||||
@@ -210,7 +217,7 @@ public abstract class UpgradeDependencies extends DefaultTask {
|
||||
List<Upgrade> 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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -23,6 +23,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}.
|
||||
*
|
||||
@@ -33,47 +35,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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,29 +28,30 @@ import java.util.function.Function;
|
||||
public interface DependencyVersion extends Comparable<DependencyVersion> {
|
||||
|
||||
/**
|
||||
* 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<Function<String, DependencyVersion>> parsers = Arrays.asList(CalendarVersionDependencyVersion::parse,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -62,30 +63,44 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNewerThan(DependencyVersion other) {
|
||||
if (other instanceof CalendarVersionDependencyVersion) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
|
||||
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
|
||||
if (!(candidate instanceof ReleaseTrainDependencyVersion)) {
|
||||
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
|
||||
public boolean isSameMajorAndNewerThan(DependencyVersion other) {
|
||||
return isNewerThan(other);
|
||||
public boolean isSameMajor(DependencyVersion other) {
|
||||
return isSameReleaseTrain(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameMinorAndNewerThan(DependencyVersion other) {
|
||||
public boolean isSameMinor(DependencyVersion other) {
|
||||
return isSameReleaseTrain(other);
|
||||
}
|
||||
|
||||
private boolean isSameReleaseTrain(DependencyVersion other) {
|
||||
if (other instanceof CalendarVersionDependencyVersion) {
|
||||
return false;
|
||||
}
|
||||
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
|
||||
return true;
|
||||
if (other instanceof ReleaseTrainDependencyVersion otherReleaseTrain) {
|
||||
return otherReleaseTrain.releaseTrain.equals(this.releaseTrain);
|
||||
}
|
||||
return otherReleaseTrain.releaseTrain.equals(this.releaseTrain) && isNewerThan(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,8 +136,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user