handle rc versions of gradle in version compare (#141612)
- handle number format exceptions and strip rc information from version compare - add test that handles rc format part 2/n https://github.com/flutter/flutter/issues/138523 Helpfully pointed out by [asaarnak](https://github.com/asaarnak) https://github.com/flutter/flutter/pull/139325#issuecomment-1892554584
This commit is contained in:
parent
2442603cfc
commit
2b890af939
@ -450,5 +450,6 @@ Future<void> main() async {
|
|||||||
await task(combine(<TaskFunction>[
|
await task(combine(<TaskFunction>[
|
||||||
// ignore: avoid_redundant_argument_values
|
// ignore: avoid_redundant_argument_values
|
||||||
ModuleTest('module-gradle-7.6', gradleVersion: '7.6.3').call,
|
ModuleTest('module-gradle-7.6', gradleVersion: '7.6.3').call,
|
||||||
|
ModuleTest('module-gradle-7.6', gradleVersion: '7.6-rc-2').call,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
@ -1423,6 +1423,7 @@ class FlutterPlugin implements Plugin<Project> {
|
|||||||
|
|
||||||
// compareTo implementation of version strings in the format of ints and periods
|
// compareTo implementation of version strings in the format of ints and periods
|
||||||
// Requires non null objects.
|
// Requires non null objects.
|
||||||
|
// Will not crash on RC candidate strings but considers all RC candidates the same version.
|
||||||
static int compareVersionStrings(String firstString, String secondString) {
|
static int compareVersionStrings(String firstString, String secondString) {
|
||||||
List firstVersion = firstString.tokenize(".")
|
List firstVersion = firstString.tokenize(".")
|
||||||
List secondVersion = secondString.tokenize(".")
|
List secondVersion = secondString.tokenize(".")
|
||||||
@ -1430,12 +1431,32 @@ class FlutterPlugin implements Plugin<Project> {
|
|||||||
def commonIndices = Math.min(firstVersion.size(), secondVersion.size())
|
def commonIndices = Math.min(firstVersion.size(), secondVersion.size())
|
||||||
|
|
||||||
for (int i = 0; i < commonIndices; i++) {
|
for (int i = 0; i < commonIndices; i++) {
|
||||||
def firstAtIndex = firstVersion[i].toInteger()
|
String firstAtIndex = firstVersion[i]
|
||||||
def secondAtIndex = secondVersion[i].toInteger()
|
String secondAtIndex = secondVersion[i]
|
||||||
|
int firstInt = 0;
|
||||||
|
int secondInt = 0
|
||||||
|
try {
|
||||||
|
if (firstAtIndex.contains("-")) {
|
||||||
|
// Strip any chars after "-". For example "8.6-rc-2"
|
||||||
|
firstAtIndex = firstAtIndex.substring(0, firstAtIndex.indexOf('-'))
|
||||||
|
}
|
||||||
|
firstInt = firstAtIndex.toInteger()
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
println(nfe)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (firstAtIndex.contains("-")) {
|
||||||
|
// Strip any chars after "-". For example "8.6-rc-2"
|
||||||
|
secondAtIndex = secondAtIndex.substring(0, secondAtIndex.indexOf('-'))
|
||||||
|
}
|
||||||
|
secondInt = secondAtIndex.toInteger()
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
println(nfe)
|
||||||
|
}
|
||||||
|
|
||||||
if (firstAtIndex != secondAtIndex) {
|
if (firstInt != secondInt) {
|
||||||
// <=> in groovy delegates to compareTo
|
// <=> in groovy delegates to compareTo
|
||||||
return firstAtIndex <=> secondAtIndex
|
return firstInt <=> secondInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user