From f9c118b6b211f2c89bfae9cd63b6e3889f1008d0 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 3 Mar 2020 22:43:42 +0100 Subject: [PATCH] Exit for missing Windows plugin projects (#51838) Exit, rather than crash, if a Windows plugin is missing its project. Fixes #51743 --- .../windows/visual_studio_solution_utils.dart | 6 +++++- .../visual_studio_solution_utils_test.dart | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/windows/visual_studio_solution_utils.dart b/packages/flutter_tools/lib/src/windows/visual_studio_solution_utils.dart index c01d89a43e..66560ef873 100644 --- a/packages/flutter_tools/lib/src/windows/visual_studio_solution_utils.dart +++ b/packages/flutter_tools/lib/src/windows/visual_studio_solution_utils.dart @@ -32,10 +32,14 @@ class _PluginProjectInfo { }) { name = plugin.name; final File projectFile = fileSystem.directory(plugin.path).childDirectory('windows').childFile('plugin.vcxproj'); + try { guid = VisualStudioProject(projectFile, fileSystem: fileSystem).guid; - if (guid == null) { + } on FileSystemException { throwToolExit('Unable to find a plugin.vcxproj for plugin "$name"'); } + if (guid == null) { + throwToolExit('Unable to find a plugin.vcxproj ID for plugin "$name"'); + } } // The name of the plugin, which is also the name of the symlink folder. diff --git a/packages/flutter_tools/test/general.shard/windows/visual_studio_solution_utils_test.dart b/packages/flutter_tools/test/general.shard/windows/visual_studio_solution_utils_test.dart index ee7b8c0167..530022500b 100644 --- a/packages/flutter_tools/test/general.shard/windows/visual_studio_solution_utils_test.dart +++ b/packages/flutter_tools/test/general.shard/windows/visual_studio_solution_utils_test.dart @@ -222,12 +222,14 @@ EndGlobal'''); // Configures and returns a mock plugin with the given name and GUID in the // project's plugin symlink directory. - Plugin getMockPlugin(String name, String guid) { + Plugin getMockPlugin(String name, String guid, {bool createProject = true}) { final MockPlugin plugin = MockPlugin(); when(plugin.platforms).thenReturn({project.pluginConfigKey: null}); when(plugin.name).thenReturn(name); when(plugin.path).thenReturn(project.pluginSymlinkDirectory.childDirectory(name).path); - writeDummyPluginProject(name, guid); + if (createProject) { + writeDummyPluginProject(name, guid); + } return plugin; } @@ -422,6 +424,16 @@ EndGlobal'''); expect(RegExp(r'^([ \t]+\t|\t[ \t]+)GlobalSection\(\s*$', multiLine: true).hasMatch(newSolutionContents), false); expect(RegExp(r'^([ \t]+\t|\t[ \t]+)EndGlobalSection\s*$', multiLine: true).hasMatch(newSolutionContents), false); }); + + test('A plugin without a project exits without crashing', () async { + writeSolutionWithoutPlugins(); + + final List plugins = [ + getMockPlugin('plugin_a', pluginAGuid, createProject: false), + ]; + expect(() => VisualStudioSolutionUtils(project: project, fileSystem: fs).updatePlugins(plugins), + throwsToolExit()); + }); }); }