diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 738d4559b37..71c0311e161 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -1293,11 +1293,13 @@ class GradleWrapper extends CachedArtifact { OperatingSystemUtils operatingSystemUtils, ) async { 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. - fileSystem.file(fileSystem.path.join(location.path, 'gradle', 'wrapper', 'gradle-wrapper.properties')).deleteSync(); // 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 diff --git a/packages/flutter_tools/test/general.shard/cache_test.dart b/packages/flutter_tools/test/general.shard/cache_test.dart index c8b7b3109e7..369c1a704ec 100644 --- a/packages/flutter_tools/test/general.shard/cache_test.dart +++ b/packages/flutter_tools/test/general.shard/cache_test.dart @@ -136,6 +136,28 @@ void main() { 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', () { final FileSystem fileSystem = MemoryFileSystem.test(); final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any()); @@ -941,3 +963,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk { reinitialized = true; } } + +class FakeArtifactUpdater extends Fake implements ArtifactUpdater { + @override + Future downloadZippedTarball(String message, Uri url, Directory location) async { + return; + } +}