Merge branch '3.1.x'

Closes gh-37193
pull/37196/head
Andy Wilkinson 1 year ago
commit 809990bc86

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

@ -42,6 +42,8 @@ public class Library {
private final List<ProhibitedVersion> prohibitedVersions;
private final boolean considerSnapshots;
/**
* Create a new {@code Library} with the given {@code name}, {@code version}, and
* {@code groups}.
@ -49,15 +51,17 @@ public class Library {
* @param version version of the library
* @param groups groups in the library
* @param prohibitedVersions version of the library that are prohibited
* @param considerSnapshots whether to consider snapshots
*/
public Library(String name, LibraryVersion version, List<Group> groups,
List<ProhibitedVersion> prohibitedVersions) {
public Library(String name, LibraryVersion version, List<Group> groups, List<ProhibitedVersion> prohibitedVersions,
boolean considerSnapshots) {
this.name = name;
this.version = version;
this.groups = groups;
this.versionProperty = "Spring Boot".equals(name) ? null
: name.toLowerCase(Locale.ENGLISH).replace(' ', '-') + ".version";
this.prohibitedVersions = prohibitedVersions;
this.considerSnapshots = considerSnapshots;
}
public String getName() {
@ -80,6 +84,10 @@ public class Library {
return this.prohibitedVersions;
}
public boolean isConsiderSnapshots() {
return this.considerSnapshots;
}
/**
* 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.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
/**
* 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());
}
@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 StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()),
this.bom.getUpgrade().getPolicy())))
.resolveUpgrades(matchingLibraries(getLibraries().getOrNull()), this.bom.getLibraries());
.resolveUpgrades(matchingLibraries(), this.bom.getLibraries());
return upgrades;
}
private List<Library> matchingLibraries(String pattern) {
if (pattern == null) {
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();
private List<Library> matchingLibraries() {
List<Library> matchingLibraries = this.bom.getLibraries().stream().filter(this::eligible).toList();
if (matchingLibraries.isEmpty()) {
throw new InvalidUserDataException("No libraries matched '" + pattern + "'");
throw new InvalidUserDataException("No libraries to upgrade");
}
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 commitMessage(Upgrade upgrade, int issueNumber);

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

@ -989,6 +989,7 @@ bom {
}
}
library("Micrometer", "1.12.0-M2") {
considerSnapshots()
group("io.micrometer") {
modules = [
"micrometer-registry-stackdriver" {
@ -1001,6 +1002,7 @@ bom {
}
}
library("Micrometer Tracing", "1.2.0-M2") {
considerSnapshots()
group("io.micrometer") {
imports = [
"micrometer-tracing-bom"
@ -1145,6 +1147,7 @@ bom {
}
}
library("R2DBC H2", "1.0.0.RELEASE") {
considerSnapshots()
group("io.r2dbc") {
modules = [
"r2dbc-h2"
@ -1173,6 +1176,7 @@ bom {
}
}
library("R2DBC Pool", "1.0.1.RELEASE") {
considerSnapshots()
group("io.r2dbc") {
modules = [
"r2dbc-pool"
@ -1180,6 +1184,7 @@ bom {
}
}
library("R2DBC Postgresql", "1.0.2.RELEASE") {
considerSnapshots()
group("org.postgresql") {
modules = [
"r2dbc-postgresql"
@ -1187,6 +1192,7 @@ bom {
}
}
library("R2DBC Proxy", "1.1.2.RELEASE") {
considerSnapshots()
group("io.r2dbc") {
modules = [
"r2dbc-proxy"
@ -1194,6 +1200,7 @@ bom {
}
}
library("R2DBC SPI", "1.0.0.RELEASE") {
considerSnapshots()
group("io.r2dbc") {
modules = [
"r2dbc-spi"
@ -1222,6 +1229,7 @@ bom {
}
}
library("Reactor Bom", "2023.0.0-M2") {
considerSnapshots()
group("io.projectreactor") {
imports = [
"reactor-bom"
@ -1385,6 +1393,7 @@ bom {
}
}
library("Spring AMQP", "3.0.8") {
considerSnapshots()
group("org.springframework.amqp") {
imports = [
"spring-amqp-bom"
@ -1392,6 +1401,7 @@ bom {
}
}
library("Spring Authorization Server", "1.1.2") {
considerSnapshots()
group("org.springframework.security") {
modules = [
"spring-security-oauth2-authorization-server"
@ -1399,6 +1409,7 @@ bom {
}
}
library("Spring Batch", "5.1.0-M2") {
considerSnapshots()
group("org.springframework.batch") {
imports = [
"spring-batch-bom"
@ -1406,6 +1417,7 @@ bom {
}
}
library("Spring Data Bom", "2023.1.0-M2") {
considerSnapshots()
group("org.springframework.data") {
imports = [
"spring-data-bom"
@ -1413,6 +1425,7 @@ bom {
}
}
library("Spring Framework", "${springFrameworkVersion}") {
considerSnapshots()
group("org.springframework") {
imports = [
"spring-framework-bom"
@ -1420,6 +1433,7 @@ bom {
}
}
library("Spring GraphQL", "1.2.2") {
considerSnapshots()
group("org.springframework.graphql") {
modules = [
"spring-graphql",
@ -1428,6 +1442,7 @@ bom {
}
}
library("Spring HATEOAS", "2.2.0-M2") {
considerSnapshots()
group("org.springframework.hateoas") {
modules = [
"spring-hateoas"
@ -1435,6 +1450,7 @@ bom {
}
}
library("Spring Integration", "6.2.0-M2") {
considerSnapshots()
group("org.springframework.integration") {
imports = [
"spring-integration-bom"
@ -1442,6 +1458,7 @@ bom {
}
}
library("Spring Kafka", "3.0.10") {
considerSnapshots()
group("org.springframework.kafka") {
modules = [
"spring-kafka",
@ -1450,6 +1467,7 @@ bom {
}
}
library("Spring LDAP", "3.2.0-M2") {
considerSnapshots()
group("org.springframework.ldap") {
modules = [
"spring-ldap-core",
@ -1460,6 +1478,7 @@ bom {
}
}
library("Spring RESTDocs", "3.0.0") {
considerSnapshots()
group("org.springframework.restdocs") {
imports = [
"spring-restdocs-bom"
@ -1467,6 +1486,7 @@ bom {
}
}
library("Spring Retry", "2.0.2") {
considerSnapshots()
group("org.springframework.retry") {
modules = [
"spring-retry"
@ -1474,6 +1494,7 @@ bom {
}
}
library("Spring Security", "6.2.0-M2") {
considerSnapshots()
group("org.springframework.security") {
imports = [
"spring-security-bom"
@ -1481,6 +1502,7 @@ bom {
}
}
library("Spring Session", "3.2.0-M1") {
considerSnapshots()
prohibit {
startsWith(["Apple-", "Bean-", "Corn-", "Dragonfruit-"])
because "Spring Session switched to numeric version numbers"
@ -1492,6 +1514,7 @@ bom {
}
}
library("Spring WS", "4.0.5") {
considerSnapshots()
group("org.springframework.ws") {
imports = [
"spring-ws-bom"

Loading…
Cancel
Save