16
16
17
17
package org .springframework .boot .build .bom ;
18
18
19
- import java .io .BufferedReader ;
20
- import java .io .IOException ;
21
- import java .io .InputStreamReader ;
22
- import java .net .URI ;
23
19
import java .util .Collections ;
24
- import java .util .HashMap ;
25
20
import java .util .List ;
26
21
import java .util .Locale ;
27
- import java .util .Map ;
28
- import java .util .regex .Matcher ;
29
- import java .util .regex .Pattern ;
30
22
31
23
import org .apache .maven .artifact .versioning .VersionRange ;
32
- import org .gradle .api .GradleException ;
33
24
34
25
import org .springframework .boot .build .bom .bomr .version .DependencyVersion ;
35
26
@@ -51,26 +42,22 @@ public class Library {
51
42
52
43
private final List <ProhibitedVersion > prohibitedVersions ;
53
44
54
- private final DependencyVersions dependencyVersions ;
55
-
56
45
/**
57
46
* Create a new {@code Library} with the given {@code name}, {@code version}, and
58
47
* {@code groups}.
59
48
* @param name name of the library
60
49
* @param version version of the library
61
50
* @param groups groups in the library
62
51
* @param prohibitedVersions version of the library that are prohibited
63
- * @param dependencyVersions the library's dependency versions
64
52
*/
65
- public Library (String name , LibraryVersion version , List <Group > groups , List < ProhibitedVersion > prohibitedVersions ,
66
- DependencyVersions dependencyVersions ) {
53
+ public Library (String name , LibraryVersion version , List <Group > groups ,
54
+ List < ProhibitedVersion > prohibitedVersions ) {
67
55
this .name = name ;
68
56
this .version = version ;
69
57
this .groups = groups ;
70
58
this .versionProperty = "Spring Boot" .equals (name ) ? null
71
59
: name .toLowerCase (Locale .ENGLISH ).replace (' ' , '-' ) + ".version" ;
72
60
this .prohibitedVersions = prohibitedVersions ;
73
- this .dependencyVersions = dependencyVersions ;
74
61
}
75
62
76
63
public String getName () {
@@ -93,10 +80,6 @@ public List<ProhibitedVersion> getProhibitedVersions() {
93
80
return this .prohibitedVersions ;
94
81
}
95
82
96
- public DependencyVersions getDependencyVersions () {
97
- return this .dependencyVersions ;
98
- }
99
-
100
83
/**
101
84
* A version or range of versions that are prohibited from being used in a bom.
102
85
*/
@@ -147,21 +130,14 @@ public static class LibraryVersion {
147
130
148
131
private final DependencyVersion version ;
149
132
150
- private final VersionAlignment versionAlignment ;
151
-
152
- public LibraryVersion (DependencyVersion version , VersionAlignment versionAlignment ) {
133
+ public LibraryVersion (DependencyVersion version ) {
153
134
this .version = version ;
154
- this .versionAlignment = versionAlignment ;
155
135
}
156
136
157
137
public DependencyVersion getVersion () {
158
138
return this .version ;
159
139
}
160
140
161
- public VersionAlignment getVersionAlignment () {
162
- return this .versionAlignment ;
163
- }
164
-
165
141
}
166
142
167
143
/**
@@ -276,128 +252,4 @@ public String getArtifactId() {
276
252
277
253
}
278
254
279
- public interface DependencyVersions {
280
-
281
- String getVersion (String groupId , String artifactId );
282
-
283
- default boolean available () {
284
- return true ;
285
- }
286
-
287
- }
288
-
289
- public static class DependencyLockDependencyVersions implements DependencyVersions {
290
-
291
- private final Map <String , Map <String , String >> dependencyVersions = new HashMap <>();
292
-
293
- private final String sourceTemplate ;
294
-
295
- private final String libraryVersion ;
296
-
297
- public DependencyLockDependencyVersions (String sourceTemplate , String libraryVersion ) {
298
- this .sourceTemplate = sourceTemplate ;
299
- this .libraryVersion = libraryVersion ;
300
- }
301
-
302
- @ Override
303
- public boolean available () {
304
- return !this .libraryVersion .contains ("-SNAPSHOT" );
305
- }
306
-
307
- @ Override
308
- public String getVersion (String groupId , String artifactId ) {
309
- if (this .dependencyVersions .isEmpty ()) {
310
- loadVersions ();
311
- }
312
- return this .dependencyVersions .computeIfAbsent (groupId , (key ) -> Collections .emptyMap ()).get (artifactId );
313
- }
314
-
315
- private void loadVersions () {
316
- String source = this .sourceTemplate .replace ("<libraryVersion>" , this .libraryVersion );
317
- try {
318
- try (BufferedReader reader = new BufferedReader (
319
- new InputStreamReader (URI .create (source ).toURL ().openStream ()))) {
320
- String line ;
321
- while ((line = reader .readLine ()) != null ) {
322
- if (!line .startsWith ("#" )) {
323
- String [] components = line .split (":" );
324
- Map <String , String > groupDependencies = this .dependencyVersions
325
- .computeIfAbsent (components [0 ], (key ) -> new HashMap <>());
326
- groupDependencies .put (components [1 ], components [2 ]);
327
- }
328
- }
329
- }
330
- }
331
- catch (IOException ex ) {
332
- throw new GradleException ("Failed to load versions from dependency lock file '" + source + "'" , ex );
333
- }
334
- }
335
-
336
- }
337
-
338
- public static class DependencyConstraintsDependencyVersions implements DependencyVersions {
339
-
340
- private static final Pattern CONSTRAINT_PATTERN = Pattern .compile ("api \" (.+):(.+):(.+)\" " );
341
-
342
- private final Map <String , Map <String , String >> dependencyVersions = new HashMap <>();
343
-
344
- private final String sourceTemplate ;
345
-
346
- private final String libraryVersion ;
347
-
348
- public DependencyConstraintsDependencyVersions (String sourceTemplate , String libraryVersion ) {
349
- this .sourceTemplate = sourceTemplate ;
350
- this .libraryVersion = libraryVersion ;
351
- }
352
-
353
- @ Override
354
- public String getVersion (String groupId , String artifactId ) {
355
- if (this .dependencyVersions .isEmpty ()) {
356
- loadVersions ();
357
- }
358
- return this .dependencyVersions .computeIfAbsent (groupId , (key ) -> Collections .emptyMap ()).get (artifactId );
359
- }
360
-
361
- private void loadVersions () {
362
- String version = this .libraryVersion ;
363
- if (version .endsWith ("-SNAPSHOT" )) {
364
- version = version .substring (0 , version .lastIndexOf ('.' )) + ".x" ;
365
- }
366
- String source = this .sourceTemplate .replace ("<libraryVersion>" , version );
367
- try {
368
- try (BufferedReader reader = new BufferedReader (
369
- new InputStreamReader (URI .create (source ).toURL ().openStream ()))) {
370
- String line ;
371
- while ((line = reader .readLine ()) != null ) {
372
- Matcher matcher = CONSTRAINT_PATTERN .matcher (line .trim ());
373
- if (matcher .matches ()) {
374
- Map <String , String > groupDependencies = this .dependencyVersions
375
- .computeIfAbsent (matcher .group (1 ), (key ) -> new HashMap <>());
376
- groupDependencies .put (matcher .group (2 ), matcher .group (3 ));
377
- }
378
- }
379
- }
380
- }
381
- catch (IOException ex ) {
382
- throw new GradleException (
383
- "Failed to load versions from dependency constraints declared in '" + source + "'" , ex );
384
- }
385
- }
386
-
387
- }
388
-
389
- public static class VersionAlignment {
390
-
391
- private final String libraryName ;
392
-
393
- public VersionAlignment (String libraryName ) {
394
- this .libraryName = libraryName ;
395
- }
396
-
397
- public String getLibraryName () {
398
- return this .libraryName ;
399
- }
400
-
401
- }
402
-
403
255
}
0 commit comments