Skip to content

Commit 79d9780

Browse files
committed
Merge branch '3.3.x'
Closes gh-43551
2 parents 6bcc41d + aa374bf commit 79d9780

File tree

9 files changed

+198
-101
lines changed

9 files changed

+198
-101
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public Library(String name, String calendarName, LibraryVersion version, List<Gr
101101
this.versionAlignment = versionAlignment;
102102
this.alignsWithBom = alignsWithBom;
103103
this.linkRootName = (linkRootName != null) ? linkRootName : generateLinkRootName(name);
104-
this.links = Collections.unmodifiableMap(new TreeMap<>(links));
104+
this.links = (links != null) ? Collections.unmodifiableMap(new TreeMap<>(links)) : Collections.emptyMap();
105105
}
106106

107107
private static String generateLinkRootName(String name) {
@@ -167,6 +167,15 @@ public List<Link> getLinks(String name) {
167167
return this.links.get(name);
168168
}
169169

170+
public String getNameAndVersion() {
171+
return getName() + " " + getVersion();
172+
}
173+
174+
public Library withVersion(LibraryVersion version) {
175+
return new Library(this.name, this.calendarName, version, this.groups, this.prohibitedVersions,
176+
this.considerSnapshots, this.versionAlignment, this.alignsWithBom, this.linkRootName, this.links);
177+
}
178+
170179
/**
171180
* A version or range of versions that are prohibited from being used in a bom.
172181
*/

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/InteractiveUpgradeResolver.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,42 @@ public List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Col
5151
for (Library library : libraries) {
5252
librariesByName.put(library.getName(), library);
5353
}
54-
List<LibraryWithVersionOptions> libraryUpdates = this.libraryUpdateResolver
55-
.findLibraryUpdates(librariesToUpgrade, librariesByName);
5654
try {
57-
return libraryUpdates.stream().map(this::resolveUpgrade).filter(Objects::nonNull).toList();
55+
return this.libraryUpdateResolver.findLibraryUpdates(librariesToUpgrade, librariesByName)
56+
.stream()
57+
.map(this::resolveUpgrade)
58+
.filter(Objects::nonNull)
59+
.toList();
5860
}
5961
catch (UpgradesInterruptedException ex) {
6062
return Collections.emptyList();
6163
}
6264
}
6365

6466
private Upgrade resolveUpgrade(LibraryWithVersionOptions libraryWithVersionOptions) {
65-
if (libraryWithVersionOptions.getVersionOptions().isEmpty()) {
67+
Library library = libraryWithVersionOptions.getLibrary();
68+
List<VersionOption> versionOptions = libraryWithVersionOptions.getVersionOptions();
69+
if (versionOptions.isEmpty()) {
6670
return null;
6771
}
68-
VersionOption defaultOption = new VersionOption(
69-
libraryWithVersionOptions.getLibrary().getVersion().getVersion());
72+
VersionOption defaultOption = new VersionOption(library.getVersion().getVersion());
73+
VersionOption selected = selectOption(defaultOption, library, versionOptions);
74+
return (selected.equals(defaultOption)) ? null : new Upgrade(library, selected.getVersion());
75+
}
76+
77+
private VersionOption selectOption(VersionOption defaultOption, Library library,
78+
List<VersionOption> versionOptions) {
7079
VersionOption selected = this.userInputHandler.askUser((questions) -> {
71-
String question = libraryWithVersionOptions.getLibrary().getName() + " "
72-
+ libraryWithVersionOptions.getLibrary().getVersion().getVersion();
80+
String question = library.getNameAndVersion();
7381
List<VersionOption> options = new ArrayList<>();
7482
options.add(defaultOption);
75-
options.addAll(libraryWithVersionOptions.getVersionOptions());
83+
options.addAll(versionOptions);
7684
return questions.selectOption(question, options, defaultOption);
7785
}).get();
7886
if (this.userInputHandler.interrupted()) {
7987
throw new UpgradesInterruptedException();
8088
}
81-
return (selected.equals(defaultOption)) ? null
82-
: new Upgrade(libraryWithVersionOptions.getLibrary(), selected.getVersion());
89+
return selected;
8390
}
8491

8592
static class UpgradesInterruptedException extends RuntimeException {

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MoveToSnapshots.java

+2-32
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.build.bom.bomr;
1818

1919
import java.time.OffsetDateTime;
20-
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.Map;
2322
import java.util.function.BiPredicate;
@@ -33,7 +32,6 @@
3332
import org.springframework.boot.build.bom.BomExtension;
3433
import org.springframework.boot.build.bom.Library;
3534
import org.springframework.boot.build.bom.bomr.ReleaseSchedule.Release;
36-
import org.springframework.boot.build.bom.bomr.github.Issue;
3735
import org.springframework.boot.build.bom.bomr.github.Milestone;
3836
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
3937
import org.springframework.boot.build.properties.BuildProperties;
@@ -67,38 +65,10 @@ void upgradeDependencies() {
6765
super.upgradeDependencies();
6866
}
6967

70-
@Override
71-
protected String issueTitle(Upgrade upgrade) {
72-
return "Upgrade to " + description(upgrade);
73-
}
74-
75-
private String description(Upgrade upgrade) {
76-
String snapshotVersion = upgrade.getVersion().toString();
77-
String releaseVersion = snapshotVersion.substring(0, snapshotVersion.length() - "-SNAPSHOT".length());
78-
return upgrade.getLibrary().getName() + " " + releaseVersion;
79-
}
80-
81-
@Override
82-
protected String issueBody(Upgrade upgrade, Issue existingUpgrade) {
83-
Library library = upgrade.getLibrary();
84-
String releaseNotesLink = library.getLinkUrl("releaseNotes");
85-
List<String> lines = new ArrayList<>();
86-
String description = description(upgrade);
87-
if (releaseNotesLink != null) {
88-
lines.add("Upgrade to [%s](%s).".formatted(description, releaseNotesLink));
89-
}
90-
else {
91-
lines.add("Upgrade to %s.".formatted(description));
92-
}
93-
if (existingUpgrade != null) {
94-
lines.add("Supersedes #" + existingUpgrade.getNumber());
95-
}
96-
return String.join("\n\n", lines);
97-
}
98-
9968
@Override
10069
protected String commitMessage(Upgrade upgrade, int issueNumber) {
101-
return "Start building against " + description(upgrade) + " snapshots" + "\n\nSee gh-" + issueNumber;
70+
return "Start building against " + upgrade.toRelease().getNameAndVersion() + " snapshots" + "\n\nSee gh-"
71+
+ issueNumber;
10272
}
10373

10474
@Override
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,30 +17,33 @@
1717
package org.springframework.boot.build.bom.bomr;
1818

1919
import org.springframework.boot.build.bom.Library;
20+
import org.springframework.boot.build.bom.Library.LibraryVersion;
2021
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
2122

2223
/**
2324
* An upgrade to change a {@link Library} to use a new version.
2425
*
2526
* @author Andy Wilkinson
27+
* @author Phillip Webb
28+
* @param from the library we're upgrading from
29+
* @param to the library we're upgrading to (may be a SNAPSHOT)
30+
* @param toRelease the release version of the library we're ultimately upgrading to
2631
*/
27-
final class Upgrade {
32+
record Upgrade(Library from, Library to, Library toRelease) {
2833

29-
private final Library library;
30-
31-
private final DependencyVersion version;
32-
33-
Upgrade(Library library, DependencyVersion version) {
34-
this.library = library;
35-
this.version = version;
34+
Upgrade(Library from, DependencyVersion to) {
35+
this(from, from.withVersion(new LibraryVersion(to)));
3636
}
3737

38-
Library getLibrary() {
39-
return this.library;
38+
Upgrade(Library from, Library to) {
39+
this(from, to, withReleaseVersion(to));
4040
}
4141

42-
DependencyVersion getVersion() {
43-
return this.version;
42+
private static Library withReleaseVersion(Library to) {
43+
String version = to.getVersion().toString();
44+
version = version.replace(".BUILD-SNAPSHOT", "");
45+
version = version.replace("-SNAPSHOT", "");
46+
return to.withVersion(new LibraryVersion(DependencyVersion.parse(version)));
4447
}
4548

4649
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeApplicator.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,16 +42,14 @@ class UpgradeApplicator {
4242

4343
Path apply(Upgrade upgrade) throws IOException {
4444
String buildFileContents = Files.readString(this.buildFile);
45-
Matcher matcher = Pattern.compile("library\\(\"" + upgrade.getLibrary().getName() + "\", \"(.+)\"\\)")
46-
.matcher(buildFileContents);
45+
String toName = upgrade.to().getName();
46+
Matcher matcher = Pattern.compile("library\\(\"" + toName + "\", \"(.+)\"\\)").matcher(buildFileContents);
4747
if (!matcher.find()) {
48-
matcher = Pattern
49-
.compile("library\\(\"" + upgrade.getLibrary().getName() + "\"\\) \\{\\s+version\\(\"(.+)\"\\)",
50-
Pattern.MULTILINE)
48+
matcher = Pattern.compile("library\\(\"" + toName + "\"\\) \\{\\s+version\\(\"(.+)\"\\)", Pattern.MULTILINE)
5149
.matcher(buildFileContents);
5250
if (!matcher.find()) {
53-
throw new IllegalStateException("Failed to find definition for library '"
54-
+ upgrade.getLibrary().getName() + "' in bom '" + this.buildFile + "'");
51+
throw new IllegalStateException("Failed to find definition for library '" + upgrade.to().getName()
52+
+ "' in bom '" + this.buildFile + "'");
5553
}
5654
}
5755
String version = matcher.group(1);
@@ -68,14 +66,14 @@ Path apply(Upgrade upgrade) throws IOException {
6866
private void updateGradleProperties(Upgrade upgrade, String version) throws IOException {
6967
String property = version.substring(2, version.length() - 1);
7068
String gradlePropertiesContents = Files.readString(this.gradleProperties);
71-
String modified = gradlePropertiesContents.replace(
72-
property + "=" + upgrade.getLibrary().getVersion().getVersion(), property + "=" + upgrade.getVersion());
69+
String modified = gradlePropertiesContents.replace(property + "=" + upgrade.from().getVersion(),
70+
property + "=" + upgrade.to().getVersion());
7371
overwrite(this.gradleProperties, modified);
7472
}
7573

7674
private void updateBuildFile(Upgrade upgrade, String buildFileContents, int versionStart, int versionEnd)
7775
throws IOException {
78-
String modified = buildFileContents.substring(0, versionStart) + upgrade.getVersion()
76+
String modified = buildFileContents.substring(0, versionStart) + upgrade.to().getVersion()
7977
+ buildFileContents.substring(versionEnd);
8078
overwrite(this.buildFile, modified);
8179
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeBom.java

-28
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.boot.build.bom.bomr;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
2219
import javax.inject.Inject;
2320

2421
import org.gradle.api.Task;
@@ -27,8 +24,6 @@
2724
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
2825

2926
import org.springframework.boot.build.bom.BomExtension;
30-
import org.springframework.boot.build.bom.Library.LibraryVersion;
31-
import org.springframework.boot.build.bom.bomr.github.Issue;
3227
import org.springframework.boot.build.properties.BuildProperties;
3328

3429
/**
@@ -63,32 +58,9 @@ private void addCommercialRepositories() {
6358
"spring-commercial-release");
6459
}
6560

66-
@Override
67-
protected String issueTitle(Upgrade upgrade) {
68-
return "Upgrade to " + upgrade.getLibrary().getName() + " " + upgrade.getVersion();
69-
}
70-
7161
@Override
7262
protected String commitMessage(Upgrade upgrade, int issueNumber) {
7363
return issueTitle(upgrade) + "\n\nCloses gh-" + issueNumber;
7464
}
7565

76-
@Override
77-
protected String issueBody(Upgrade upgrade, Issue existingUpgrade) {
78-
LibraryVersion upgradeVersion = new LibraryVersion(upgrade.getVersion());
79-
String releaseNotesLink = upgrade.getLibrary().getLinkUrl("releaseNotes");
80-
List<String> lines = new ArrayList<>();
81-
String description = upgrade.getLibrary().getName() + " " + upgradeVersion;
82-
if (releaseNotesLink != null) {
83-
lines.add("Upgrade to [%s](%s).".formatted(description, releaseNotesLink));
84-
}
85-
else {
86-
lines.add("Upgrade to %s.".formatted(description));
87-
}
88-
if (existingUpgrade != null) {
89-
lines.add("Supersedes #" + existingUpgrade.getNumber());
90-
}
91-
return String.join("\n\n", lines);
92-
}
93-
9466
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void applyUpgrades(GitHubRepository repository, List<String> issueLabels
118118
System.out.println("Applying upgrades...");
119119
System.out.println("");
120120
for (Upgrade upgrade : upgrades) {
121-
System.out.println(upgrade.getLibrary().getName() + " " + upgrade.getVersion());
121+
System.out.println(upgrade.to().getNameAndVersion());
122122
Issue existingUpgradeIssue = findExistingUpgradeIssue(existingUpgradeIssues, upgrade);
123123
try {
124124
Path modified = this.upgradeApplicator.apply(upgrade);
@@ -207,7 +207,7 @@ private Milestone determineMilestone(GitHubRepository repository) {
207207
}
208208

209209
private Issue findExistingUpgradeIssue(List<Issue> existingUpgradeIssues, Upgrade upgrade) {
210-
String toMatch = "Upgrade to " + upgrade.getLibrary().getName();
210+
String toMatch = "Upgrade to " + upgrade.toRelease().getName();
211211
for (Issue existingUpgradeIssue : existingUpgradeIssues) {
212212
String title = existingUpgradeIssue.getTitle();
213213
int lastSpaceIndex = title.lastIndexOf(' ');
@@ -285,10 +285,21 @@ protected boolean eligible(Library library) {
285285
return libraryPredicate.test(library.getName());
286286
}
287287

288-
protected abstract String issueTitle(Upgrade upgrade);
289-
290288
protected abstract String commitMessage(Upgrade upgrade, int issueNumber);
291289

292-
protected abstract String issueBody(Upgrade upgrade, Issue existingUpgrade);
290+
protected String issueTitle(Upgrade upgrade) {
291+
return "Upgrade to " + upgrade.toRelease().getNameAndVersion();
292+
}
293+
294+
protected String issueBody(Upgrade upgrade, Issue existingUpgrade) {
295+
String description = upgrade.toRelease().getNameAndVersion();
296+
String releaseNotesLink = upgrade.toRelease().getLinkUrl("releaseNotes");
297+
String body = (releaseNotesLink != null) ? "Upgrade to [%s](%s).".formatted(description, releaseNotesLink)
298+
: "Upgrade to %s.".formatted(description);
299+
if (existingUpgrade != null) {
300+
body += "\n\nSupersedes #" + existingUpgrade.getNumber();
301+
}
302+
return body;
303+
}
293304

294305
}

0 commit comments

Comments
 (0)