Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-31910
  • Loading branch information
wilkinsona committed Jul 28, 2022
2 parents 6786659 + 532285b commit 5370320
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Expand Up @@ -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());
}
Expand Down
Expand Up @@ -28,6 +28,9 @@
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;

Expand All @@ -42,6 +45,7 @@
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;
Expand All @@ -61,6 +65,8 @@ public class UpgradeBom extends DefaultTask {

private String milestone;

private String libraries;

@Inject
public UpgradeBom(BomExtension bom) {
this.bom = bom;
Expand All @@ -83,6 +89,17 @@ public String getMilestone() {
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() {
Expand All @@ -100,7 +117,7 @@ void upgradeDependencies() {
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);
Expand Down Expand Up @@ -140,6 +157,19 @@ void upgradeDependencies() {
}
}

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) {
Expand Down
@@ -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.
Expand Down Expand Up @@ -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);

}

0 comments on commit 5370320

Please sign in to comment.