@@ -109,15 +109,20 @@ public BwcVersions(List<String> versionLines) {
109
109
}
110
110
111
111
protected BwcVersions (List <String > versionLines , Version currentVersionProperty ) {
112
- this (versionLines .stream ()
113
- .map (LINE_PATTERN ::matcher )
114
- .filter (Matcher ::matches )
115
- .map (match -> new Version (
116
- Integer .parseInt (match .group (1 )),
117
- Integer .parseInt (match .group (2 )),
118
- Integer .parseInt (match .group (3 ))
119
- ))
120
- .collect (Collectors .toCollection (TreeSet ::new )), currentVersionProperty );
112
+ this (
113
+ versionLines .stream ()
114
+ .map (LINE_PATTERN ::matcher )
115
+ .filter (Matcher ::matches )
116
+ .map (
117
+ match -> new Version (
118
+ Integer .parseInt (match .group (1 )),
119
+ Integer .parseInt (match .group (2 )),
120
+ Integer .parseInt (match .group (3 ))
121
+ )
122
+ )
123
+ .collect (Collectors .toCollection (TreeSet ::new )),
124
+ currentVersionProperty
125
+ );
121
126
}
122
127
123
128
// for testkit tests, until BwcVersions is extracted into an extension
@@ -140,27 +145,29 @@ public BwcVersions(SortedSet<Version> allVersions, Version currentVersionPropert
140
145
141
146
Map <Version , UnreleasedVersionInfo > unreleased = new HashMap <>();
142
147
for (Version unreleasedVersion : getUnreleased ()) {
143
- unreleased .put (unreleasedVersion ,
144
- new UnreleasedVersionInfo (unreleasedVersion , getBranchFor (unreleasedVersion ), getGradleProjectPathFor (unreleasedVersion )));
148
+ unreleased .put (
149
+ unreleasedVersion ,
150
+ new UnreleasedVersionInfo (unreleasedVersion , getBranchFor (unreleasedVersion ), getGradleProjectPathFor (unreleasedVersion ))
151
+ );
145
152
}
146
153
this .unreleased = Collections .unmodifiableMap (unreleased );
147
154
}
148
155
149
156
private void assertNoOlderThanTwoMajors () {
150
157
Set <Integer > majors = groupByMajor .keySet ();
151
158
if (majors .size () != 2 && currentVersion .getMinor () != 0 && currentVersion .getRevision () != 0 ) {
152
- throw new IllegalStateException (
153
- "Expected exactly 2 majors in parsed versions but found: " + majors
154
- );
159
+ throw new IllegalStateException ("Expected exactly 2 majors in parsed versions but found: " + majors );
155
160
}
156
161
}
157
162
158
163
private void assertCurrentVersionMatchesParsed (Version currentVersionProperty ) {
159
164
if (currentVersionProperty .equals (currentVersion ) == false ) {
160
165
throw new IllegalStateException (
161
- "Parsed versions latest version does not match the one configured in build properties. " +
162
- "Parsed latest version is " + currentVersion + " but the build has " +
163
- currentVersionProperty
166
+ "Parsed versions latest version does not match the one configured in build properties. "
167
+ + "Parsed latest version is "
168
+ + currentVersion
169
+ + " but the build has "
170
+ + currentVersionProperty
164
171
);
165
172
}
166
173
}
@@ -175,12 +182,7 @@ public UnreleasedVersionInfo unreleasedInfo(Version version) {
175
182
public void forPreviousUnreleased (Consumer <UnreleasedVersionInfo > consumer ) {
176
183
List <UnreleasedVersionInfo > collect = getUnreleased ().stream ()
177
184
.filter (version -> version .equals (currentVersion ) == false )
178
- .map (version -> new UnreleasedVersionInfo (
179
- version ,
180
- getBranchFor (version ),
181
- getGradleProjectPathFor (version )
182
- )
183
- )
185
+ .map (version -> new UnreleasedVersionInfo (version , getBranchFor (version ), getGradleProjectPathFor (version )))
184
186
.collect (Collectors .toList ());
185
187
186
188
collect .forEach (uvi -> consumer .accept (uvi ));
@@ -196,22 +198,18 @@ private String getGradleProjectPathFor(Version version) {
196
198
Map <Integer , List <Version >> releasedMajorGroupedByMinor = getReleasedMajorGroupedByMinor ();
197
199
198
200
if (version .getRevision () == 0 ) {
199
- List <Version > unreleasedStagedOrMinor = getUnreleased ().stream ()
200
- .filter (v -> v .getRevision () == 0 )
201
- .collect (Collectors .toList ());
201
+ List <Version > unreleasedStagedOrMinor = getUnreleased ().stream ().filter (v -> v .getRevision () == 0 ).collect (Collectors .toList ());
202
202
if (unreleasedStagedOrMinor .size () > 2 ) {
203
203
if (unreleasedStagedOrMinor .get (unreleasedStagedOrMinor .size () - 2 ).equals (version )) {
204
204
return ":distribution:bwc:minor" ;
205
- } else {
205
+ } else {
206
206
return ":distribution:bwc:staged" ;
207
207
}
208
208
} else {
209
209
return ":distribution:bwc:minor" ;
210
210
}
211
211
} else {
212
- if (releasedMajorGroupedByMinor
213
- .getOrDefault (version .getMinor (), emptyList ())
214
- .contains (version )) {
212
+ if (releasedMajorGroupedByMinor .getOrDefault (version .getMinor (), emptyList ()).contains (version )) {
215
213
return ":distribution:bwc:bugfix" ;
216
214
} else {
217
215
return ":distribution:bwc:maintenance" ;
@@ -229,7 +227,7 @@ private String getBranchFor(Version version) {
229
227
return "master" ;
230
228
case ":distribution:bwc:minor" :
231
229
// The .x branch will always point to the latest minor (for that major), so a "minor" project will be on the .x branch
232
- // unless there is more recent (higher) minor.
230
+ // unless there is more recent (higher) minor.
233
231
final Version latestInMajor = getLatestVersionByKey (groupByMajor , version .getMajor ());
234
232
if (latestInMajor .getMinor () == version .getMinor ()) {
235
233
return version .getMajor () + ".x" ;
@@ -279,23 +277,16 @@ public List<Version> getUnreleased() {
279
277
}
280
278
}
281
279
282
- return unmodifiableList (
283
- unreleased .stream ()
284
- .sorted ()
285
- .distinct ()
286
- .collect (Collectors .toList ())
287
- );
280
+ return unmodifiableList (unreleased .stream ().sorted ().distinct ().collect (Collectors .toList ()));
288
281
}
289
282
290
283
private Version getLatestInMinor (int major , int minor ) {
291
- return groupByMajor .get (major ).stream ()
292
- .filter (v -> v .getMinor () == minor )
293
- .max (Version ::compareTo )
294
- .orElse (null );
284
+ return groupByMajor .get (major ).stream ().filter (v -> v .getMinor () == minor ).max (Version ::compareTo ).orElse (null );
295
285
}
296
286
297
287
private Version getLatestVersionByKey (Map <Integer , List <Version >> groupByMajor , int key ) {
298
- return groupByMajor .getOrDefault (key , emptyList ()).stream ()
288
+ return groupByMajor .getOrDefault (key , emptyList ())
289
+ .stream ()
299
290
.max (Version ::compareTo )
300
291
.orElseThrow (() -> new IllegalStateException ("Unexpected number of versions in collection" ));
301
292
}
@@ -307,11 +298,9 @@ private Map<Integer, List<Version>> getReleasedMajorGroupedByMinor() {
307
298
final Map <Integer , List <Version >> groupByMinor ;
308
299
if (currentMajorVersions .size () == 1 ) {
309
300
// Current is an unreleased major: x.0.0 so we have to look for other unreleased versions in the previous major
310
- groupByMinor = previousMajorVersions .stream ()
311
- .collect (Collectors .groupingBy (Version ::getMinor , Collectors .toList ()));
301
+ groupByMinor = previousMajorVersions .stream ().collect (Collectors .groupingBy (Version ::getMinor , Collectors .toList ()));
312
302
} else {
313
- groupByMinor = currentMajorVersions .stream ()
314
- .collect (Collectors .groupingBy (Version ::getMinor , Collectors .toList ()));
303
+ groupByMinor = currentMajorVersions .stream ().collect (Collectors .groupingBy (Version ::getMinor , Collectors .toList ()));
315
304
}
316
305
return groupByMinor ;
317
306
}
@@ -321,37 +310,37 @@ public void compareToAuthoritative(List<Version> authoritativeReleasedVersions)
321
310
notReallyReleased .removeAll (authoritativeReleasedVersions );
322
311
if (notReallyReleased .isEmpty () == false ) {
323
312
throw new IllegalStateException (
324
- "out-of-date released versions" +
325
- "\n Following versions are not really released, but the build thinks they are: " + notReallyReleased
313
+ "out-of-date released versions"
314
+ + "\n Following versions are not really released, but the build thinks they are: "
315
+ + notReallyReleased
326
316
);
327
317
}
328
318
329
319
Set <Version > incorrectlyConsideredUnreleased = new HashSet <>(authoritativeReleasedVersions );
330
320
incorrectlyConsideredUnreleased .retainAll (getUnreleased ());
331
321
if (incorrectlyConsideredUnreleased .isEmpty () == false ) {
332
322
throw new IllegalStateException (
333
- "out-of-date released versions" +
334
- "\n Build considers versions unreleased, " +
335
- "but they are released according to an authoritative source: " + incorrectlyConsideredUnreleased +
336
- "\n The next versions probably needs to be added to Version.java (CURRENT doesn't count)."
323
+ "out-of-date released versions"
324
+ + "\n Build considers versions unreleased, "
325
+ + "but they are released according to an authoritative source: "
326
+ + incorrectlyConsideredUnreleased
327
+ + "\n The next versions probably needs to be added to Version.java (CURRENT doesn't count)."
337
328
);
338
329
}
339
330
}
340
331
341
332
private List <Version > getReleased () {
342
333
List <Version > unreleased = getUnreleased ();
343
- return groupByMajor .values ().stream ()
334
+ return groupByMajor .values ()
335
+ .stream ()
344
336
.flatMap (Collection ::stream )
345
337
.filter (each -> unreleased .contains (each ) == false )
346
338
.collect (Collectors .toList ());
347
339
}
348
340
349
341
public List <Version > getIndexCompatible () {
350
342
return unmodifiableList (
351
- Stream .concat (
352
- groupByMajor .get (currentVersion .getMajor () - 1 ).stream (),
353
- groupByMajor .get (currentVersion .getMajor ()).stream ()
354
- )
343
+ Stream .concat (groupByMajor .get (currentVersion .getMajor () - 1 ).stream (), groupByMajor .get (currentVersion .getMajor ()).stream ())
355
344
.collect (Collectors .toList ())
356
345
);
357
346
}
@@ -361,10 +350,7 @@ public List<Version> getWireCompatible() {
361
350
362
351
List <Version > prevMajors = groupByMajor .get (currentVersion .getMajor () - 1 );
363
352
int minor = prevMajors .get (prevMajors .size () - 1 ).getMinor ();
364
- for (int i = prevMajors .size () - 1 ;
365
- i > 0 && prevMajors .get (i ).getMinor () == minor ;
366
- i --
367
- ) {
353
+ for (int i = prevMajors .size () - 1 ; i > 0 && prevMajors .get (i ).getMinor () == minor ; i --) {
368
354
wireCompat .add (prevMajors .get (i ));
369
355
}
370
356
wireCompat .addAll (groupByMajor .get (currentVersion .getMajor ()));
0 commit comments