65
65
import org .springframework .boot .build .bom .Library .VersionAlignment ;
66
66
import org .springframework .boot .build .bom .bomr .version .DependencyVersion ;
67
67
import org .springframework .boot .build .mavenplugin .MavenExec ;
68
+ import org .springframework .boot .build .properties .BuildProperties ;
68
69
import org .springframework .util .FileCopyUtils ;
69
70
70
71
/**
74
75
*/
75
76
public class BomExtension {
76
77
78
+ private final Project project ;
79
+
80
+ private final UpgradeHandler upgradeHandler ;
81
+
77
82
private final Map <String , DependencyVersion > properties = new LinkedHashMap <>();
78
83
79
84
private final Map <String , String > artifactVersionProperties = new HashMap <>();
80
85
81
86
private final List <Library > libraries = new ArrayList <>();
82
87
83
- private final UpgradeHandler upgradeHandler ;
84
-
85
- private final DependencyHandler dependencyHandler ;
86
-
87
- private final Project project ;
88
-
89
- public BomExtension (DependencyHandler dependencyHandler , Project project ) {
90
- this .dependencyHandler = dependencyHandler ;
91
- this .upgradeHandler = project .getObjects ().newInstance (UpgradeHandler .class );
88
+ public BomExtension (Project project ) {
92
89
this .project = project ;
90
+ this .upgradeHandler = project .getObjects ().newInstance (UpgradeHandler .class , project );
93
91
}
94
92
95
93
public List <Library > getLibraries () {
@@ -101,8 +99,9 @@ public void upgrade(Action<UpgradeHandler> action) {
101
99
}
102
100
103
101
public Upgrade getUpgrade () {
104
- return new Upgrade (this .upgradeHandler .upgradePolicy , new GitHub (this .upgradeHandler .gitHub .organization ,
105
- this .upgradeHandler .gitHub .repository , this .upgradeHandler .gitHub .issueLabels ));
102
+ GitHubHandler gitHub = this .upgradeHandler .gitHub ;
103
+ return new Upgrade (this .upgradeHandler .upgradePolicy ,
104
+ new GitHub (gitHub .organization , gitHub .repository , gitHub .issueLabels ));
106
105
}
107
106
108
107
public void library (String name , Action <LibraryHandler > action ) {
@@ -191,30 +190,38 @@ private void putArtifactVersionProperty(String groupId, String artifactId, Strin
191
190
}
192
191
193
192
private void addLibrary (Library library ) {
193
+ DependencyHandler dependencies = this .project .getDependencies ();
194
194
this .libraries .add (library );
195
195
String versionProperty = library .getVersionProperty ();
196
196
if (versionProperty != null ) {
197
197
this .properties .put (versionProperty , library .getVersion ().getVersion ());
198
198
}
199
199
for (Group group : library .getGroups ()) {
200
200
for (Module module : group .getModules ()) {
201
- putArtifactVersionProperty (group .getId (), module .getName (), module .getClassifier (), versionProperty );
202
- this .dependencyHandler .getConstraints ()
203
- .add (JavaPlatformPlugin .API_CONFIGURATION_NAME , createDependencyNotation (group .getId (),
204
- module .getName (), library .getVersion ().getVersion ()));
201
+ addModule (library , dependencies , versionProperty , group , module );
205
202
}
206
203
for (String bomImport : group .getBoms ()) {
207
- putArtifactVersionProperty (group .getId (), bomImport , versionProperty );
208
- String bomDependency = createDependencyNotation (group .getId (), bomImport ,
209
- library .getVersion ().getVersion ());
210
- this .dependencyHandler .add (JavaPlatformPlugin .API_CONFIGURATION_NAME ,
211
- this .dependencyHandler .platform (bomDependency ));
212
- this .dependencyHandler .add (BomPlugin .API_ENFORCED_CONFIGURATION_NAME ,
213
- this .dependencyHandler .enforcedPlatform (bomDependency ));
204
+ addBomImport (library , dependencies , versionProperty , group , bomImport );
214
205
}
215
206
}
216
207
}
217
208
209
+ private void addModule (Library library , DependencyHandler dependencies , String versionProperty , Group group ,
210
+ Module module ) {
211
+ putArtifactVersionProperty (group .getId (), module .getName (), module .getClassifier (), versionProperty );
212
+ String constraint = createDependencyNotation (group .getId (), module .getName (),
213
+ library .getVersion ().getVersion ());
214
+ dependencies .getConstraints ().add (JavaPlatformPlugin .API_CONFIGURATION_NAME , constraint );
215
+ }
216
+
217
+ private void addBomImport (Library library , DependencyHandler dependencies , String versionProperty , Group group ,
218
+ String bomImport ) {
219
+ putArtifactVersionProperty (group .getId (), bomImport , versionProperty );
220
+ String bomDependency = createDependencyNotation (group .getId (), bomImport , library .getVersion ().getVersion ());
221
+ dependencies .add (JavaPlatformPlugin .API_CONFIGURATION_NAME , dependencies .platform (bomDependency ));
222
+ dependencies .add (BomPlugin .API_ENFORCED_CONFIGURATION_NAME , dependencies .enforcedPlatform (bomDependency ));
223
+ }
224
+
218
225
public static class LibraryHandler {
219
226
220
227
private final List <Group > groups = new ArrayList <>();
@@ -421,7 +428,12 @@ public static class UpgradeHandler {
421
428
422
429
private UpgradePolicy upgradePolicy ;
423
430
424
- private final GitHubHandler gitHub = new GitHubHandler ();
431
+ private final GitHubHandler gitHub ;
432
+
433
+ @ Inject
434
+ public UpgradeHandler (Project project ) {
435
+ this .gitHub = new GitHubHandler (project );
436
+ }
425
437
426
438
public void setPolicy (UpgradePolicy upgradePolicy ) {
427
439
this .upgradePolicy = upgradePolicy ;
@@ -456,12 +468,18 @@ public GitHub getGitHub() {
456
468
457
469
public static class GitHubHandler {
458
470
459
- private String organization = "spring-projects" ;
471
+ private String organization ;
460
472
461
- private String repository = "spring-boot" ;
473
+ private String repository ;
462
474
463
475
private List <String > issueLabels ;
464
476
477
+ public GitHubHandler (Project project ) {
478
+ BuildProperties buildProperties = BuildProperties .get (project );
479
+ this .organization = buildProperties .gitHub ().organization ();
480
+ this .repository = buildProperties .gitHub ().repository ();
481
+ }
482
+
465
483
public void setOrganization (String organization ) {
466
484
this .organization = organization ;
467
485
}
@@ -478,9 +496,9 @@ public void setIssueLabels(List<String> issueLabels) {
478
496
479
497
public static final class GitHub {
480
498
481
- private String organization = "spring-projects" ;
499
+ private String organization ;
482
500
483
- private String repository = "spring-boot" ;
501
+ private String repository ;
484
502
485
503
private final List <String > issueLabels ;
486
504
0 commit comments