Unverified Commit 2b890af9 authored by Reid Baker's avatar Reid Baker Committed by GitHub

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
parent 2442603c
......@@ -450,5 +450,6 @@ Future<void> main() async {
await task(combine(<TaskFunction>[
// ignore: avoid_redundant_argument_values
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
// 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) {
List firstVersion = firstString.tokenize(".")
List secondVersion = secondString.tokenize(".")
......@@ -1430,12 +1431,32 @@ class FlutterPlugin implements Plugin<Project> {
def commonIndices = Math.min(firstVersion.size(), secondVersion.size())
for (int i = 0; i < commonIndices; i++) {
def firstAtIndex = firstVersion[i].toInteger()
def secondAtIndex = secondVersion[i].toInteger()
String firstAtIndex = firstVersion[i]
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
return firstAtIndex <=> secondAtIndex
return firstInt <=> secondInt
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment