Skip to content

Commit 47cac96

Browse files
committed
Merge branch '3.1.x'
Closes gh-38253
2 parents b9a5bdc + b2c5976 commit 47cac96

File tree

5 files changed

+80
-27
lines changed

5 files changed

+80
-27
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public void apply(Project project) {
6262
createApiEnforcedConfiguration(project);
6363
BomExtension bom = project.getExtensions()
6464
.create("bom", BomExtension.class, project.getDependencies(), project);
65-
project.getTasks().create("bomrCheck", CheckBom.class, bom);
65+
CheckBom checkBom = project.getTasks().create("bomrCheck", CheckBom.class, bom);
66+
project.getTasks().named("check").configure((check) -> check.dependsOn(checkBom));
6667
project.getTasks().create("bomrUpgrade", UpgradeBom.class, bom);
6768
project.getTasks().create("moveToSnapshots", MoveToSnapshots.class, bom);
6869
new PublishingCustomizer(project, bom).customize();

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

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616

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

19+
import java.util.ArrayList;
20+
import java.util.List;
1921
import java.util.Set;
2022
import java.util.TreeSet;
2123
import java.util.stream.Collectors;
2224

2325
import javax.inject.Inject;
2426

27+
import org.apache.maven.artifact.versioning.ArtifactVersion;
28+
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
29+
import org.apache.maven.artifact.versioning.Restriction;
30+
import org.apache.maven.artifact.versioning.VersionRange;
2531
import org.gradle.api.DefaultTask;
26-
import org.gradle.api.InvalidUserDataException;
32+
import org.gradle.api.GradleException;
2733
import org.gradle.api.tasks.TaskAction;
2834

2935
import org.springframework.boot.build.bom.Library.Group;
3036
import org.springframework.boot.build.bom.Library.Module;
37+
import org.springframework.boot.build.bom.Library.ProhibitedVersion;
3138
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
3239

3340
/**
@@ -46,18 +53,41 @@ public CheckBom(BomExtension bom) {
4653

4754
@TaskAction
4855
void checkBom() {
56+
List<String> errors = new ArrayList<>();
4957
for (Library library : this.bom.getLibraries()) {
50-
for (Group group : library.getGroups()) {
51-
for (Module module : group.getModules()) {
52-
if (!module.getExclusions().isEmpty()) {
53-
checkExclusions(group.getId(), module, library.getVersion().getVersion());
54-
}
58+
checkLibrary(library, errors);
59+
}
60+
if (!errors.isEmpty()) {
61+
System.out.println();
62+
errors.forEach(System.out::println);
63+
System.out.println();
64+
throw new GradleException("Bom check failed. See previous output for details.");
65+
}
66+
}
67+
68+
private void checkLibrary(Library library, List<String> errors) {
69+
List<String> libraryErrors = new ArrayList<>();
70+
checkExclusions(library, libraryErrors);
71+
checkProhibitedVersions(library, libraryErrors);
72+
if (!libraryErrors.isEmpty()) {
73+
errors.add(library.getName());
74+
for (String libraryError : libraryErrors) {
75+
errors.add(" - " + libraryError);
76+
}
77+
}
78+
}
79+
80+
private void checkExclusions(Library library, List<String> errors) {
81+
for (Group group : library.getGroups()) {
82+
for (Module module : group.getModules()) {
83+
if (!module.getExclusions().isEmpty()) {
84+
checkExclusions(group.getId(), module, library.getVersion().getVersion(), errors);
5585
}
5686
}
5787
}
5888
}
5989

60-
private void checkExclusions(String groupId, Module module, DependencyVersion version) {
90+
private void checkExclusions(String groupId, Module module, DependencyVersion version, List<String> errors) {
6191
Set<String> resolved = getProject().getConfigurations()
6292
.detachedConfiguration(
6393
getProject().getDependencies().create(groupId + ":" + module.getName() + ":" + version))
@@ -87,8 +117,34 @@ private void checkExclusions(String groupId, Module module, DependencyVersion ve
87117
}
88118
exclusions.removeAll(resolved);
89119
if (!unused.isEmpty()) {
90-
throw new InvalidUserDataException(
91-
"Unnecessary exclusions on " + groupId + ":" + module.getName() + ": " + exclusions);
120+
errors.add("Unnecessary exclusions on " + groupId + ":" + module.getName() + ": " + exclusions);
121+
}
122+
}
123+
124+
private void checkProhibitedVersions(Library library, List<String> errors) {
125+
ArtifactVersion currentVersion = new DefaultArtifactVersion(library.getVersion().getVersion().toString());
126+
for (ProhibitedVersion prohibited : library.getProhibitedVersions()) {
127+
if (prohibited.isProhibited(library.getVersion().getVersion().toString())) {
128+
errors.add("Current version " + currentVersion + " is prohibited");
129+
}
130+
else {
131+
VersionRange versionRange = prohibited.getRange();
132+
if (versionRange != null) {
133+
for (Restriction restriction : versionRange.getRestrictions()) {
134+
ArtifactVersion upperBound = restriction.getUpperBound();
135+
if (upperBound == null) {
136+
return;
137+
}
138+
int comparison = currentVersion.compareTo(upperBound);
139+
if ((restriction.isUpperBoundInclusive() && comparison <= 0)
140+
|| ((!restriction.isUpperBoundInclusive()) && comparison < 0)) {
141+
return;
142+
}
143+
}
144+
errors.add("Version range " + versionRange + " is ineffective as the current version, "
145+
+ currentVersion + ", is greater than its upper bound");
146+
}
147+
}
92148
}
93149
}
94150

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Locale;
2222

23+
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
2324
import org.apache.maven.artifact.versioning.VersionRange;
2425

2526
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
@@ -141,6 +142,16 @@ public String getReason() {
141142
return this.reason;
142143
}
143144

145+
public boolean isProhibited(String candidate) {
146+
boolean result = false;
147+
result = result
148+
|| (this.range != null && this.range.containsVersion(new DefaultArtifactVersion(candidate)));
149+
result = result || this.startsWith.stream().anyMatch(candidate::startsWith);
150+
result = result || this.endsWith.stream().anyMatch(candidate::endsWith);
151+
result = result || this.contains.stream().anyMatch(candidate::contains);
152+
return result;
153+
}
154+
144155
}
145156

146157
public static class LibraryVersion {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
import javax.inject.Inject;
3535

36-
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
37-
import org.apache.maven.artifact.versioning.VersionRange;
3836
import org.gradle.api.DefaultTask;
3937
import org.gradle.api.InvalidUserDataException;
4038
import org.gradle.api.internal.tasks.userinput.UserInputHandler;
@@ -48,7 +46,6 @@
4846

4947
import org.springframework.boot.build.bom.BomExtension;
5048
import org.springframework.boot.build.bom.Library;
51-
import org.springframework.boot.build.bom.Library.ProhibitedVersion;
5249
import org.springframework.boot.build.bom.bomr.github.GitHub;
5350
import org.springframework.boot.build.bom.bomr.github.GitHubRepository;
5451
import org.springframework.boot.build.bom.bomr.github.Issue;
@@ -246,17 +243,7 @@ private boolean isAnUpgrade(Library library, DependencyVersion candidate) {
246243
private boolean isNotProhibited(Library library, DependencyVersion candidate) {
247244
return !library.getProhibitedVersions()
248245
.stream()
249-
.anyMatch((prohibited) -> isProhibited(prohibited, candidate.toString()));
250-
}
251-
252-
private boolean isProhibited(ProhibitedVersion prohibited, String candidate) {
253-
boolean result = false;
254-
VersionRange range = prohibited.getRange();
255-
result = result || (range != null && range.containsVersion(new DefaultArtifactVersion(candidate)));
256-
result = result || prohibited.getStartsWith().stream().anyMatch(candidate::startsWith);
257-
result = result || prohibited.getStartsWith().stream().anyMatch(candidate::endsWith);
258-
result = result || prohibited.getStartsWith().stream().anyMatch(candidate::contains);
259-
return result;
246+
.anyMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
260247
}
261248

262249
private List<Library> matchingLibraries() {

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ bom {
159159
"java-driver-bom"
160160
]
161161
modules = [
162-
"java-driver-core" {
163-
exclude group: "org.slf4j", module: "jcl-over-slf4j"
164-
}
162+
"java-driver-core"
165163
]
166164
}
167165
}

0 commit comments

Comments
 (0)