66
66
import org .springframework .boot .build .bom .Library .VersionAlignment ;
67
67
import org .springframework .boot .build .bom .bomr .version .DependencyVersion ;
68
68
import org .springframework .boot .build .mavenplugin .MavenExec ;
69
+ import org .springframework .boot .build .properties .BuildProperties ;
69
70
import org .springframework .util .FileCopyUtils ;
70
71
import org .springframework .util .PropertyPlaceholderHelper ;
71
72
import org .springframework .util .PropertyPlaceholderHelper .PlaceholderResolver ;
78
79
*/
79
80
public class BomExtension {
80
81
82
+ private final Project project ;
83
+
84
+ private final UpgradeHandler upgradeHandler ;
85
+
81
86
private final Map <String , DependencyVersion > properties = new LinkedHashMap <>();
82
87
83
88
private final Map <String , String > artifactVersionProperties = new HashMap <>();
84
89
85
90
private final List <Library > libraries = new ArrayList <>();
86
91
87
- private final UpgradeHandler upgradeHandler ;
88
-
89
- private final DependencyHandler dependencyHandler ;
90
-
91
- private final Project project ;
92
-
93
- public BomExtension (DependencyHandler dependencyHandler , Project project ) {
94
- this .dependencyHandler = dependencyHandler ;
95
- this .upgradeHandler = project .getObjects ().newInstance (UpgradeHandler .class );
92
+ public BomExtension (Project project ) {
96
93
this .project = project ;
94
+ this .upgradeHandler = project .getObjects ().newInstance (UpgradeHandler .class , project );
97
95
}
98
96
99
97
public List <Library > getLibraries () {
@@ -105,8 +103,9 @@ public void upgrade(Action<UpgradeHandler> action) {
105
103
}
106
104
107
105
public Upgrade getUpgrade () {
108
- return new Upgrade (this .upgradeHandler .upgradePolicy , new GitHub (this .upgradeHandler .gitHub .organization ,
109
- this .upgradeHandler .gitHub .repository , this .upgradeHandler .gitHub .issueLabels ));
106
+ GitHubHandler gitHub = this .upgradeHandler .gitHub ;
107
+ return new Upgrade (this .upgradeHandler .upgradePolicy ,
108
+ new GitHub (gitHub .organization , gitHub .repository , gitHub .issueLabels ));
110
109
}
111
110
112
111
public void library (String name , Action <LibraryHandler > action ) {
@@ -196,30 +195,38 @@ private void putArtifactVersionProperty(String groupId, String artifactId, Strin
196
195
}
197
196
198
197
private void addLibrary (Library library ) {
198
+ DependencyHandler dependencies = this .project .getDependencies ();
199
199
this .libraries .add (library );
200
200
String versionProperty = library .getVersionProperty ();
201
201
if (versionProperty != null ) {
202
202
this .properties .put (versionProperty , library .getVersion ().getVersion ());
203
203
}
204
204
for (Group group : library .getGroups ()) {
205
205
for (Module module : group .getModules ()) {
206
- putArtifactVersionProperty (group .getId (), module .getName (), module .getClassifier (), versionProperty );
207
- this .dependencyHandler .getConstraints ()
208
- .add (JavaPlatformPlugin .API_CONFIGURATION_NAME , createDependencyNotation (group .getId (),
209
- module .getName (), library .getVersion ().getVersion ()));
206
+ addModule (library , dependencies , versionProperty , group , module );
210
207
}
211
208
for (String bomImport : group .getBoms ()) {
212
- putArtifactVersionProperty (group .getId (), bomImport , versionProperty );
213
- String bomDependency = createDependencyNotation (group .getId (), bomImport ,
214
- library .getVersion ().getVersion ());
215
- this .dependencyHandler .add (JavaPlatformPlugin .API_CONFIGURATION_NAME ,
216
- this .dependencyHandler .platform (bomDependency ));
217
- this .dependencyHandler .add (BomPlugin .API_ENFORCED_CONFIGURATION_NAME ,
218
- this .dependencyHandler .enforcedPlatform (bomDependency ));
209
+ addBomImport (library , dependencies , versionProperty , group , bomImport );
219
210
}
220
211
}
221
212
}
222
213
214
+ private void addModule (Library library , DependencyHandler dependencies , String versionProperty , Group group ,
215
+ Module module ) {
216
+ putArtifactVersionProperty (group .getId (), module .getName (), module .getClassifier (), versionProperty );
217
+ String constraint = createDependencyNotation (group .getId (), module .getName (),
218
+ library .getVersion ().getVersion ());
219
+ dependencies .getConstraints ().add (JavaPlatformPlugin .API_CONFIGURATION_NAME , constraint );
220
+ }
221
+
222
+ private void addBomImport (Library library , DependencyHandler dependencies , String versionProperty , Group group ,
223
+ String bomImport ) {
224
+ putArtifactVersionProperty (group .getId (), bomImport , versionProperty );
225
+ String bomDependency = createDependencyNotation (group .getId (), bomImport , library .getVersion ().getVersion ());
226
+ dependencies .add (JavaPlatformPlugin .API_CONFIGURATION_NAME , dependencies .platform (bomDependency ));
227
+ dependencies .add (BomPlugin .API_ENFORCED_CONFIGURATION_NAME , dependencies .enforcedPlatform (bomDependency ));
228
+ }
229
+
223
230
public static class LibraryHandler {
224
231
225
232
private final List <Group > groups = new ArrayList <>();
@@ -501,7 +508,12 @@ public static class UpgradeHandler {
501
508
502
509
private UpgradePolicy upgradePolicy ;
503
510
504
- private final GitHubHandler gitHub = new GitHubHandler ();
511
+ private final GitHubHandler gitHub ;
512
+
513
+ @ Inject
514
+ public UpgradeHandler (Project project ) {
515
+ this .gitHub = new GitHubHandler (project );
516
+ }
505
517
506
518
public void setPolicy (UpgradePolicy upgradePolicy ) {
507
519
this .upgradePolicy = upgradePolicy ;
@@ -536,12 +548,18 @@ public GitHub getGitHub() {
536
548
537
549
public static class GitHubHandler {
538
550
539
- private String organization = "spring-projects" ;
551
+ private String organization ;
540
552
541
- private String repository = "spring-boot" ;
553
+ private String repository ;
542
554
543
555
private List <String > issueLabels ;
544
556
557
+ public GitHubHandler (Project project ) {
558
+ BuildProperties buildProperties = BuildProperties .get (project );
559
+ this .organization = buildProperties .gitHub ().organization ();
560
+ this .repository = buildProperties .gitHub ().repository ();
561
+ }
562
+
545
563
public void setOrganization (String organization ) {
546
564
this .organization = organization ;
547
565
}
@@ -558,9 +576,9 @@ public void setIssueLabels(List<String> issueLabels) {
558
576
559
577
public static final class GitHub {
560
578
561
- private String organization = "spring-projects" ;
579
+ private String organization ;
562
580
563
- private String repository = "spring-boot" ;
581
+ private String repository ;
564
582
565
583
private final List <String > issueLabels ;
566
584
0 commit comments