1616
1717package org .springframework .boot .build .bom ;
1818
19- import java .io .BufferedReader ;
20- import java .io .IOException ;
21- import java .io .InputStreamReader ;
22- import java .net .URI ;
2319import java .util .Collections ;
24- import java .util .HashMap ;
2520import java .util .List ;
2621import java .util .Locale ;
27- import java .util .Map ;
28- import java .util .regex .Matcher ;
29- import java .util .regex .Pattern ;
3022
3123import org .apache .maven .artifact .versioning .VersionRange ;
32- import org .gradle .api .GradleException ;
3324
3425import org .springframework .boot .build .bom .bomr .version .DependencyVersion ;
3526
@@ -51,26 +42,22 @@ public class Library {
5142
5243 private final List <ProhibitedVersion > prohibitedVersions ;
5344
54- private final DependencyVersions dependencyVersions ;
55-
5645 /**
5746 * Create a new {@code Library} with the given {@code name}, {@code version}, and
5847 * {@code groups}.
5948 * @param name name of the library
6049 * @param version version of the library
6150 * @param groups groups in the library
6251 * @param prohibitedVersions version of the library that are prohibited
63- * @param dependencyVersions the library's dependency versions
6452 */
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 ) {
6755 this .name = name ;
6856 this .version = version ;
6957 this .groups = groups ;
7058 this .versionProperty = "Spring Boot" .equals (name ) ? null
7159 : name .toLowerCase (Locale .ENGLISH ).replace (' ' , '-' ) + ".version" ;
7260 this .prohibitedVersions = prohibitedVersions ;
73- this .dependencyVersions = dependencyVersions ;
7461 }
7562
7663 public String getName () {
@@ -93,10 +80,6 @@ public List<ProhibitedVersion> getProhibitedVersions() {
9380 return this .prohibitedVersions ;
9481 }
9582
96- public DependencyVersions getDependencyVersions () {
97- return this .dependencyVersions ;
98- }
99-
10083 /**
10184 * A version or range of versions that are prohibited from being used in a bom.
10285 */
@@ -147,21 +130,14 @@ public static class LibraryVersion {
147130
148131 private final DependencyVersion version ;
149132
150- private final VersionAlignment versionAlignment ;
151-
152- public LibraryVersion (DependencyVersion version , VersionAlignment versionAlignment ) {
133+ public LibraryVersion (DependencyVersion version ) {
153134 this .version = version ;
154- this .versionAlignment = versionAlignment ;
155135 }
156136
157137 public DependencyVersion getVersion () {
158138 return this .version ;
159139 }
160140
161- public VersionAlignment getVersionAlignment () {
162- return this .versionAlignment ;
163- }
164-
165141 }
166142
167143 /**
@@ -276,128 +252,4 @@ public String getArtifactId() {
276252
277253 }
278254
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-
403255}
0 commit comments