Unverified Commit 975fb0f0 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tool] fix deletion of gradle wrapper artifacts in cache (#78911)

parent 64d9650e
...@@ -1293,11 +1293,13 @@ class GradleWrapper extends CachedArtifact { ...@@ -1293,11 +1293,13 @@ class GradleWrapper extends CachedArtifact {
OperatingSystemUtils operatingSystemUtils, OperatingSystemUtils operatingSystemUtils,
) async { ) async {
final Uri archiveUri = _toStorageUri(version); final Uri archiveUri = _toStorageUri(version);
await artifactUpdater.downloadZippedTarball('Downloading Gradle Wrapper...', archiveUri, location); await artifactUpdater.downloadZippedTarball('Downloading Gradle Wrapper...', archiveUri, location);
// Delete property file, allowing templates to provide it. // Delete property file, allowing templates to provide it.
fileSystem.file(fileSystem.path.join(location.path, 'gradle', 'wrapper', 'gradle-wrapper.properties')).deleteSync();
// Remove NOTICE file. Should not be part of the template. // Remove NOTICE file. Should not be part of the template.
fileSystem.file(fileSystem.path.join(location.path, 'NOTICE')).deleteSync(); final File propertiesFile = fileSystem.file(fileSystem.path.join(location.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
final File noticeFile = fileSystem.file(fileSystem.path.join(location.path, 'NOTICE'));
ErrorHandlingFileSystem.deleteIfExists(propertiesFile);
ErrorHandlingFileSystem.deleteIfExists(noticeFile);
} }
@override @override
......
...@@ -136,6 +136,28 @@ void main() { ...@@ -136,6 +136,28 @@ void main() {
expect(gradleWrapper.isUpToDateInner(fileSystem), false); expect(gradleWrapper.isUpToDateInner(fileSystem), false);
}); });
testWithoutContext('Gradle wrapper will delete .properties/NOTICES if they exist', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());
final OperatingSystemUtils operatingSystemUtils = OperatingSystemUtils(
processManager: FakeProcessManager.any(),
platform: FakePlatform(),
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
final GradleWrapper gradleWrapper = GradleWrapper(cache);
final Directory directory = cache.getCacheDir(fileSystem.path.join('artifacts', 'gradle_wrapper'));
final File propertiesFile = fileSystem.file(fileSystem.path.join(directory.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'))
..createSync(recursive: true);
final File noticeFile = fileSystem.file(fileSystem.path.join(directory.path, 'NOTICE'))
..createSync(recursive: true);
await gradleWrapper.updateInner(FakeArtifactUpdater(), fileSystem, operatingSystemUtils);
expect(propertiesFile, isNot(exists));
expect(noticeFile, isNot(exists));
});
testWithoutContext('Gradle wrapper should be up to date, only if all cached artifact are available', () { testWithoutContext('Gradle wrapper should be up to date, only if all cached artifact are available', () {
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any()); final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());
...@@ -941,3 +963,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk { ...@@ -941,3 +963,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {
reinitialized = true; reinitialized = true;
} }
} }
class FakeArtifactUpdater extends Fake implements ArtifactUpdater {
@override
Future<void> downloadZippedTarball(String message, Uri url, Directory location) async {
return;
}
}
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