Unverified Commit 7a791b5d authored by Reid Baker's avatar Reid Baker Committed by GitHub

Update getGradleVersion to ignore commented out lines (#124260)

https://github.com/flutter/flutter/issues/123917
Missed feedback from https://github.com/flutter/flutter/pull/123916 

- Handle commented out lines in gradle-wrapper.properties

This is 1 of 2 prs to handle missed feedback. Formatting will be done in
the second whereas this one captures a weakness missed in the last pr.

## 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].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.
parent f28eb28f
......@@ -189,8 +189,9 @@ Future<String?> getGradleVersion(
// Expected content format (with lines above and below).
// Version can have 2 or 3 numbers.
// 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip'
// '^\s*' protects against commented out lines.
final RegExp distributionUrlRegex =
RegExp(r'distributionUrl\s?=\s?.*\.zip');
RegExp(r'^\s*distributionUrl\s?=\s?.*\.zip', multiLine: true);
final RegExpMatch? distributionUrl =
distributionUrlRegex.firstMatch(wrapperFileContent);
......
......@@ -226,6 +226,33 @@ distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\\://services.gradle.org/distributions/gradle-$expectedVersion-all.zip
''');
expect(
await getGradleVersion(
androidDirectory, BufferLogger.test(), FakeProcessManager.empty()),
expectedVersion,
);
});
testWithoutContext('ignores gradle comments', () async {
const String expectedVersion = '7.4.2';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
final Directory wrapperDirectory = androidDirectory
.childDirectory('gradle')
.childDirectory('wrapper')
..createSync(recursive: true);
wrapperDirectory
.childFile('gradle-wrapper.properties')
.writeAsStringSync('''
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# distributionUrl=https\\://services.gradle.org/distributions/gradle-8.0.2-all.zip
distributionUrl=https\\://services.gradle.org/distributions/gradle-$expectedVersion-all.zip
# distributionUrl=https\\://services.gradle.org/distributions/gradle-8.0.2-all.zip
''');
expect(
......
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