update mostRecentSemanticVersion
to handle strings like "8.6-rc-2" (#158020)
updated mostRecentSemanticVersion func to handle strings like "8.6-rc-2"
.
see :
41006014ab/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy (L815-L824)
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
---------
Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com>
This commit is contained in:
parent
ad74f9f0cd
commit
09fdf159b9
@ -795,32 +795,44 @@ class FlutterPlugin implements Plugin<Project> {
|
|||||||
* Compares semantic versions ignoring labels.
|
* Compares semantic versions ignoring labels.
|
||||||
*
|
*
|
||||||
* If the versions are equal (ignoring labels), returns one of the two strings arbitrarily.
|
* If the versions are equal (ignoring labels), returns one of the two strings arbitrarily.
|
||||||
*
|
|
||||||
* If minor or patch are omitted (non-conformant to semantic versioning), they are considered zero.
|
* If minor or patch are omitted (non-conformant to semantic versioning), they are considered zero.
|
||||||
* If the provided versions in both are equal, the longest version string is returned.
|
* If the provided versions in both are equal, the longest version string is returned.
|
||||||
* For example, "2.8.0" vs "2.8" will always consider "2.8.0" to be the most recent version.
|
* For example, "2.8.0" vs "2.8" will always consider "2.8.0" to be the most recent version.
|
||||||
* TODO: Remove this or compareVersionStrings. This does not handle strings like "8.6-rc-2".
|
* For another example, "8.7-rc-2" vs "8.7.2" will always consider "8.7.2" to be the most recent version.
|
||||||
*/
|
*/
|
||||||
static String mostRecentSemanticVersion(String version1, String version2) {
|
static String mostRecentSemanticVersion(String version1, String version2) {
|
||||||
List version1Tokenized = version1.tokenize(".")
|
def v1Parts = version1.tokenize('.-')
|
||||||
List version2Tokenized = version2.tokenize(".")
|
def v2Parts = version2.tokenize('.-')
|
||||||
int version1numTokens = version1Tokenized.size()
|
|
||||||
int version2numTokens = version2Tokenized.size()
|
for (int i = 0; i < Math.max(v1Parts.size(), v2Parts.size()); i++) {
|
||||||
int minNumTokens = Math.min(version1numTokens, version2numTokens)
|
def v1Part = i < v1Parts.size() ? v1Parts[i] : '0'
|
||||||
for (int i = 0; i < minNumTokens; i++) {
|
def v2Part = i < v2Parts.size() ? v2Parts[i] : '0'
|
||||||
int num1 = version1Tokenized[i].toInteger()
|
|
||||||
int num2 = version2Tokenized[i].toInteger()
|
def v1Num = v1Part.isNumber() ? v1Part.toInteger() : 0
|
||||||
if (num1 > num2) {
|
def v2Num = v2Part.isNumber() ? v2Part.toInteger() : 0
|
||||||
|
|
||||||
|
if (v1Num != v2Num) {
|
||||||
|
return v1Num > v2Num ? version1 : version2
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v1Part.isNumber() && !v2Part.isNumber()) {
|
||||||
return version1
|
return version1
|
||||||
}
|
} else if (!v1Part.isNumber() && v2Part.isNumber()) {
|
||||||
if (num2 > num1) {
|
|
||||||
return version2
|
return version2
|
||||||
|
} else if (v1Part != v2Part) {
|
||||||
|
return comparePreReleaseIdentifiers(v1Part, v2Part) ? version1 : version2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (version1numTokens > version2numTokens) {
|
|
||||||
return version1
|
// If versions are equal, return the longest version string
|
||||||
}
|
return version1.length() >= version2.length() ? version1 : version2
|
||||||
return version2
|
}
|
||||||
|
|
||||||
|
static boolean comparePreReleaseIdentifiers(String v1Part, String v2Part) {
|
||||||
|
def v1PreRelease = v1Part.replaceAll("\\D", "")
|
||||||
|
def v2PreRelease = v2Part.replaceAll("\\D", "")
|
||||||
|
|
||||||
|
return v1PreRelease < v2PreRelease
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceNdkDownload(Project gradleProject, String flutterSdkRootPath) {
|
private void forceNdkDownload(Project gradleProject, String flutterSdkRootPath) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user