Skip to content

Commit 09fdf15

Browse files
AbdeMohlbigmackall
andauthored
update mostRecentSemanticVersion to handle strings like "8.6-rc-2" (#158020)
updated mostRecentSemanticVersion func to handle strings like "8.6-rc-2" . see : https://github.com/flutter/flutter/blob/41006014abc1352e29cc5f0eacdd66dff173ba74/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 <[email protected]>
1 parent ad74f9f commit 09fdf15

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

packages/flutter_tools/gradle/src/main/groovy/flutter.groovy

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -795,32 +795,44 @@ class FlutterPlugin implements Plugin<Project> {
795795
* Compares semantic versions ignoring labels.
796796
*
797797
* If the versions are equal (ignoring labels), returns one of the two strings arbitrarily.
798-
*
799798
* If minor or patch are omitted (non-conformant to semantic versioning), they are considered zero.
800799
* If the provided versions in both are equal, the longest version string is returned.
801800
* For example, "2.8.0" vs "2.8" will always consider "2.8.0" to be the most recent version.
802-
* TODO: Remove this or compareVersionStrings. This does not handle strings like "8.6-rc-2".
801+
* For another example, "8.7-rc-2" vs "8.7.2" will always consider "8.7.2" to be the most recent version.
803802
*/
804-
static String mostRecentSemanticVersion(String version1, String version2) {
805-
List version1Tokenized = version1.tokenize(".")
806-
List version2Tokenized = version2.tokenize(".")
807-
int version1numTokens = version1Tokenized.size()
808-
int version2numTokens = version2Tokenized.size()
809-
int minNumTokens = Math.min(version1numTokens, version2numTokens)
810-
for (int i = 0; i < minNumTokens; i++) {
811-
int num1 = version1Tokenized[i].toInteger()
812-
int num2 = version2Tokenized[i].toInteger()
813-
if (num1 > num2) {
814-
return version1
803+
static String mostRecentSemanticVersion(String version1, String version2) {
804+
def v1Parts = version1.tokenize('.-')
805+
def v2Parts = version2.tokenize('.-')
806+
807+
for (int i = 0; i < Math.max(v1Parts.size(), v2Parts.size()); i++) {
808+
def v1Part = i < v1Parts.size() ? v1Parts[i] : '0'
809+
def v2Part = i < v2Parts.size() ? v2Parts[i] : '0'
810+
811+
def v1Num = v1Part.isNumber() ? v1Part.toInteger() : 0
812+
def v2Num = v2Part.isNumber() ? v2Part.toInteger() : 0
813+
814+
if (v1Num != v2Num) {
815+
return v1Num > v2Num ? version1 : version2
815816
}
816-
if (num2 > num1) {
817+
818+
if (v1Part.isNumber() && !v2Part.isNumber()) {
819+
return version1
820+
} else if (!v1Part.isNumber() && v2Part.isNumber()) {
817821
return version2
822+
} else if (v1Part != v2Part) {
823+
return comparePreReleaseIdentifiers(v1Part, v2Part) ? version1 : version2
818824
}
819825
}
820-
if (version1numTokens > version2numTokens) {
821-
return version1
822-
}
823-
return version2
826+
827+
// If versions are equal, return the longest version string
828+
return version1.length() >= version2.length() ? version1 : version2
829+
}
830+
831+
static boolean comparePreReleaseIdentifiers(String v1Part, String v2Part) {
832+
def v1PreRelease = v1Part.replaceAll("\\D", "")
833+
def v2PreRelease = v2Part.replaceAll("\\D", "")
834+
835+
return v1PreRelease < v2PreRelease
824836
}
825837

826838
private void forceNdkDownload(Project gradleProject, String flutterSdkRootPath) {

0 commit comments

Comments
 (0)