Merge branch '3.4.x' into 3.5.x

Closes gh-46412
This commit is contained in:
Andy Wilkinson
2025-07-14 09:36:18 +01:00
8 changed files with 38 additions and 16 deletions
@@ -111,9 +111,9 @@ public class BomExtension {
action.execute(libraryHandler);
LibraryVersion libraryVersion = new LibraryVersion(DependencyVersion.parse(libraryHandler.version));
addLibrary(new Library(name, libraryHandler.calendarName, libraryVersion, libraryHandler.groups,
libraryHandler.prohibitedVersions, libraryHandler.considerSnapshots, versionAlignment(libraryHandler),
libraryHandler.alignWith.dependencyManagementDeclaredIn, libraryHandler.linkRootName,
libraryHandler.links));
libraryHandler.upgradePolicy, libraryHandler.prohibitedVersions, libraryHandler.considerSnapshots,
versionAlignment(libraryHandler), libraryHandler.alignWith.dependencyManagementDeclaredIn,
libraryHandler.linkRootName, libraryHandler.links));
}
private VersionAlignment versionAlignment(LibraryHandler libraryHandler) {
@@ -196,6 +196,8 @@ public class BomExtension {
private final List<Group> groups = new ArrayList<>();
private UpgradePolicy upgradePolicy;
private final List<ProhibitedVersion> prohibitedVersions = new ArrayList<>();
private final AlignWithHandler alignWith;
@@ -236,6 +238,10 @@ public class BomExtension {
.add(new Group(groupHandler.id, groupHandler.modules, groupHandler.plugins, groupHandler.imports));
}
public void setUpgradePolicy(UpgradePolicy upgradePolicy) {
this.upgradePolicy = upgradePolicy;
}
public void prohibit(Action<ProhibitedHandler> action) {
ProhibitedHandler handler = new ProhibitedHandler();
action.execute(handler);
@@ -66,6 +66,8 @@ public class Library {
private final String versionProperty;
private final UpgradePolicy upgradePolicy;
private final List<ProhibitedVersion> prohibitedVersions;
private final boolean considerSnapshots;
@@ -86,6 +88,8 @@ public class Library {
* be {@code null} in which case the {@code name} is used.
* @param version version of the library
* @param groups groups in the library
* @param upgradePolicy the upgrade policy of the library, or {@code null} to use the
* containing bom's policy
* @param prohibitedVersions version of the library that are prohibited
* @param considerSnapshots whether to consider snapshots
* @param versionAlignment version alignment, if any, for the library
@@ -96,14 +100,16 @@ public class Library {
* @param links a list of HTTP links relevant to the library
*/
public Library(String name, String calendarName, LibraryVersion version, List<Group> groups,
List<ProhibitedVersion> prohibitedVersions, boolean considerSnapshots, VersionAlignment versionAlignment,
String alignsWithBom, String linkRootName, Map<String, List<Link>> links) {
UpgradePolicy upgradePolicy, List<ProhibitedVersion> prohibitedVersions, boolean considerSnapshots,
VersionAlignment versionAlignment, String alignsWithBom, String linkRootName,
Map<String, List<Link>> links) {
this.name = name;
this.calendarName = (calendarName != null) ? calendarName : name;
this.version = version;
this.groups = groups;
this.versionProperty = "Spring Boot".equals(name) ? null
: name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version";
this.upgradePolicy = upgradePolicy;
this.prohibitedVersions = prohibitedVersions;
this.considerSnapshots = considerSnapshots;
this.versionAlignment = versionAlignment;
@@ -136,6 +142,10 @@ public class Library {
return this.versionProperty;
}
public UpgradePolicy getUpgradePolicy() {
return this.upgradePolicy;
}
public List<ProhibitedVersion> getProhibitedVersions() {
return this.prohibitedVersions;
}
@@ -180,8 +190,9 @@ public class Library {
}
public Library withVersion(LibraryVersion version) {
return new Library(this.name, this.calendarName, version, this.groups, this.prohibitedVersions,
this.considerSnapshots, this.versionAlignment, this.alignsWithBom, this.linkRootName, this.links);
return new Library(this.name, this.calendarName, version, this.groups, this.upgradePolicy,
this.prohibitedVersions, this.considerSnapshots, this.versionAlignment, this.alignsWithBom,
this.linkRootName, this.links);
}
/**
@@ -50,6 +50,7 @@ import org.gradle.api.tasks.options.Option;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.bom.UpgradePolicy;
import org.springframework.boot.build.bom.bomr.github.GitHub;
import org.springframework.boot.build.bom.bomr.github.GitHubRepository;
import org.springframework.boot.build.bom.bomr.github.Issue;
@@ -264,7 +265,11 @@ public abstract class UpgradeDependencies extends DefaultTask {
}
private boolean compliesWithUpgradePolicy(Library library, DependencyVersion candidate) {
return this.bom.getUpgrade().getPolicy().test(candidate, library.getVersion().getVersion());
UpgradePolicy upgradePolicy = library.getUpgradePolicy();
if (upgradePolicy == null) {
upgradePolicy = this.bom.getUpgrade().getPolicy();
}
return upgradePolicy.test(candidate, library.getVersion().getVersion());
}
private boolean isAnUpgrade(Library library, DependencyVersion candidate) {
@@ -237,7 +237,7 @@ class AntoraAsciidocAttributesTests {
VersionAlignment versionAlignment = null;
String alignsWithBom = null;
String linkRootName = null;
Library library = new Library(name, calendarName, version, groups, prohibitedVersion, considerSnapshots,
Library library = new Library(name, calendarName, version, groups, null, prohibitedVersion, considerSnapshots,
versionAlignment, alignsWithBom, linkRootName, links);
return library;
}
@@ -50,7 +50,7 @@ class LibraryTests {
String alignsWithBom = null;
String linkRootName = null;
Map<String, List<Link>> links = Collections.emptyMap();
Library library = new Library(name, calendarName, version, groups, prohibitedVersion, considerSnapshots,
Library library = new Library(name, calendarName, version, groups, null, prohibitedVersion, considerSnapshots,
versionAlignment, alignsWithBom, linkRootName, links);
assertThat(library.getLinkRootName()).isEqualTo("spring-framework");
}
@@ -67,7 +67,7 @@ class LibraryTests {
String alignsWithBom = null;
String linkRootName = "spring-data";
Map<String, List<Link>> links = Collections.emptyMap();
Library library = new Library(name, calendarName, version, groups, prohibitedVersion, considerSnapshots,
Library library = new Library(name, calendarName, version, groups, null, prohibitedVersion, considerSnapshots,
versionAlignment, alignsWithBom, linkRootName, links);
assertThat(library.getLinkRootName()).isEqualTo("spring-data");
}
@@ -48,7 +48,7 @@ class InteractiveUpgradeResolverTests {
List<Library> libraries = new ArrayList<>();
DependencyVersion version = DependencyVersion.parse("1.0.0");
LibraryVersion libraryVersion = new LibraryVersion(version);
Library library = new Library("test", null, libraryVersion, null, null, false, null, null, null, null);
Library library = new Library("test", null, libraryVersion, null, null, null, false, null, null, null, null);
libraries.add(library);
List<Library> librariesToUpgrade = new ArrayList<>();
librariesToUpgrade.add(library);
@@ -53,7 +53,7 @@ class UpgradeApplicatorTests {
File gradleProperties = new File(this.temp, "gradle.properties");
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
Library activeMq = new Library("ActiveMQ", null, new LibraryVersion(DependencyVersion.parse("5.15.11")), null,
null, false, null, null, null, Collections.emptyMap());
null, null, false, null, null, null, Collections.emptyMap());
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
.apply(new Upgrade(activeMq, activeMq.withVersion(new LibraryVersion(DependencyVersion.parse("5.16")))));
String bomContents = Files.readString(bom.toPath());
@@ -67,7 +67,7 @@ class UpgradeApplicatorTests {
File gradleProperties = new File(this.temp, "gradle.properties");
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
Library kotlin = new Library("Kotlin", null, new LibraryVersion(DependencyVersion.parse("1.3.70")), null, null,
false, null, null, null, Collections.emptyMap());
null, false, null, null, null, Collections.emptyMap());
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
.apply(new Upgrade(kotlin, kotlin.withVersion(new LibraryVersion(DependencyVersion.parse("1.4")))));
Properties properties = new Properties();
@@ -33,7 +33,7 @@ class UpgradeTests {
@Test
void createToRelease() {
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null,
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null, null,
false, null, null, null, null);
Upgrade upgrade = new Upgrade(from, from.withVersion(new LibraryVersion(DependencyVersion.parse("1.0.1"))));
assertThat(upgrade.from().getNameAndVersion()).isEqualTo("Test 1.0.0");
@@ -43,7 +43,7 @@ class UpgradeTests {
@Test
void createToSnapshot() {
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null,
Library from = new Library("Test", null, new LibraryVersion(DependencyVersion.parse("1.0.0")), null, null, null,
false, null, null, null, null);
Upgrade upgrade = new Upgrade(from,
from.withVersion(new LibraryVersion(DependencyVersion.parse("1.0.1-SNAPSHOT"))),