diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java index 5d674785f7..e938de69ca 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -247,8 +248,8 @@ public class BomExtension { public void prohibit(Action action) { ProhibitedHandler handler = new ProhibitedHandler(); action.execute(handler); - this.prohibitedVersions.add( - new ProhibitedVersion(handler.versionRange, handler.endsWith, handler.contains, handler.reason)); + this.prohibitedVersions.add(new ProhibitedVersion(handler.versionRange, handler.startsWith, + handler.endsWith, handler.contains, handler.reason)); } public void dependencyVersions(Action action) { @@ -272,9 +273,11 @@ public class BomExtension { private String reason; - private String endsWith; + private final List startsWith = new ArrayList<>(); - private String contains; + private final List endsWith = new ArrayList<>(); + + private final List contains = new ArrayList<>(); private VersionRange versionRange; @@ -287,12 +290,28 @@ public class BomExtension { } } + public void startsWith(String startsWith) { + this.startsWith.add(startsWith); + } + + public void startsWith(Collection startsWith) { + this.startsWith.addAll(startsWith); + } + public void endsWith(String endsWith) { - this.endsWith = endsWith; + this.endsWith.add(endsWith); + } + + public void endsWith(Collection endsWith) { + this.endsWith.addAll(endsWith); } public void contains(String contains) { - this.contains = contains; + this.contains.add(contains); + } + + public void contains(List contains) { + this.contains.addAll(contains); } public void because(String because) { diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java index aa9ca236a6..a7a9d8a83a 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java @@ -104,14 +104,18 @@ public class Library { private final VersionRange range; - private final String endsWith; + private final List startsWith; - private final String contains; + private final List endsWith; + + private final List contains; private final String reason; - public ProhibitedVersion(VersionRange range, String endsWith, String contains, String reason) { + public ProhibitedVersion(VersionRange range, List startsWith, List endsWith, + List contains, String reason) { this.range = range; + this.startsWith = startsWith; this.endsWith = endsWith; this.contains = contains; this.reason = reason; @@ -121,11 +125,15 @@ public class Library { return this.range; } - public String getEndsWith() { + public List getStartsWith() { + return this.startsWith; + } + + public List getEndsWith() { return this.endsWith; } - public String getContains() { + public List getContains() { return this.contains; } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/InteractiveUpgradeResolver.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/InteractiveUpgradeResolver.java index 31363b99f5..05df334544 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/InteractiveUpgradeResolver.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/InteractiveUpgradeResolver.java @@ -166,21 +166,26 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver { } private boolean isPermitted(DependencyVersion dependencyVersion, List prohibitedVersions) { - if (prohibitedVersions.isEmpty()) { - return true; - } for (ProhibitedVersion prohibitedVersion : prohibitedVersions) { + String dependencyVersionToString = dependencyVersion.toString(); if (prohibitedVersion.getRange() != null && prohibitedVersion.getRange() - .containsVersion(new DefaultArtifactVersion(dependencyVersion.toString()))) { + .containsVersion(new DefaultArtifactVersion(dependencyVersionToString))) { return false; } - if (prohibitedVersion.getEndsWith() != null - && dependencyVersion.toString().endsWith(prohibitedVersion.getEndsWith())) { - return false; + for (String startsWith : prohibitedVersion.getStartsWith()) { + if (dependencyVersionToString.startsWith(startsWith)) { + return false; + } } - if (prohibitedVersion.getContains() != null - && dependencyVersion.toString().contains(prohibitedVersion.getContains())) { - return false; + for (String endsWith : prohibitedVersion.getEndsWith()) { + if (dependencyVersionToString.endsWith(endsWith)) { + return false; + } + } + for (String contains : prohibitedVersion.getContains()) { + if (dependencyVersionToString.contains(contains)) { + return false; + } } } return true; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java index b52bc18cbb..40055926fc 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/MavenMetadataVersionResolver.java @@ -17,8 +17,8 @@ package org.springframework.boot.build.bom.bomr; import java.io.StringReader; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.SortedSet; @@ -52,7 +52,7 @@ final class MavenMetadataVersionResolver implements VersionResolver { private final Collection repositoryUrls; MavenMetadataVersionResolver(Collection repositoryUrls) { - this(new RestTemplate(Arrays.asList(new StringHttpMessageConverter())), repositoryUrls); + this(new RestTemplate(Collections.singletonList(new StringHttpMessageConverter())), repositoryUrls); } MavenMetadataVersionResolver(RestTemplate restTemplate, Collection repositoryUrls) { @@ -66,7 +66,7 @@ final class MavenMetadataVersionResolver implements VersionResolver { for (String repositoryUrl : this.repositoryUrls) { versions.addAll(resolveVersions(groupId, artifactId, repositoryUrl)); } - return new TreeSet<>(versions.stream().map(DependencyVersion::parse).collect(Collectors.toSet())); + return versions.stream().map(DependencyVersion::parse).collect(Collectors.toCollection(TreeSet::new)); } private Set resolveVersions(String groupId, String artifactId, String repositoryUrl) { diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/StandardGitHub.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/StandardGitHub.java index 5be432a0ac..6d41e3e551 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/StandardGitHub.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/StandardGitHub.java @@ -16,17 +16,12 @@ package org.springframework.boot.build.bom.bomr.github; -import java.io.IOException; -import java.util.Arrays; import java.util.Base64; +import java.util.Collections; import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.http.HttpRequest; import org.springframework.http.MediaType; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -51,19 +46,13 @@ final class StandardGitHub implements GitHub { @Override public GitHubRepository getRepository(String organization, String name) { RestTemplate restTemplate = new RestTemplate( - Arrays.asList(new MappingJackson2HttpMessageConverter(new ObjectMapper()))); - restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { - - @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) - throws IOException { - request.getHeaders().add("User-Agent", StandardGitHub.this.username); - request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString( - (StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes())); - request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE); - return execution.execute(request, body); - } - + Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper()))); + restTemplate.getInterceptors().add((request, body, execution) -> { + request.getHeaders().add("User-Agent", StandardGitHub.this.username); + request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder() + .encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes())); + request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE); + return execution.execute(request, body); }); UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory( "https://api.github.com/repos/" + organization + "/" + name + "/");