28
28
import java .util .Optional ;
29
29
import java .util .Properties ;
30
30
import java .util .Set ;
31
+ import java .util .function .Predicate ;
32
+ import java .util .regex .Pattern ;
33
+ import java .util .stream .Collectors ;
31
34
32
35
import javax .inject .Inject ;
33
36
42
45
import org .gradle .api .tasks .options .Option ;
43
46
44
47
import org .springframework .boot .build .bom .BomExtension ;
48
+ import org .springframework .boot .build .bom .Library ;
45
49
import org .springframework .boot .build .bom .bomr .github .GitHub ;
46
50
import org .springframework .boot .build .bom .bomr .github .GitHubRepository ;
47
51
import org .springframework .boot .build .bom .bomr .github .Issue ;
@@ -61,6 +65,8 @@ public class UpgradeBom extends DefaultTask {
61
65
62
66
private String milestone ;
63
67
68
+ private String libraries ;
69
+
64
70
@ Inject
65
71
public UpgradeBom (BomExtension bom ) {
66
72
this .bom = bom ;
@@ -83,6 +89,17 @@ public String getMilestone() {
83
89
return this .milestone ;
84
90
}
85
91
92
+ @ Option (option = "libraries" , description = "Regular expression that identifies the libraries to upgrade" )
93
+ public void setLibraries (String libraries ) {
94
+ this .libraries = libraries ;
95
+ }
96
+
97
+ @ Input
98
+ @ org .gradle .api .tasks .Optional
99
+ public String getLibraries () {
100
+ return this .libraries ;
101
+ }
102
+
86
103
@ TaskAction
87
104
@ SuppressWarnings ("deprecation" )
88
105
void upgradeDependencies () {
@@ -100,7 +117,7 @@ void upgradeDependencies() {
100
117
List <Issue > existingUpgradeIssues = repository .findIssues (issueLabels , milestone );
101
118
List <Upgrade > upgrades = new InteractiveUpgradeResolver (new MavenMetadataVersionResolver (this .repositoryUrls ),
102
119
this .bom .getUpgrade ().getPolicy (), getServices ().get (UserInputHandler .class ))
103
- .resolveUpgrades (this .bom .getLibraries ());
120
+ .resolveUpgrades (matchingLibraries ( this . libraries ), this .bom .getLibraries ());
104
121
Path buildFile = getProject ().getBuildFile ().toPath ();
105
122
Path gradleProperties = new File (getProject ().getRootProject ().getProjectDir (), "gradle.properties" ).toPath ();
106
123
UpgradeApplicator upgradeApplicator = new UpgradeApplicator (buildFile , gradleProperties );
@@ -140,6 +157,19 @@ void upgradeDependencies() {
140
157
}
141
158
}
142
159
160
+ private List <Library > matchingLibraries (String pattern ) {
161
+ if (pattern == null ) {
162
+ return this .bom .getLibraries ();
163
+ }
164
+ Predicate <String > libraryPredicate = Pattern .compile (pattern ).asPredicate ();
165
+ List <Library > matchingLibraries = this .bom .getLibraries ().stream ()
166
+ .filter ((library ) -> libraryPredicate .test (library .getName ())).collect (Collectors .toList ());
167
+ if (matchingLibraries .isEmpty ()) {
168
+ throw new InvalidUserDataException ("No libraries matched '" + pattern + "'" );
169
+ }
170
+ return matchingLibraries ;
171
+ }
172
+
143
173
private Issue findExistingUpgradeIssue (List <Issue > existingUpgradeIssues , Upgrade upgrade ) {
144
174
String toMatch = "Upgrade to " + upgrade .getLibrary ().getName ();
145
175
for (Issue existingUpgradeIssue : existingUpgradeIssues ) {
0 commit comments