From b225cb8d53aec5abb16d282680efad3c83e55858 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 16 Jan 2020 16:19:54 -0800 Subject: [PATCH] Revert "[flutter_tools] Removes the need of a no-op plugin implementations (#48614)" (#49005) This reverts commit 5eb394e08492fadd66581c4c0af45ec657d4495a. --- .../bin/tasks/plugin_dependencies_test.dart | 49 ++--- packages/flutter_tools/lib/src/plugins.dart | 183 ++++-------------- packages/flutter_tools/lib/src/project.dart | 45 +---- packages/flutter_tools/lib/src/version.dart | 2 - .../test/general.shard/plugins_test.dart | 169 +++------------- 5 files changed, 92 insertions(+), 356 deletions(-) diff --git a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart index 6e32c2d65e..f3714f2669 100644 --- a/dev/devicelab/bin/tasks/plugin_dependencies_test.dart +++ b/dev/devicelab/bin/tasks/plugin_dependencies_test.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:flutter_devicelab/framework/framework.dart'; @@ -75,6 +74,10 @@ Future main() async { ); }); + // https://github.com/flutter/flutter/issues/46898 + // https://github.com/flutter/flutter/issues/39657 + File(path.join(pluginCDirectory.path, 'android', 'build.gradle')).deleteSync(); + final File pluginCpubspec = File(path.join(pluginCDirectory.path, 'pubspec.yaml')); await pluginCpubspec.writeAsString(''' name: plugin_c @@ -174,32 +177,30 @@ public class DummyPluginAClass { } final String flutterPluginsDependenciesFileContent = flutterPluginsDependenciesFile.readAsStringSync(); - - final Map jsonContent = json.decode(flutterPluginsDependenciesFileContent) as Map; - - // Verify the dependencyGraph object is valid. The rest of the contents of this file are not relevant to the - // dependency graph and are tested by unit tests. - final List dependencyGraph = jsonContent['dependencyGraph'] as List; const String kExpectedPluginsDependenciesContent = - '[' - '{' - '\"name\":\"plugin_a\",' - '\"dependencies\":[\"plugin_b\",\"plugin_c\"]' - '},' - '{' - '\"name\":\"plugin_b\",' - '\"dependencies\":[]' - '},' - '{' - '\"name\":\"plugin_c\",' - '\"dependencies\":[]' - '}' - ']'; - final String graphString = json.encode(dependencyGraph); - if (graphString != kExpectedPluginsDependenciesContent) { + '{' + '\"_info\":\"// This is a generated file; do not edit or check into version control.\",' + '\"dependencyGraph\":[' + '{' + '\"name\":\"plugin_a\",' + '\"dependencies\":[\"plugin_b\",\"plugin_c\"]' + '},' + '{' + '\"name\":\"plugin_b\",' + '\"dependencies\":[]' + '},' + '{' + '\"name\":\"plugin_c\",' + '\"dependencies\":[]' + '}' + ']' + '}'; + + if (flutterPluginsDependenciesFileContent != kExpectedPluginsDependenciesContent) { return TaskResult.failure( 'Unexpected file content in ${flutterPluginsDependenciesFile.path}: ' - 'Found "$graphString" instead of "$kExpectedPluginsDependenciesContent"' + 'Found "$flutterPluginsDependenciesFileContent" instead of ' + '"$kExpectedPluginsDependenciesContent"' ); } diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index 628058f347..efee39fe55 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -11,7 +11,6 @@ import 'package:yaml/yaml.dart'; import 'android/gradle.dart'; import 'base/common.dart'; import 'base/file_system.dart'; -import 'base/time.dart'; import 'convert.dart'; import 'dart/package_map.dart'; import 'features.dart'; @@ -19,7 +18,6 @@ import 'globals.dart' as globals; import 'macos/cocoapods.dart'; import 'platform_plugins.dart'; import 'project.dart'; -import 'version.dart'; void _renderTemplateToFile(String template, dynamic context, String filePath) { final String renderedTemplate = @@ -265,7 +263,7 @@ class Plugin { final Map platforms; } -Plugin _pluginFromPackage(String name, Uri packageRoot) { +Plugin _pluginFromPubspec(String name, Uri packageRoot) { final String pubspecPath = globals.fs.path.fromUri(packageRoot.resolve('pubspec.yaml')); if (!globals.fs.isFileSync(pubspecPath)) { return null; @@ -304,7 +302,7 @@ List findPlugins(FlutterProject project) { } packages.forEach((String name, Uri uri) { final Uri packageRoot = uri.resolve('..'); - final Plugin plugin = _pluginFromPackage(name, packageRoot); + final Plugin plugin = _pluginFromPubspec(name, packageRoot); if (plugin != null) { plugins.add(plugin); } @@ -312,159 +310,55 @@ List findPlugins(FlutterProject project) { return plugins; } - /// Filters [plugins] to those supported by [platformKey]. - List> _filterPluginsByPlatform(Listplugins, String platformKey) { - final Iterable platformPlugins = plugins.where((Plugin p) { - return p.platforms.containsKey(platformKey); - }); - - final Set pluginNames = platformPlugins.map((Plugin plugin) => plugin.name).toSet(); - final List> list = >[]; - for (final Plugin plugin in platformPlugins) { - list.add({ - 'name': plugin.name, - 'path': fsUtils.escapePath(plugin.path), - 'dependencies': [...plugin.dependencies.where(pluginNames.contains)], - }); - } - return list; - } - -/// Writes the .flutter-plugins-dependencies file based on the list of plugins. -/// If there aren't any plugins, then the files aren't written to disk. The resulting -/// file looks something like this (order of keys is not guaranteed): -/// { -/// "info": "This is a generated file; do not edit or check into version control.", -/// "plugins": { -/// "ios": [ -/// { -/// "name": "test", -/// "path": "test_path", -/// "dependencies": [ -/// "plugin-a", -/// "plugin-b" -/// ] -/// } -/// ], -/// "android": [], -/// "macos": [], -/// "linux": [], -/// "windows": [], -/// "web": [] -/// }, -/// "dependencyGraph": [ -/// { -/// "name": "plugin-a", -/// "dependencies": [ -/// "plugin-b", -/// "plugin-c" -/// ] -/// }, -/// { -/// "name": "plugin-b", -/// "dependencies": [ -/// "plugin-c" -/// ] -/// }, -/// { -/// "name": "plugin-c", -/// "dependencies": [] -/// } -/// ], -/// "date_created": "1970-01-01 00:00:00.000", -/// "version": "0.0.0-unknown" -/// } +/// Writes the .flutter-plugins and .flutter-plugins-dependencies files based on the list of plugins. +/// If there aren't any plugins, then the files aren't written to disk. /// -/// -/// Finally, returns [true] if .flutter-plugins-dependencies has changed, +/// Finally, returns [true] if .flutter-plugins or .flutter-plugins-dependencies have changed, /// otherwise returns [false]. bool _writeFlutterPluginsList(FlutterProject project, List plugins) { - final File pluginsFile = project.flutterPluginsDependenciesFile; - if (plugins.isEmpty) { - if (pluginsFile.existsSync()) { - pluginsFile.deleteSync(); - return true; - } - return false; - } - - final String iosKey = project.ios.pluginConfigKey; - final String androidKey = project.android.pluginConfigKey; - final String macosKey = project.macos.pluginConfigKey; - final String linuxKey = project.linux.pluginConfigKey; - final String windowsKey = project.windows.pluginConfigKey; - final String webKey = project.web.pluginConfigKey; - - final Map pluginsMap = {}; - pluginsMap[iosKey] = _filterPluginsByPlatform(plugins, iosKey); - pluginsMap[androidKey] = _filterPluginsByPlatform(plugins, androidKey); - pluginsMap[macosKey] = _filterPluginsByPlatform(plugins, macosKey); - pluginsMap[linuxKey] = _filterPluginsByPlatform(plugins, linuxKey); - pluginsMap[windowsKey] = _filterPluginsByPlatform(plugins, windowsKey); - pluginsMap[webKey] = _filterPluginsByPlatform(plugins, webKey); - - final Map result = {}; - - result['info'] = 'This is a generated file; do not edit or check into version control.'; - result['plugins'] = pluginsMap; - /// The dependencyGraph object is kept for backwards compatibility, but - /// should be removed once migration is complete. - /// https://github.com/flutter/flutter/issues/48918 - result['dependencyGraph'] = _createPluginLegacyDependencyGraph(plugins); - result['date_created'] = systemClock.now().toString(); - result['version'] = flutterVersion.frameworkVersion; - - final String oldPluginFileContent = _readFileContent(pluginsFile); - final String pluginFileContent = json.encode(result); - pluginsFile.writeAsStringSync(pluginFileContent, flush: true); - - return oldPluginFileContent != pluginFileContent; -} - -List _createPluginLegacyDependencyGraph(List plugins) { final List directAppDependencies = []; + const String info = 'This is a generated file; do not edit or check into version control.'; + final StringBuffer flutterPluginsBuffer = StringBuffer('# $info\n'); - final Set pluginNames = plugins.map((Plugin plugin) => plugin.name).toSet(); + final Set pluginNames = {}; for (final Plugin plugin in plugins) { + pluginNames.add(plugin.name); + } + for (final Plugin plugin in plugins) { + flutterPluginsBuffer.write('${plugin.name}=${fsUtils.escapePath(plugin.path)}\n'); directAppDependencies.add({ 'name': plugin.name, // Extract the plugin dependencies which happen to be plugins. 'dependencies': [...plugin.dependencies.where(pluginNames.contains)], }); } - return directAppDependencies; -} - -// The .flutter-plugins file will be DEPRECATED in favor of .flutter-plugins-dependencies. -// TODO(franciscojma): Remove this method once deprecated. -// https://github.com/flutter/flutter/issues/48918 -// -/// Writes the .flutter-plugins files based on the list of plugins. -/// If there aren't any plugins, then the files aren't written to disk. -/// -/// Finally, returns [true] if .flutter-plugins has changed, otherwise returns [false]. -bool _writeFlutterPluginsListLegacy(FlutterProject project, List plugins) { - final File pluginsFile = project.flutterPluginsFile; - if (plugins.isEmpty) { - if (pluginsFile.existsSync()) { - pluginsFile.deleteSync(); - return true; - } - return false; - } - - const String info = 'This is a generated file; do not edit or check into version control.'; - final StringBuffer flutterPluginsBuffer = StringBuffer('# $info\n'); - - for (final Plugin plugin in plugins) { - flutterPluginsBuffer.write('${plugin.name}=${fsUtils.escapePath(plugin.path)}\n'); - } final String oldPluginFileContent = _readFileContent(pluginsFile); final String pluginFileContent = flutterPluginsBuffer.toString(); - pluginsFile.writeAsStringSync(pluginFileContent, flush: true); + if (pluginNames.isNotEmpty) { + pluginsFile.writeAsStringSync(pluginFileContent, flush: true); + } else { + if (pluginsFile.existsSync()) { + pluginsFile.deleteSync(); + } + } - return oldPluginFileContent != _readFileContent(pluginsFile); + final File dependenciesFile = project.flutterPluginsDependenciesFile; + final String oldDependenciesFileContent = _readFileContent(dependenciesFile); + final String dependenciesFileContent = json.encode({ + '_info': '// $info', + 'dependencyGraph': directAppDependencies, + }); + if (pluginNames.isNotEmpty) { + dependenciesFile.writeAsStringSync(dependenciesFileContent, flush: true); + } else { + if (dependenciesFile.existsSync()) { + dependenciesFile.deleteSync(); + } + } + + return oldPluginFileContent != _readFileContent(pluginsFile) + || oldDependenciesFileContent != _readFileContent(dependenciesFile); } /// Returns the contents of [File] or [null] if that file does not exist. @@ -888,13 +782,8 @@ Future _writeWebPluginRegistrant(FlutterProject project, List plug /// Assumes `pub get` has been executed since last change to `pubspec.yaml`. void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) { final List plugins = findPlugins(project); - - // TODO(franciscojma): Remove once migration is complete. - // Write the legacy plugin files to avoid breaking existing apps. - final bool legacyChanged = _writeFlutterPluginsListLegacy(project, plugins); - final bool changed = _writeFlutterPluginsList(project, plugins); - if (changed || legacyChanged) { + if (changed) { if (!checkProjects || project.ios.existsSync()) { cocoaPods.invalidatePodInstallOutput(project.ios); } diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index f397a332b1..fd8a48054f 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -20,7 +20,6 @@ import 'flutter_manifest.dart'; import 'globals.dart' as globals; import 'ios/plist_parser.dart'; import 'ios/xcodeproj.dart' as xcode; -import 'platform_plugins.dart'; import 'plugins.dart'; import 'template.dart'; @@ -252,16 +251,6 @@ class FlutterProject { } } -/// Base class for projects per platform. -abstract class FlutterProjectPlatform { - - /// Plugin's platform config key, e.g., "macos", "ios". - String get pluginConfigKey; - - /// Whether the platform exists in the project. - bool existsSync(); -} - /// Represents an Xcode-based sub-project. /// /// This defines interfaces common to iOS and macOS projects. @@ -311,15 +300,12 @@ abstract class XcodeBasedProject { /// /// Instances will reflect the contents of the `ios/` sub-folder of /// Flutter applications and the `.ios/` sub-folder of Flutter module projects. -class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { +class IosProject implements XcodeBasedProject { IosProject.fromFlutter(this.parent); @override final FlutterProject parent; - @override - String get pluginConfigKey => IOSPlugin.kConfigKey; - static final RegExp _productBundleIdPattern = RegExp(r'''^\s*PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(["']?)(.*?)\1;\s*$'''); static const String _productBundleIdVariable = r'$(PRODUCT_BUNDLE_IDENTIFIER)'; static const String _hostAppBundleName = 'Runner'; @@ -588,15 +574,12 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { /// /// Instances will reflect the contents of the `android/` sub-folder of /// Flutter applications and the `.android/` sub-folder of Flutter module projects. -class AndroidProject extends FlutterProjectPlatform { +class AndroidProject { AndroidProject._(this.parent); /// The parent of this project. final FlutterProject parent; - @override - String get pluginConfigKey => AndroidPlugin.kConfigKey; - static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s+[\'\"](.*)[\'\"]\\s*\$'); static final RegExp _kotlinPluginPattern = RegExp('^\\s*apply plugin\:\\s+[\'\"]kotlin-android[\'\"]\\s*\$'); static final RegExp _groupPattern = RegExp('^\\s*group\\s+[\'\"](.*)[\'\"]\\s*\$'); @@ -644,7 +627,6 @@ class AndroidProject extends FlutterProjectPlatform { } /// Whether the current flutter project has an Android sub-project. - @override bool existsSync() { return parent.isModule || _editableHostAppDirectory.existsSync(); } @@ -778,16 +760,12 @@ enum AndroidEmbeddingVersion { } /// Represents the web sub-project of a Flutter project. -class WebProject extends FlutterProjectPlatform { +class WebProject { WebProject._(this.parent); final FlutterProject parent; - @override - String get pluginConfigKey => WebPlugin.kConfigKey; - /// Whether this flutter project has a web sub-project. - @override bool existsSync() { return parent.directory.childDirectory('web').existsSync() && indexFile.existsSync(); @@ -832,15 +810,12 @@ Match _firstMatchInFile(File file, RegExp regExp) { } /// The macOS sub project. -class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject { +class MacOSProject implements XcodeBasedProject { MacOSProject._(this.parent); @override final FlutterProject parent; - @override - String get pluginConfigKey => MacOSPlugin.kConfigKey; - static const String _hostAppBundleName = 'Runner'; @override @@ -920,15 +895,11 @@ class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject { } /// The Windows sub project -class WindowsProject extends FlutterProjectPlatform { +class WindowsProject { WindowsProject._(this.project); final FlutterProject project; - @override - String get pluginConfigKey => WindowsPlugin.kConfigKey; - - @override bool existsSync() => _editableDirectory.existsSync(); Directory get _editableDirectory => project.directory.childDirectory('windows'); @@ -962,14 +933,11 @@ class WindowsProject extends FlutterProjectPlatform { } /// The Linux sub project. -class LinuxProject extends FlutterProjectPlatform { +class LinuxProject { LinuxProject._(this.project); final FlutterProject project; - @override - String get pluginConfigKey => LinuxPlugin.kConfigKey; - Directory get _editableDirectory => project.directory.childDirectory('linux'); /// The directory in the project that is managed by Flutter. As much as @@ -982,7 +950,6 @@ class LinuxProject extends FlutterProjectPlatform { /// checked in should live here. Directory get ephemeralDirectory => managedDirectory.childDirectory('ephemeral'); - @override bool existsSync() => _editableDirectory.existsSync(); /// The Linux project makefile. diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 470f4eda63..d6dc8c859d 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -16,8 +16,6 @@ import 'cache.dart'; import 'convert.dart'; import 'globals.dart' as globals; -FlutterVersion get flutterVersion => context.get(); - class FlutterVersion { FlutterVersion([this._clock = const SystemClock()]) { _frameworkRevision = _runGit(gitLog(['-n', '1', '--pretty=format:%H']).join(' ')); diff --git a/packages/flutter_tools/test/general.shard/plugins_test.dart b/packages/flutter_tools/test/general.shard/plugins_test.dart index 1e58e34b96..635d0e92fd 100644 --- a/packages/flutter_tools/test/general.shard/plugins_test.dart +++ b/packages/flutter_tools/test/general.shard/plugins_test.dart @@ -2,17 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:convert'; - import 'package:file/file.dart'; import 'package:file/memory.dart'; -import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/dart/package_map.dart'; import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/ios/xcodeproj.dart'; import 'package:flutter_tools/src/plugins.dart'; import 'package:flutter_tools/src/project.dart'; -import 'package:flutter_tools/src/version.dart'; import 'package:meta/meta.dart'; import 'package:mockito/mockito.dart'; @@ -27,22 +23,15 @@ void main() { MockMacOSProject macosProject; MockAndroidProject androidProject; MockWebProject webProject; - MockWindowsProject windowsProject; - MockLinuxProject linuxProject; File packagesFile; Directory dummyPackageDirectory; - SystemClock mockClock; - FlutterVersion mockVersion; setUp(() async { fs = MemoryFileSystem(); - mockClock = MockClock(); - mockVersion = MockFlutterVersion(); // Add basic properties to the Flutter project and subprojects flutterProject = MockFlutterProject(); when(flutterProject.directory).thenReturn(fs.directory('/')); - // TODO(franciscojma): Remove logic for .flutter-plugins it's deprecated. when(flutterProject.flutterPluginsFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins')); when(flutterProject.flutterPluginsDependenciesFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins-dependencies')); iosProject = MockIosProject(); @@ -50,34 +39,18 @@ void main() { when(iosProject.pluginRegistrantHost).thenReturn(flutterProject.directory.childDirectory('Runner')); when(iosProject.podfile).thenReturn(flutterProject.directory.childDirectory('ios').childFile('Podfile')); when(iosProject.podManifestLock).thenReturn(flutterProject.directory.childDirectory('ios').childFile('Podfile.lock')); - when(iosProject.pluginConfigKey).thenReturn('ios'); - when(iosProject.existsSync()).thenReturn(false); macosProject = MockMacOSProject(); when(flutterProject.macos).thenReturn(macosProject); when(macosProject.podfile).thenReturn(flutterProject.directory.childDirectory('macos').childFile('Podfile')); when(macosProject.podManifestLock).thenReturn(flutterProject.directory.childDirectory('macos').childFile('Podfile.lock')); - when(macosProject.pluginConfigKey).thenReturn('macos'); - when(macosProject.existsSync()).thenReturn(false); androidProject = MockAndroidProject(); when(flutterProject.android).thenReturn(androidProject); when(androidProject.pluginRegistrantHost).thenReturn(flutterProject.directory.childDirectory('android').childDirectory('app')); when(androidProject.hostAppGradleRoot).thenReturn(flutterProject.directory.childDirectory('android')); - when(androidProject.pluginConfigKey).thenReturn('android'); - when(androidProject.existsSync()).thenReturn(false); webProject = MockWebProject(); when(flutterProject.web).thenReturn(webProject); when(webProject.libDirectory).thenReturn(flutterProject.directory.childDirectory('lib')); when(webProject.existsSync()).thenReturn(true); - when(webProject.pluginConfigKey).thenReturn('web'); - when(webProject.existsSync()).thenReturn(false); - windowsProject = MockWindowsProject(); - when(flutterProject.windows).thenReturn(windowsProject); - when(windowsProject.pluginConfigKey).thenReturn('windows'); - when(windowsProject.existsSync()).thenReturn(false); - linuxProject = MockLinuxProject(); - when(flutterProject.linux).thenReturn(linuxProject); - when(linuxProject.pluginConfigKey).thenReturn('linux'); - when(linuxProject.existsSync()).thenReturn(false); // Set up a simple .packages file for all the tests to use, pointing to one package. dummyPackageDirectory = fs.directory('/pubcache/apackage/lib/'); @@ -94,18 +67,6 @@ void main() { platforms: ios: pluginClass: FLESomePlugin - macos: - pluginClass: FLESomePlugin - windows: - pluginClass: FLESomePlugin - linux: - pluginClass: FLESomePlugin - web: - pluginClass: SomePlugin - fileName: lib/SomeFile.dart - android: - pluginClass: SomePlugin - package: AndroidPackage '''); } @@ -278,8 +239,8 @@ dependencies: testUsingContext('Refreshing the plugin list deletes the plugin file when there were plugins but no longer are', () { flutterProject.flutterPluginsFile.createSync(); - flutterProject.flutterPluginsDependenciesFile.createSync(); - + when(iosProject.existsSync()).thenReturn(false); + when(macosProject.existsSync()).thenReturn(false); refreshPluginsList(flutterProject); expect(flutterProject.flutterPluginsFile.existsSync(), false); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), false); @@ -290,8 +251,8 @@ dependencies: testUsingContext('Refreshing the plugin list creates a plugin directory when there are plugins', () { configureDummyPackageAsPlugin(); - when(iosProject.existsSync()).thenReturn(true); - + when(iosProject.existsSync()).thenReturn(false); + when(macosProject.existsSync()).thenReturn(false); refreshPluginsList(flutterProject); expect(flutterProject.flutterPluginsFile.existsSync(), true); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true); @@ -304,20 +265,11 @@ dependencies: createPluginWithDependencies(name: 'plugin-a', dependencies: const ['plugin-b', 'plugin-c', 'random-package']); createPluginWithDependencies(name: 'plugin-b', dependencies: const ['plugin-c']); createPluginWithDependencies(name: 'plugin-c', dependencies: const []); - when(iosProject.existsSync()).thenReturn(true); - - final DateTime dateCreated = DateTime(1970, 1, 1); - when(mockClock.now()).thenAnswer( - (Invocation _) => dateCreated - ); - const String version = '1.0.0'; - when(mockVersion.frameworkVersion).thenAnswer( - (Invocation _) => version - ); + when(iosProject.existsSync()).thenReturn(false); + when(macosProject.existsSync()).thenReturn(false); refreshPluginsList(flutterProject); - // Verify .flutter-plugins-dependencies is configured correctly. expect(flutterProject.flutterPluginsFile.existsSync(), true); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true); expect(flutterProject.flutterPluginsFile.readAsStringSync(), @@ -327,79 +279,28 @@ dependencies: 'plugin-c=/.tmp_rand0/plugin.rand2/\n' '' ); - - final String pluginsString = flutterProject.flutterPluginsDependenciesFile.readAsStringSync(); - final Map jsonContent = json.decode(pluginsString) as Map; - expect(jsonContent['info'], 'This is a generated file; do not edit or check into version control.'); - - final Map plugins = jsonContent['plugins'] as Map; - final List expectedPlugins = [ - { - 'name': 'plugin-a', - 'path': '/.tmp_rand0/plugin.rand0/', - 'dependencies': [ - 'plugin-b', - 'plugin-c' - ] - }, - { - 'name': 'plugin-b', - 'path': '/.tmp_rand0/plugin.rand1/', - 'dependencies': [ - 'plugin-c' - ] - }, - { - 'name': 'plugin-c', - 'path': '/.tmp_rand0/plugin.rand2/', - 'dependencies': [] - }, - ]; - expect(plugins['ios'], expectedPlugins); - expect(plugins['android'], expectedPlugins); - expect(plugins['macos'], []); - expect(plugins['windows'], []); - expect(plugins['linux'], []); - expect(plugins['web'], []); - - final List expectedDependencyGraph = [ - { - 'name': 'plugin-a', - 'dependencies': [ - 'plugin-b', - 'plugin-c' - ] - }, - { - 'name': 'plugin-b', - 'dependencies': [ - 'plugin-c' - ] - }, - { - 'name': 'plugin-c', - 'dependencies': [] - }, - ]; - - expect(jsonContent['dependencyGraph'], expectedDependencyGraph); - expect(jsonContent['date_created'], dateCreated.toString()); - expect(jsonContent['version'], version); - - // Make sure tests are updated if a new object is added/removed. - final List expectedKeys = [ - 'info', - 'plugins', - 'dependencyGraph', - 'date_created', - 'version', - ]; - expect(jsonContent.keys, expectedKeys); + expect(flutterProject.flutterPluginsDependenciesFile.readAsStringSync(), + '{' + '"_info":"// This is a generated file; do not edit or check into version control.",' + '"dependencyGraph":[' + '{' + '"name":"plugin-a",' + '"dependencies":["plugin-b","plugin-c"]' + '},' + '{' + '"name":"plugin-b",' + '"dependencies":["plugin-c"]' + '},' + '{' + '"name":"plugin-c",' + '"dependencies":[]' + '}' + ']' + '}' + ); }, overrides: { FileSystem: () => fs, ProcessManager: () => FakeProcessManager.any(), - SystemClock: () => mockClock, - FlutterVersion: () => mockVersion }); testUsingContext('Changes to the plugin list invalidates the Cocoapod lockfiles', () { @@ -415,25 +316,8 @@ dependencies: FileSystem: () => fs, ProcessManager: () => FakeProcessManager.any(), }); - - testUsingContext('Changes to the plugin json list invalidates the Cocoapod lockfiles', () { - simulatePodInstallRun(iosProject); - simulatePodInstallRun(macosProject); - configureDummyPackageAsPlugin(); - - when(iosProject.existsSync()).thenReturn(true); - when(macosProject.existsSync()).thenReturn(true); - - refreshPluginsList(flutterProject); - expect(iosProject.podManifestLock.existsSync(), false); - expect(macosProject.podManifestLock.existsSync(), false); - }, overrides: { - FileSystem: () => fs, - ProcessManager: () => FakeProcessManager.any(), - }); }); - group('injectPlugins', () { MockFeatureFlags featureFlags; MockXcodeProjectInterpreter xcodeProjectInterpreter; @@ -716,7 +600,6 @@ dependencies: testUsingContext('Registrant for web doesn\'t escape slashes in imports', () async { when(flutterProject.isModule).thenReturn(true); when(featureFlags.isWebEnabled).thenReturn(true); - when(webProject.existsSync()).thenReturn(true); final Directory webPluginWithNestedFile = fs.systemTempDirectory.createTempSync('web_plugin_with_nested'); @@ -765,5 +648,3 @@ class MockIosProject extends Mock implements IosProject {} class MockMacOSProject extends Mock implements MacOSProject {} class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {} class MockWebProject extends Mock implements WebProject {} -class MockWindowsProject extends Mock implements WindowsProject {} -class MockLinuxProject extends Mock implements LinuxProject {}