commit
8436654614
|
@ -65,12 +65,12 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Upgrade> resolveUpgrades(Collection<Library> libraries) {
|
public List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Collection<Library> libraries) {
|
||||||
Map<String, Library> librariesByName = new HashMap<>();
|
Map<String, Library> librariesByName = new HashMap<>();
|
||||||
for (Library library : libraries) {
|
for (Library library : libraries) {
|
||||||
librariesByName.put(library.getName(), library);
|
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)
|
.map((library) -> resolveUpgrade(library, librariesByName)).filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,9 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -42,6 +45,7 @@ import org.gradle.api.tasks.TaskExecutionException;
|
||||||
import org.gradle.api.tasks.options.Option;
|
import org.gradle.api.tasks.options.Option;
|
||||||
|
|
||||||
import org.springframework.boot.build.bom.BomExtension;
|
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.GitHub;
|
||||||
import org.springframework.boot.build.bom.bomr.github.GitHubRepository;
|
import org.springframework.boot.build.bom.bomr.github.GitHubRepository;
|
||||||
import org.springframework.boot.build.bom.bomr.github.Issue;
|
import org.springframework.boot.build.bom.bomr.github.Issue;
|
||||||
|
@ -61,6 +65,8 @@ public class UpgradeBom extends DefaultTask {
|
||||||
|
|
||||||
private String milestone;
|
private String milestone;
|
||||||
|
|
||||||
|
private String libraries;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UpgradeBom(BomExtension bom) {
|
public UpgradeBom(BomExtension bom) {
|
||||||
this.bom = bom;
|
this.bom = bom;
|
||||||
|
@ -83,6 +89,17 @@ public class UpgradeBom extends DefaultTask {
|
||||||
return this.milestone;
|
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
|
@TaskAction
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
void upgradeDependencies() {
|
void upgradeDependencies() {
|
||||||
|
@ -100,7 +117,7 @@ public class UpgradeBom extends DefaultTask {
|
||||||
List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
|
List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
|
||||||
List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls),
|
List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls),
|
||||||
this.bom.getUpgrade().getPolicy(), getServices().get(UserInputHandler.class))
|
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 buildFile = getProject().getBuildFile().toPath();
|
||||||
Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
|
Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
|
||||||
UpgradeApplicator upgradeApplicator = new UpgradeApplicator(buildFile, gradleProperties);
|
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) {
|
private Issue findExistingUpgradeIssue(List<Issue> existingUpgradeIssues, Upgrade upgrade) {
|
||||||
String toMatch = "Upgrade to " + upgrade.getLibrary().getName();
|
String toMatch = "Upgrade to " + upgrade.getLibrary().getName();
|
||||||
for (Issue existingUpgradeIssue : existingUpgradeIssues) {
|
for (Issue existingUpgradeIssue : existingUpgradeIssues) {
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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}.
|
* 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
|
* @return the upgrades
|
||||||
*/
|
*/
|
||||||
List<Upgrade> resolveUpgrades(Collection<Library> libraries);
|
List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Collection<Library> libraries);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue