mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge branch '2.7.x'
This commit is contained in:
commit
600300c071
@ -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<ProhibitedHandler> 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<DependencyVersionsHandler> action) {
|
||||
@ -272,9 +273,11 @@ public class BomExtension {
|
||||
|
||||
private String reason;
|
||||
|
||||
private String endsWith;
|
||||
private final List<String> startsWith = new ArrayList<>();
|
||||
|
||||
private String contains;
|
||||
private final List<String> endsWith = new ArrayList<>();
|
||||
|
||||
private final List<String> 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<String> startsWith) {
|
||||
this.startsWith.addAll(startsWith);
|
||||
}
|
||||
|
||||
public void endsWith(String endsWith) {
|
||||
this.endsWith = endsWith;
|
||||
this.endsWith.add(endsWith);
|
||||
}
|
||||
|
||||
public void endsWith(Collection<String> endsWith) {
|
||||
this.endsWith.addAll(endsWith);
|
||||
}
|
||||
|
||||
public void contains(String contains) {
|
||||
this.contains = contains;
|
||||
this.contains.add(contains);
|
||||
}
|
||||
|
||||
public void contains(List<String> contains) {
|
||||
this.contains.addAll(contains);
|
||||
}
|
||||
|
||||
public void because(String because) {
|
||||
|
@ -104,14 +104,18 @@ public class Library {
|
||||
|
||||
private final VersionRange range;
|
||||
|
||||
private final String endsWith;
|
||||
private final List<String> startsWith;
|
||||
|
||||
private final String contains;
|
||||
private final List<String> endsWith;
|
||||
|
||||
private final List<String> contains;
|
||||
|
||||
private final String reason;
|
||||
|
||||
public ProhibitedVersion(VersionRange range, String endsWith, String contains, String reason) {
|
||||
public ProhibitedVersion(VersionRange range, List<String> startsWith, List<String> endsWith,
|
||||
List<String> 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<String> getStartsWith() {
|
||||
return this.startsWith;
|
||||
}
|
||||
|
||||
public List<String> getEndsWith() {
|
||||
return this.endsWith;
|
||||
}
|
||||
|
||||
public String getContains() {
|
||||
public List<String> getContains() {
|
||||
return this.contains;
|
||||
}
|
||||
|
||||
|
@ -166,21 +166,26 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver {
|
||||
}
|
||||
|
||||
private boolean isPermitted(DependencyVersion dependencyVersion, List<ProhibitedVersion> 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;
|
||||
|
@ -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<String> repositoryUrls;
|
||||
|
||||
MavenMetadataVersionResolver(Collection<String> repositoryUrls) {
|
||||
this(new RestTemplate(Arrays.asList(new StringHttpMessageConverter())), repositoryUrls);
|
||||
this(new RestTemplate(Collections.singletonList(new StringHttpMessageConverter())), repositoryUrls);
|
||||
}
|
||||
|
||||
MavenMetadataVersionResolver(RestTemplate restTemplate, Collection<String> 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<String> resolveVersions(String groupId, String artifactId, String repositoryUrl) {
|
||||
|
@ -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 + "/");
|
||||
|
Loading…
Reference in New Issue
Block a user