|
|
|
|
@ -16,18 +16,25 @@
@@ -16,18 +16,25 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.build.bom; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.TreeSet; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import javax.inject.Inject; |
|
|
|
|
|
|
|
|
|
import org.apache.maven.artifact.versioning.ArtifactVersion; |
|
|
|
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; |
|
|
|
|
import org.apache.maven.artifact.versioning.Restriction; |
|
|
|
|
import org.apache.maven.artifact.versioning.VersionRange; |
|
|
|
|
import org.gradle.api.DefaultTask; |
|
|
|
|
import org.gradle.api.InvalidUserDataException; |
|
|
|
|
import org.gradle.api.GradleException; |
|
|
|
|
import org.gradle.api.tasks.TaskAction; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.build.bom.Library.Group; |
|
|
|
|
import org.springframework.boot.build.bom.Library.Module; |
|
|
|
|
import org.springframework.boot.build.bom.Library.ProhibitedVersion; |
|
|
|
|
import org.springframework.boot.build.bom.bomr.version.DependencyVersion; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -46,18 +53,41 @@ public class CheckBom extends DefaultTask {
@@ -46,18 +53,41 @@ public class CheckBom extends DefaultTask {
|
|
|
|
|
|
|
|
|
|
@TaskAction |
|
|
|
|
void checkBom() { |
|
|
|
|
List<String> errors = new ArrayList<>(); |
|
|
|
|
for (Library library : this.bom.getLibraries()) { |
|
|
|
|
for (Group group : library.getGroups()) { |
|
|
|
|
for (Module module : group.getModules()) { |
|
|
|
|
if (!module.getExclusions().isEmpty()) { |
|
|
|
|
checkExclusions(group.getId(), module, library.getVersion().getVersion()); |
|
|
|
|
} |
|
|
|
|
checkLibrary(library, errors); |
|
|
|
|
} |
|
|
|
|
if (!errors.isEmpty()) { |
|
|
|
|
System.out.println(); |
|
|
|
|
errors.forEach(System.out::println); |
|
|
|
|
System.out.println(); |
|
|
|
|
throw new GradleException("Bom check failed. See previous output for details."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkLibrary(Library library, List<String> errors) { |
|
|
|
|
List<String> libraryErrors = new ArrayList<>(); |
|
|
|
|
checkExclusions(library, libraryErrors); |
|
|
|
|
checkProhibitedVersions(library, libraryErrors); |
|
|
|
|
if (!libraryErrors.isEmpty()) { |
|
|
|
|
errors.add(library.getName()); |
|
|
|
|
for (String libraryError : libraryErrors) { |
|
|
|
|
errors.add(" - " + libraryError); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkExclusions(Library library, List<String> errors) { |
|
|
|
|
for (Group group : library.getGroups()) { |
|
|
|
|
for (Module module : group.getModules()) { |
|
|
|
|
if (!module.getExclusions().isEmpty()) { |
|
|
|
|
checkExclusions(group.getId(), module, library.getVersion().getVersion(), errors); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkExclusions(String groupId, Module module, DependencyVersion version) { |
|
|
|
|
private void checkExclusions(String groupId, Module module, DependencyVersion version, List<String> errors) { |
|
|
|
|
Set<String> resolved = getProject().getConfigurations() |
|
|
|
|
.detachedConfiguration( |
|
|
|
|
getProject().getDependencies().create(groupId + ":" + module.getName() + ":" + version)) |
|
|
|
|
@ -87,8 +117,34 @@ public class CheckBom extends DefaultTask {
@@ -87,8 +117,34 @@ public class CheckBom extends DefaultTask {
|
|
|
|
|
} |
|
|
|
|
exclusions.removeAll(resolved); |
|
|
|
|
if (!unused.isEmpty()) { |
|
|
|
|
throw new InvalidUserDataException( |
|
|
|
|
"Unnecessary exclusions on " + groupId + ":" + module.getName() + ": " + exclusions); |
|
|
|
|
errors.add("Unnecessary exclusions on " + groupId + ":" + module.getName() + ": " + exclusions); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkProhibitedVersions(Library library, List<String> errors) { |
|
|
|
|
ArtifactVersion currentVersion = new DefaultArtifactVersion(library.getVersion().getVersion().toString()); |
|
|
|
|
for (ProhibitedVersion prohibited : library.getProhibitedVersions()) { |
|
|
|
|
if (prohibited.isProhibited(library.getVersion().getVersion().toString())) { |
|
|
|
|
errors.add("Current version " + currentVersion + " is prohibited"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
VersionRange versionRange = prohibited.getRange(); |
|
|
|
|
if (versionRange != null) { |
|
|
|
|
for (Restriction restriction : versionRange.getRestrictions()) { |
|
|
|
|
ArtifactVersion upperBound = restriction.getUpperBound(); |
|
|
|
|
if (upperBound == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
int comparison = currentVersion.compareTo(upperBound); |
|
|
|
|
if ((restriction.isUpperBoundInclusive() && comparison <= 0) |
|
|
|
|
|| ((!restriction.isUpperBoundInclusive()) && comparison < 0)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
errors.add("Version range " + versionRange + " is ineffective as the current version, " |
|
|
|
|
+ currentVersion + ", is greater than its upper bound"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|