Skip to content

Commit f9c118b

Browse files
Exit for missing Windows plugin projects (flutter#51838)
Exit, rather than crash, if a Windows plugin is missing its project. Fixes flutter#51743
1 parent 8d8439f commit f9c118b

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/flutter_tools/lib/src/windows/visual_studio_solution_utils.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ class _PluginProjectInfo {
3232
}) {
3333
name = plugin.name;
3434
final File projectFile = fileSystem.directory(plugin.path).childDirectory('windows').childFile('plugin.vcxproj');
35+
try {
3536
guid = VisualStudioProject(projectFile, fileSystem: fileSystem).guid;
36-
if (guid == null) {
37+
} on FileSystemException {
3738
throwToolExit('Unable to find a plugin.vcxproj for plugin "$name"');
3839
}
40+
if (guid == null) {
41+
throwToolExit('Unable to find a plugin.vcxproj ID for plugin "$name"');
42+
}
3943
}
4044

4145
// The name of the plugin, which is also the name of the symlink folder.

packages/flutter_tools/test/general.shard/windows/visual_studio_solution_utils_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,14 @@ EndGlobal''');
222222

223223
// Configures and returns a mock plugin with the given name and GUID in the
224224
// project's plugin symlink directory.
225-
Plugin getMockPlugin(String name, String guid) {
225+
Plugin getMockPlugin(String name, String guid, {bool createProject = true}) {
226226
final MockPlugin plugin = MockPlugin();
227227
when(plugin.platforms).thenReturn(<String, PluginPlatform>{project.pluginConfigKey: null});
228228
when(plugin.name).thenReturn(name);
229229
when(plugin.path).thenReturn(project.pluginSymlinkDirectory.childDirectory(name).path);
230-
writeDummyPluginProject(name, guid);
230+
if (createProject) {
231+
writeDummyPluginProject(name, guid);
232+
}
231233
return plugin;
232234
}
233235

@@ -422,6 +424,16 @@ EndGlobal''');
422424
expect(RegExp(r'^([ \t]+\t|\t[ \t]+)GlobalSection\(\s*$', multiLine: true).hasMatch(newSolutionContents), false);
423425
expect(RegExp(r'^([ \t]+\t|\t[ \t]+)EndGlobalSection\s*$', multiLine: true).hasMatch(newSolutionContents), false);
424426
});
427+
428+
test('A plugin without a project exits without crashing', () async {
429+
writeSolutionWithoutPlugins();
430+
431+
final List<Plugin> plugins = <Plugin>[
432+
getMockPlugin('plugin_a', pluginAGuid, createProject: false),
433+
];
434+
expect(() => VisualStudioSolutionUtils(project: project, fileSystem: fs).updatePlugins(plugins),
435+
throwsToolExit());
436+
});
425437
});
426438
}
427439

0 commit comments

Comments
 (0)