@@ -51,35 +51,42 @@ public List<Upgrade> resolveUpgrades(Collection<Library> librariesToUpgrade, Col
51
51
for (Library library : libraries ) {
52
52
librariesByName .put (library .getName (), library );
53
53
}
54
- List <LibraryWithVersionOptions > libraryUpdates = this .libraryUpdateResolver
55
- .findLibraryUpdates (librariesToUpgrade , librariesByName );
56
54
try {
57
- return libraryUpdates .stream ().map (this ::resolveUpgrade ).filter (Objects ::nonNull ).toList ();
55
+ return this .libraryUpdateResolver .findLibraryUpdates (librariesToUpgrade , librariesByName )
56
+ .stream ()
57
+ .map (this ::resolveUpgrade )
58
+ .filter (Objects ::nonNull )
59
+ .toList ();
58
60
}
59
61
catch (UpgradesInterruptedException ex ) {
60
62
return Collections .emptyList ();
61
63
}
62
64
}
63
65
64
66
private Upgrade resolveUpgrade (LibraryWithVersionOptions libraryWithVersionOptions ) {
65
- if (libraryWithVersionOptions .getVersionOptions ().isEmpty ()) {
67
+ Library library = libraryWithVersionOptions .getLibrary ();
68
+ List <VersionOption > versionOptions = libraryWithVersionOptions .getVersionOptions ();
69
+ if (versionOptions .isEmpty ()) {
66
70
return null ;
67
71
}
68
- VersionOption defaultOption = new VersionOption (
69
- libraryWithVersionOptions .getLibrary ().getVersion ().getVersion ());
72
+ VersionOption defaultOption = new VersionOption (library .getVersion ().getVersion ());
73
+ VersionOption selected = selectOption (defaultOption , library , versionOptions );
74
+ return (selected .equals (defaultOption )) ? null : new Upgrade (library , selected .getVersion ());
75
+ }
76
+
77
+ private VersionOption selectOption (VersionOption defaultOption , Library library ,
78
+ List <VersionOption > versionOptions ) {
70
79
VersionOption selected = this .userInputHandler .askUser ((questions ) -> {
71
- String question = libraryWithVersionOptions .getLibrary ().getName () + " "
72
- + libraryWithVersionOptions .getLibrary ().getVersion ().getVersion ();
80
+ String question = library .getNameAndVersion ();
73
81
List <VersionOption > options = new ArrayList <>();
74
82
options .add (defaultOption );
75
- options .addAll (libraryWithVersionOptions . getVersionOptions () );
83
+ options .addAll (versionOptions );
76
84
return questions .selectOption (question , options , defaultOption );
77
85
}).get ();
78
86
if (this .userInputHandler .interrupted ()) {
79
87
throw new UpgradesInterruptedException ();
80
88
}
81
- return (selected .equals (defaultOption )) ? null
82
- : new Upgrade (libraryWithVersionOptions .getLibrary (), selected .getVersion ());
89
+ return selected ;
83
90
}
84
91
85
92
static class UpgradesInterruptedException extends RuntimeException {
0 commit comments