Skip to content

Commit

Permalink
Remove no longer needed special case for version suffixes
Browse files Browse the repository at this point in the history
We initially ignored -android and -jre suffixes that could be
found in Guava versions, but now that we don't treat suffixes as
unknown stability levels, we no longer need this special case.

This commit also adds test data for Guava, and for Kotlin versions.
  • Loading branch information
LouisCAD committed Sep 30, 2022
1 parent 06d908f commit 858417a
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,13 @@ data class Version(val value: String) : Comparable<Version> {

private val reverseStabilityComparator: Comparator<StabilityLevel> = compareByDescending { it }

private val knownVersionSuffixes = listOf("-android", "-jre")
private val knownStableKeywords = listOf("RELEASE", "FINAL", "GA")
private val digitsOnlyBasedVersionNumberRegex = "^[0-9,.v-]+$".toRegex()

private fun isDefinitelyStable(version: String): Boolean {
val uppercaseVersion = version.toUpperCase()
val hasStableKeyword = knownStableKeywords.any { it in uppercaseVersion }
return hasStableKeyword || digitsOnlyBasedVersionNumberRegex.matches(version.withoutKnownSuffixes())
return hasStableKeyword || digitsOnlyBasedVersionNumberRegex.matches(version)
}

private fun isStabilityLevelWithNumber(
Expand Down Expand Up @@ -182,7 +181,7 @@ data class Version(val value: String) : Comparable<Version> {
?: error("no lower version bound found in range: '$value'")
return lowerBound.toComparableList()
}
return value.withoutKnownStableKeywordsOrSuffixes().split(".", "-").flatMap {
return value.withoutKnownStableKeywords().split(".", "-").flatMap {
it.toBigIntegerOrNull()?.let { number -> listOf(number) }
?: it.findStabilityLevel(fullVersion = false)?.let { level ->
val indexOfLastNonDigit = it.indexOfLast { c -> c.isDigit().not() }
Expand All @@ -192,18 +191,6 @@ data class Version(val value: String) : Comparable<Version> {
}
}

private fun String.withoutKnownStableKeywordsOrSuffixes(): String {
return withoutKnownSuffixes().withoutKnownStableKeywords()
}

private fun String.withoutKnownSuffixes(): String {
var result: String = this
for (suffix in knownVersionSuffixes) {
result = result.removeSuffix(suffix)
}
return result
}

private fun String.withoutKnownStableKeywords(): String {
var result: String = this
for (suffix in knownStableKeywords) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
r03
r05
r06
r07
r08
r09
10.0-rc1
10.0-rc2
10.0-rc3
10.0
10.0.1
11.0-rc1
11.0
11.0.1
11.0.2
12.0-rc1
12.0-rc2
12.0
12.0.1
13.0-rc1
13.0-rc2
13.0
13.0.1
14.0-rc1
14.0-rc2
14.0-rc3
14.0
14.0.1
15.0-rc1
15.0
16.0-rc1
16.0
16.0.1
17.0-rc1
17.0-rc2
17.0
18.0-rc1
18.0-rc2
18.0
19.0-rc1
19.0-rc2
19.0-rc3
19.0
20.0-rc1
20.0
21.0-rc1
21.0-rc2
21.0
22.0-rc1
22.0-rc1-android
22.0
22.0-android
23.0-rc1
23.0-rc1-android
23.0
23.0-android
23.1-android
23.1-jre
23.2-android
23.2-jre
23.3-android
23.3-jre
23.4-android
23.4-jre
23.5-android
23.5-jre
23.6-android
23.6-jre
23.6.1-android
23.6.1-jre
24.0-android
24.0-jre
24.1-android
24.1-jre
24.1.1-android
24.1.1-jre
25.0-android
25.0-jre
25.1-android
25.1-jre
26.0-android
26.0-jre
27.0-android
27.0-jre
27.0.1-android
27.0.1-jre
27.1-android
27.1-jre
28.0-android
28.0-jre
28.1-android
28.1-jre
28.2-android
28.2-jre
29.0-android
29.0-jre
30.0-android
30.0-jre
30.1-android
30.1-jre
30.1.1-android
30.1.1-jre
31.0-android
31.0-jre
31.0.1-android
31.0.1-jre
31.1-android
31.1-jre
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
0.0.1-test-deploy
0.0.2-test-deploy
0.5.998
0.5.1131
0.6.22
0.6.31
0.6.69
0.6.179
0.6.317
0.6.350
0.6.594
0.6.602
0.6.786
0.6.800
0.6.912
0.6.1070
0.6.1315
0.6.1411
0.6.1507
0.6.1590
0.6.1603
0.6.1617
0.6.1658
0.6.1670
0.6.1673
0.6.1910
0.6.2451
0.6.2517
0.7.5
0.7.86
0.7.115
0.7.191
0.7.258
0.7.270
0.7.271
0.7.802
0.7.852
0.7.895
0.7.1090
0.7.1217
0.8.11
0.8.484
0.8.679
0.8.1527
0.9.0-native
0.9.1-native
0.9.66
0.9.206
0.9.976
0.10.4
0.10.195
0.10.709
0.10.770
0.10.1316
0.11.91
0.11.91.1
0.11.91.2
0.11.91.4
0.12.200
0.12.213
0.12.412
0.12.1218
0.12.1230
0.13.1513
0.13.1514
0.13.1516
0.14.449
0.14.451
1.0.0-beta-1038
1.0.0-beta-1103
1.0.0-beta-2417
1.0.0-beta-2422
1.0.0-beta-2423
1.0.0-beta-3593
1.0.0-beta-3594
1.0.0-beta-3595
1.0.0-beta-4583
1.0.0-beta-4584
1.0.0-beta-4589
1.0.0-rc-1036
1.0.0
1.0.1
1.0.1-1
1.0.1-2
1.0.2
1.0.2-1
1.0.3
1.0.4
1.0.5
1.0.5-2
1.0.5-3
1.0.6
1.0.7
1.1.0
1.1.1
1.1.2
1.1.2-2
1.1.2-3
1.1.2-4
1.1.2-5
1.1.3
1.1.3-2
1.1.4
1.1.4-2
1.1.4-3
1.1.50
1.1.51
1.1.60
1.1.61
1.2.0
1.2.10
1.2.20
1.2.21
1.2.30
1.2.31
1.2.40
1.2.41
1.2.50
1.2.51
1.2.60
1.2.61
1.2.70
1.2.71
1.3.0-rc-190
1.3.0-rc-198
1.3.0
1.3.10
1.3.11
1.3.20
1.3.21
1.3.30
1.3.31
1.3.40
1.3.41
1.3.50
1.3.60
1.3.61
1.3.70
1.3.71
1.3.72
1.4.0-rc
1.4.0
1.4.10
1.4.20-M1
1.4.20-M2
1.4.20-RC
1.4.20
1.4.21
1.4.21-2
1.4.30-M1
1.4.30-RC
1.4.30
1.4.31
1.4.32
1.5.0-M1
1.5.0-M2
1.5.0-RC
1.5.0
1.5.10
1.5.20-M1
1.5.20-RC
1.5.20
1.5.21
1.5.30-M1
1.5.30-RC
1.5.30
1.5.31
1.5.32
1.6.0-M1
1.6.0-RC
1.6.0-RC2
1.6.0
1.6.10-RC
1.6.10
1.6.20-M1
1.6.20-RC
1.6.20-RC2
1.6.20
1.6.21
1.7.0-Beta
1.7.0-RC
1.7.0-RC2
1.7.0
1.7.10
1.7.20-Beta
1.7.20-RC
1.7.20

0 comments on commit 858417a

Please sign in to comment.