Merge branch '2.7.x'

Closes gh-31911
This commit is contained in:
Andy Wilkinson 2022-07-28 16:32:16 +01:00
commit 8436654614
3 changed files with 37 additions and 6 deletions

View File

@ -65,12 +65,12 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver {
}
@Override
public List<Upgrade> resolveUpgrades(Collection<Library> libraries) {
public List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Collection<Library> libraries) {
Map<String, Library> librariesByName = new HashMap<>();
for (Library library : libraries) {
librariesByName.put(library.getName(), library);
}
return libraries.stream().filter((library) -> !library.getName().equals("Spring Boot"))
return librariesToUpgrade.stream().filter((library) -> !library.getName().equals("Spring Boot"))
.map((library) -> resolveUpgrade(library, librariesByName)).filter(Objects::nonNull)
.collect(Collectors.toList());
}

View File

@ -28,6 +28,9 @@ import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.inject.Inject;
@ -42,6 +45,7 @@ import org.gradle.api.tasks.TaskExecutionException;
import org.gradle.api.tasks.options.Option;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.bom.bomr.github.GitHub;
import org.springframework.boot.build.bom.bomr.github.GitHubRepository;
import org.springframework.boot.build.bom.bomr.github.Issue;
@ -61,6 +65,8 @@ public class UpgradeBom extends DefaultTask {
private String milestone;
private String libraries;
@Inject
public UpgradeBom(BomExtension bom) {
this.bom = bom;
@ -83,6 +89,17 @@ public class UpgradeBom extends DefaultTask {
return this.milestone;
}
@Option(option = "libraries", description = "Regular expression that identifies the libraries to upgrade")
public void setLibraries(String libraries) {
this.libraries = libraries;
}
@Input
@org.gradle.api.tasks.Optional
public String getLibraries() {
return this.libraries;
}
@TaskAction
@SuppressWarnings("deprecation")
void upgradeDependencies() {
@ -100,7 +117,7 @@ public class UpgradeBom extends DefaultTask {
List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls),
this.bom.getUpgrade().getPolicy(), getServices().get(UserInputHandler.class))
.resolveUpgrades(this.bom.getLibraries());
.resolveUpgrades(matchingLibraries(this.libraries), this.bom.getLibraries());
Path buildFile = getProject().getBuildFile().toPath();
Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
UpgradeApplicator upgradeApplicator = new UpgradeApplicator(buildFile, gradleProperties);
@ -140,6 +157,19 @@ public class UpgradeBom extends DefaultTask {
}
}
private List<Library> matchingLibraries(String pattern) {
if (pattern == null) {
return this.bom.getLibraries();
}
Predicate<String> libraryPredicate = Pattern.compile(pattern).asPredicate();
List<Library> matchingLibraries = this.bom.getLibraries().stream()
.filter((library) -> libraryPredicate.test(library.getName())).collect(Collectors.toList());
if (matchingLibraries.isEmpty()) {
throw new InvalidUserDataException("No libraries matched '" + pattern + "'");
}
return matchingLibraries;
}
private Issue findExistingUpgradeIssue(List<Issue> existingUpgradeIssues, Upgrade upgrade) {
String toMatch = "Upgrade to " + upgrade.getLibrary().getName();
for (Issue existingUpgradeIssue : existingUpgradeIssues) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,9 +30,10 @@ interface UpgradeResolver {
/**
* Resolves the upgrades to be applied to the given {@code libraries}.
* @param libraries the libraries
* @param librariesToUpgrade the libraries to upgrade
* @param libraries all libraries
* @return the upgrades
*/
List<Upgrade> resolveUpgrades(Collection<Library> libraries);
List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Collection<Library> libraries);
}