mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +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.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -247,8 +248,8 @@ public class BomExtension {
|
|||||||
public void prohibit(Action<ProhibitedHandler> action) {
|
public void prohibit(Action<ProhibitedHandler> action) {
|
||||||
ProhibitedHandler handler = new ProhibitedHandler();
|
ProhibitedHandler handler = new ProhibitedHandler();
|
||||||
action.execute(handler);
|
action.execute(handler);
|
||||||
this.prohibitedVersions.add(
|
this.prohibitedVersions.add(new ProhibitedVersion(handler.versionRange, handler.startsWith,
|
||||||
new ProhibitedVersion(handler.versionRange, handler.endsWith, handler.contains, handler.reason));
|
handler.endsWith, handler.contains, handler.reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dependencyVersions(Action<DependencyVersionsHandler> action) {
|
public void dependencyVersions(Action<DependencyVersionsHandler> action) {
|
||||||
@ -272,9 +273,11 @@ public class BomExtension {
|
|||||||
|
|
||||||
private String reason;
|
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;
|
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) {
|
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) {
|
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) {
|
public void because(String because) {
|
||||||
|
@ -104,14 +104,18 @@ public class Library {
|
|||||||
|
|
||||||
private final VersionRange range;
|
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;
|
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.range = range;
|
||||||
|
this.startsWith = startsWith;
|
||||||
this.endsWith = endsWith;
|
this.endsWith = endsWith;
|
||||||
this.contains = contains;
|
this.contains = contains;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
@ -121,11 +125,15 @@ public class Library {
|
|||||||
return this.range;
|
return this.range;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEndsWith() {
|
public List<String> getStartsWith() {
|
||||||
|
return this.startsWith;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getEndsWith() {
|
||||||
return this.endsWith;
|
return this.endsWith;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContains() {
|
public List<String> getContains() {
|
||||||
return this.contains;
|
return this.contains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,21 +166,26 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPermitted(DependencyVersion dependencyVersion, List<ProhibitedVersion> prohibitedVersions) {
|
private boolean isPermitted(DependencyVersion dependencyVersion, List<ProhibitedVersion> prohibitedVersions) {
|
||||||
if (prohibitedVersions.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (ProhibitedVersion prohibitedVersion : prohibitedVersions) {
|
for (ProhibitedVersion prohibitedVersion : prohibitedVersions) {
|
||||||
|
String dependencyVersionToString = dependencyVersion.toString();
|
||||||
if (prohibitedVersion.getRange() != null && prohibitedVersion.getRange()
|
if (prohibitedVersion.getRange() != null && prohibitedVersion.getRange()
|
||||||
.containsVersion(new DefaultArtifactVersion(dependencyVersion.toString()))) {
|
.containsVersion(new DefaultArtifactVersion(dependencyVersionToString))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (prohibitedVersion.getEndsWith() != null
|
for (String startsWith : prohibitedVersion.getStartsWith()) {
|
||||||
&& dependencyVersion.toString().endsWith(prohibitedVersion.getEndsWith())) {
|
if (dependencyVersionToString.startsWith(startsWith)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (prohibitedVersion.getContains() != null
|
for (String endsWith : prohibitedVersion.getEndsWith()) {
|
||||||
&& dependencyVersion.toString().contains(prohibitedVersion.getContains())) {
|
if (dependencyVersionToString.endsWith(endsWith)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String contains : prohibitedVersion.getContains()) {
|
||||||
|
if (dependencyVersionToString.contains(contains)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
package org.springframework.boot.build.bom.bomr;
|
package org.springframework.boot.build.bom.bomr;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@ -52,7 +52,7 @@ final class MavenMetadataVersionResolver implements VersionResolver {
|
|||||||
private final Collection<String> repositoryUrls;
|
private final Collection<String> repositoryUrls;
|
||||||
|
|
||||||
MavenMetadataVersionResolver(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) {
|
MavenMetadataVersionResolver(RestTemplate restTemplate, Collection<String> repositoryUrls) {
|
||||||
@ -66,7 +66,7 @@ final class MavenMetadataVersionResolver implements VersionResolver {
|
|||||||
for (String repositoryUrl : this.repositoryUrls) {
|
for (String repositoryUrl : this.repositoryUrls) {
|
||||||
versions.addAll(resolveVersions(groupId, artifactId, repositoryUrl));
|
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) {
|
private Set<String> resolveVersions(String groupId, String artifactId, String repositoryUrl) {
|
||||||
|
@ -16,17 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.boot.build.bom.bomr.github;
|
package org.springframework.boot.build.bom.bomr.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.springframework.http.HttpRequest;
|
|
||||||
import org.springframework.http.MediaType;
|
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.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||||
@ -51,19 +46,13 @@ final class StandardGitHub implements GitHub {
|
|||||||
@Override
|
@Override
|
||||||
public GitHubRepository getRepository(String organization, String name) {
|
public GitHubRepository getRepository(String organization, String name) {
|
||||||
RestTemplate restTemplate = new RestTemplate(
|
RestTemplate restTemplate = new RestTemplate(
|
||||||
Arrays.asList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
||||||
restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
|
restTemplate.getInterceptors().add((request, body, execution) -> {
|
||||||
|
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
||||||
@Override
|
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder()
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
.encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
|
||||||
throws IOException {
|
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
return execution.execute(request, body);
|
||||||
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(
|
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory(
|
||||||
"https://api.github.com/repos/" + organization + "/" + name + "/");
|
"https://api.github.com/repos/" + organization + "/" + name + "/");
|
||||||
|
Loading…
Reference in New Issue
Block a user