Merge branch '3.0.x' into 3.1.x

Closes gh-37192
3.1.x
Andy Wilkinson 1 year ago
commit dc4d647437

@ -113,7 +113,8 @@ public class BomExtension {
LibraryHandler libraryHandler = objects.newInstance(LibraryHandler.class, (version != null) ? version : ""); LibraryHandler libraryHandler = objects.newInstance(LibraryHandler.class, (version != null) ? version : "");
action.execute(libraryHandler); action.execute(libraryHandler);
LibraryVersion libraryVersion = new LibraryVersion(DependencyVersion.parse(libraryHandler.version)); LibraryVersion libraryVersion = new LibraryVersion(DependencyVersion.parse(libraryHandler.version));
addLibrary(new Library(name, libraryVersion, libraryHandler.groups, libraryHandler.prohibitedVersions)); addLibrary(new Library(name, libraryVersion, libraryHandler.groups, libraryHandler.prohibitedVersions,
libraryHandler.considerSnapshots));
} }
public void effectiveBomArtifact() { public void effectiveBomArtifact() {
@ -213,6 +214,8 @@ public class BomExtension {
private final List<ProhibitedVersion> prohibitedVersions = new ArrayList<>(); private final List<ProhibitedVersion> prohibitedVersions = new ArrayList<>();
private boolean considerSnapshots = false;
private String version; private String version;
@Inject @Inject
@ -224,6 +227,10 @@ public class BomExtension {
this.version = version; this.version = version;
} }
public void considerSnapshots() {
this.considerSnapshots = true;
}
public void group(String id, Action<GroupHandler> action) { public void group(String id, Action<GroupHandler> action) {
GroupHandler groupHandler = new GroupHandler(id); GroupHandler groupHandler = new GroupHandler(id);
action.execute(groupHandler); action.execute(groupHandler);

@ -42,6 +42,8 @@ public class Library {
private final List<ProhibitedVersion> prohibitedVersions; private final List<ProhibitedVersion> prohibitedVersions;
private final boolean considerSnapshots;
/** /**
* Create a new {@code Library} with the given {@code name}, {@code version}, and * Create a new {@code Library} with the given {@code name}, {@code version}, and
* {@code groups}. * {@code groups}.
@ -49,15 +51,17 @@ public class Library {
* @param version version of the library * @param version version of the library
* @param groups groups in the library * @param groups groups in the library
* @param prohibitedVersions version of the library that are prohibited * @param prohibitedVersions version of the library that are prohibited
* @param considerSnapshots whether to consider snapshots
*/ */
public Library(String name, LibraryVersion version, List<Group> groups, public Library(String name, LibraryVersion version, List<Group> groups, List<ProhibitedVersion> prohibitedVersions,
List<ProhibitedVersion> prohibitedVersions) { boolean considerSnapshots) {
this.name = name; this.name = name;
this.version = version; this.version = version;
this.groups = groups; this.groups = groups;
this.versionProperty = "Spring Boot".equals(name) ? null this.versionProperty = "Spring Boot".equals(name) ? null
: name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version"; : name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version";
this.prohibitedVersions = prohibitedVersions; this.prohibitedVersions = prohibitedVersions;
this.considerSnapshots = considerSnapshots;
} }
public String getName() { public String getName() {
@ -80,6 +84,10 @@ public class Library {
return this.prohibitedVersions; return this.prohibitedVersions;
} }
public boolean isConsiderSnapshots() {
return this.considerSnapshots;
}
/** /**
* A version or range of versions that are prohibited from being used in a bom. * A version or range of versions that are prohibited from being used in a bom.
*/ */

@ -23,6 +23,7 @@ import javax.inject.Inject;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.springframework.boot.build.bom.BomExtension; import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
/** /**
* A {@link Task} to move to snapshot dependencies. * A {@link Task} to move to snapshot dependencies.
@ -57,4 +58,9 @@ public abstract class MoveToSnapshots extends UpgradeDependencies {
return snapshotVersion.substring(0, snapshotVersion.length() - "-SNAPSHOT".length()); return snapshotVersion.substring(0, snapshotVersion.length() - "-SNAPSHOT".length());
} }
@Override
protected boolean eligible(Library library) {
return library.isConsiderSnapshots() && super.eligible(library);
}
} }

@ -211,25 +211,27 @@ public abstract class UpgradeDependencies extends DefaultTask {
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())))
.resolveUpgrades(matchingLibraries(getLibraries().getOrNull()), this.bom.getLibraries()); .resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
return upgrades; return upgrades;
} }
private List<Library> matchingLibraries(String pattern) { private List<Library> matchingLibraries() {
if (pattern == null) { List<Library> matchingLibraries = this.bom.getLibraries().stream().filter(this::eligible).toList();
return this.bom.getLibraries();
}
Predicate<String> libraryPredicate = Pattern.compile(pattern).asPredicate();
List<Library> matchingLibraries = this.bom.getLibraries()
.stream()
.filter((library) -> libraryPredicate.test(library.getName()))
.toList();
if (matchingLibraries.isEmpty()) { if (matchingLibraries.isEmpty()) {
throw new InvalidUserDataException("No libraries matched '" + pattern + "'"); throw new InvalidUserDataException("No libraries to upgrade");
} }
return matchingLibraries; return matchingLibraries;
} }
protected boolean eligible(Library library) {
String pattern = getLibraries().getOrNull();
if (pattern == null) {
return true;
}
Predicate<String> libraryPredicate = Pattern.compile(pattern).asPredicate();
return libraryPredicate.test(library.getName());
}
protected abstract String issueTitle(Upgrade upgrade); protected abstract String issueTitle(Upgrade upgrade);
protected abstract String commitMessage(Upgrade upgrade, int issueNumber); protected abstract String commitMessage(Upgrade upgrade, int issueNumber);

@ -51,9 +51,9 @@ class UpgradeApplicatorTests {
String originalContents = Files.readString(bom.toPath()); String originalContents = Files.readString(bom.toPath());
File gradleProperties = new File(this.temp, "gradle.properties"); File gradleProperties = new File(this.temp, "gradle.properties");
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties); FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply( new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(
new Upgrade(new Library("ActiveMQ", new LibraryVersion(DependencyVersion.parse("5.15.11")), null, null), new Library("ActiveMQ", new LibraryVersion(DependencyVersion.parse("5.15.11")), null, null, false),
DependencyVersion.parse("5.16"))); DependencyVersion.parse("5.16")));
String bomContents = Files.readString(bom.toPath()); String bomContents = Files.readString(bom.toPath());
assertThat(bomContents).hasSize(originalContents.length() - 3); assertThat(bomContents).hasSize(originalContents.length() - 3);
} }
@ -64,9 +64,9 @@ class UpgradeApplicatorTests {
FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom); FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
File gradleProperties = new File(this.temp, "gradle.properties"); File gradleProperties = new File(this.temp, "gradle.properties");
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties); FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()) new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(
.apply(new Upgrade(new Library("Kotlin", new LibraryVersion(DependencyVersion.parse("1.3.70")), null, null), new Library("Kotlin", new LibraryVersion(DependencyVersion.parse("1.3.70")), null, null, false),
DependencyVersion.parse("1.4"))); DependencyVersion.parse("1.4")));
Properties properties = new Properties(); Properties properties = new Properties();
try (InputStream in = new FileInputStream(gradleProperties)) { try (InputStream in = new FileInputStream(gradleProperties)) {
properties.load(in); properties.load(in);

@ -977,6 +977,7 @@ bom {
} }
} }
library("Micrometer", "1.11.3") { library("Micrometer", "1.11.3") {
considerSnapshots()
group("io.micrometer") { group("io.micrometer") {
modules = [ modules = [
"micrometer-registry-stackdriver" { "micrometer-registry-stackdriver" {
@ -989,6 +990,7 @@ bom {
} }
} }
library("Micrometer Tracing", "1.1.4") { library("Micrometer Tracing", "1.1.4") {
considerSnapshots()
group("io.micrometer") { group("io.micrometer") {
imports = [ imports = [
"micrometer-tracing-bom" "micrometer-tracing-bom"
@ -1130,6 +1132,7 @@ bom {
} }
} }
library("R2DBC H2", "1.0.0.RELEASE") { library("R2DBC H2", "1.0.0.RELEASE") {
considerSnapshots()
group("io.r2dbc") { group("io.r2dbc") {
modules = [ modules = [
"r2dbc-h2" "r2dbc-h2"
@ -1158,6 +1161,7 @@ bom {
} }
} }
library("R2DBC Pool", "1.0.1.RELEASE") { library("R2DBC Pool", "1.0.1.RELEASE") {
considerSnapshots()
group("io.r2dbc") { group("io.r2dbc") {
modules = [ modules = [
"r2dbc-pool" "r2dbc-pool"
@ -1165,6 +1169,7 @@ bom {
} }
} }
library("R2DBC Postgresql", "1.0.2.RELEASE") { library("R2DBC Postgresql", "1.0.2.RELEASE") {
considerSnapshots()
group("org.postgresql") { group("org.postgresql") {
modules = [ modules = [
"r2dbc-postgresql" "r2dbc-postgresql"
@ -1172,6 +1177,7 @@ bom {
} }
} }
library("R2DBC Proxy", "1.1.2.RELEASE") { library("R2DBC Proxy", "1.1.2.RELEASE") {
considerSnapshots()
group("io.r2dbc") { group("io.r2dbc") {
modules = [ modules = [
"r2dbc-proxy" "r2dbc-proxy"
@ -1179,6 +1185,7 @@ bom {
} }
} }
library("R2DBC SPI", "1.0.0.RELEASE") { library("R2DBC SPI", "1.0.0.RELEASE") {
considerSnapshots()
group("io.r2dbc") { group("io.r2dbc") {
modules = [ modules = [
"r2dbc-spi" "r2dbc-spi"
@ -1207,6 +1214,7 @@ bom {
} }
} }
library("Reactor Bom", "2022.0.10") { library("Reactor Bom", "2022.0.10") {
considerSnapshots()
group("io.projectreactor") { group("io.projectreactor") {
imports = [ imports = [
"reactor-bom" "reactor-bom"
@ -1370,6 +1378,7 @@ bom {
} }
} }
library("Spring AMQP", "3.0.8") { library("Spring AMQP", "3.0.8") {
considerSnapshots()
group("org.springframework.amqp") { group("org.springframework.amqp") {
imports = [ imports = [
"spring-amqp-bom" "spring-amqp-bom"
@ -1377,6 +1386,7 @@ bom {
} }
} }
library("Spring Authorization Server", "1.1.2") { library("Spring Authorization Server", "1.1.2") {
considerSnapshots()
group("org.springframework.security") { group("org.springframework.security") {
modules = [ modules = [
"spring-security-oauth2-authorization-server" "spring-security-oauth2-authorization-server"
@ -1384,6 +1394,7 @@ bom {
} }
} }
library("Spring Batch", "5.0.3") { library("Spring Batch", "5.0.3") {
considerSnapshots()
group("org.springframework.batch") { group("org.springframework.batch") {
imports = [ imports = [
"spring-batch-bom" "spring-batch-bom"
@ -1391,6 +1402,7 @@ bom {
} }
} }
library("Spring Data Bom", "2023.0.3") { library("Spring Data Bom", "2023.0.3") {
considerSnapshots()
group("org.springframework.data") { group("org.springframework.data") {
imports = [ imports = [
"spring-data-bom" "spring-data-bom"
@ -1398,6 +1410,7 @@ bom {
} }
} }
library("Spring Framework", "${springFrameworkVersion}") { library("Spring Framework", "${springFrameworkVersion}") {
considerSnapshots()
group("org.springframework") { group("org.springframework") {
imports = [ imports = [
"spring-framework-bom" "spring-framework-bom"
@ -1405,6 +1418,7 @@ bom {
} }
} }
library("Spring GraphQL", "1.2.2") { library("Spring GraphQL", "1.2.2") {
considerSnapshots()
group("org.springframework.graphql") { group("org.springframework.graphql") {
modules = [ modules = [
"spring-graphql", "spring-graphql",
@ -1413,6 +1427,7 @@ bom {
} }
} }
library("Spring HATEOAS", "2.1.2") { library("Spring HATEOAS", "2.1.2") {
considerSnapshots()
group("org.springframework.hateoas") { group("org.springframework.hateoas") {
modules = [ modules = [
"spring-hateoas" "spring-hateoas"
@ -1420,6 +1435,7 @@ bom {
} }
} }
library("Spring Integration", "6.1.2") { library("Spring Integration", "6.1.2") {
considerSnapshots()
group("org.springframework.integration") { group("org.springframework.integration") {
imports = [ imports = [
"spring-integration-bom" "spring-integration-bom"
@ -1427,6 +1443,7 @@ bom {
} }
} }
library("Spring Kafka", "3.0.10") { library("Spring Kafka", "3.0.10") {
considerSnapshots()
group("org.springframework.kafka") { group("org.springframework.kafka") {
modules = [ modules = [
"spring-kafka", "spring-kafka",
@ -1435,6 +1452,7 @@ bom {
} }
} }
library("Spring LDAP", "3.1.1") { library("Spring LDAP", "3.1.1") {
considerSnapshots()
group("org.springframework.ldap") { group("org.springframework.ldap") {
modules = [ modules = [
"spring-ldap-core", "spring-ldap-core",
@ -1445,6 +1463,7 @@ bom {
} }
} }
library("Spring RESTDocs", "3.0.0") { library("Spring RESTDocs", "3.0.0") {
considerSnapshots()
group("org.springframework.restdocs") { group("org.springframework.restdocs") {
imports = [ imports = [
"spring-restdocs-bom" "spring-restdocs-bom"
@ -1452,6 +1471,7 @@ bom {
} }
} }
library("Spring Retry", "2.0.2") { library("Spring Retry", "2.0.2") {
considerSnapshots()
group("org.springframework.retry") { group("org.springframework.retry") {
modules = [ modules = [
"spring-retry" "spring-retry"
@ -1459,6 +1479,7 @@ bom {
} }
} }
library("Spring Security", "6.1.3") { library("Spring Security", "6.1.3") {
considerSnapshots()
group("org.springframework.security") { group("org.springframework.security") {
imports = [ imports = [
"spring-security-bom" "spring-security-bom"
@ -1466,6 +1487,7 @@ bom {
} }
} }
library("Spring Session", "3.1.2") { library("Spring Session", "3.1.2") {
considerSnapshots()
prohibit { prohibit {
startsWith(["Apple-", "Bean-", "Corn-", "Dragonfruit-"]) startsWith(["Apple-", "Bean-", "Corn-", "Dragonfruit-"])
because "Spring Session switched to numeric version numbers" because "Spring Session switched to numeric version numbers"
@ -1477,6 +1499,7 @@ bom {
} }
} }
library("Spring WS", "4.0.5") { library("Spring WS", "4.0.5") {
considerSnapshots()
group("org.springframework.ws") { group("org.springframework.ws") {
imports = [ imports = [
"spring-ws-bom" "spring-ws-bom"

Loading…
Cancel
Save