Skip to content

Commit 1c4923c

Browse files
reidbakerexaby73
authored andcommitted
Update getGradleVersion to ignore commented out lines (flutter#124260)
flutter#123917 Missed feedback from flutter#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.
1 parent 0aa178d commit 1c4923c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/flutter_tools/lib/src/android/gradle_utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ Future<String?> getGradleVersion(
189189
// Expected content format (with lines above and below).
190190
// Version can have 2 or 3 numbers.
191191
// 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip'
192+
// '^\s*' protects against commented out lines.
192193
final RegExp distributionUrlRegex =
193-
RegExp(r'distributionUrl\s?=\s?.*\.zip');
194+
RegExp(r'^\s*distributionUrl\s?=\s?.*\.zip', multiLine: true);
194195

195196
final RegExpMatch? distributionUrl =
196197
distributionUrlRegex.firstMatch(wrapperFileContent);

packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,33 @@ distributionPath=wrapper/dists
226226
zipStoreBase=GRADLE_USER_HOME
227227
zipStorePath=wrapper/dists
228228
distributionUrl=https\\://services.gradle.org/distributions/gradle-$expectedVersion-all.zip
229+
''');
230+
231+
expect(
232+
await getGradleVersion(
233+
androidDirectory, BufferLogger.test(), FakeProcessManager.empty()),
234+
expectedVersion,
235+
);
236+
});
237+
238+
testWithoutContext('ignores gradle comments', () async {
239+
const String expectedVersion = '7.4.2';
240+
final Directory androidDirectory = fileSystem.directory('/android')
241+
..createSync();
242+
final Directory wrapperDirectory = androidDirectory
243+
.childDirectory('gradle')
244+
.childDirectory('wrapper')
245+
..createSync(recursive: true);
246+
wrapperDirectory
247+
.childFile('gradle-wrapper.properties')
248+
.writeAsStringSync('''
249+
distributionBase=GRADLE_USER_HOME
250+
distributionPath=wrapper/dists
251+
zipStoreBase=GRADLE_USER_HOME
252+
zipStorePath=wrapper/dists
253+
# distributionUrl=https\\://services.gradle.org/distributions/gradle-8.0.2-all.zip
254+
distributionUrl=https\\://services.gradle.org/distributions/gradle-$expectedVersion-all.zip
255+
# distributionUrl=https\\://services.gradle.org/distributions/gradle-8.0.2-all.zip
229256
''');
230257

231258
expect(

0 commit comments

Comments
 (0)