Skip to content

Commit

Permalink
Allow a no-op default_package key for a plugin platform (flutter#45364)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh authored Nov 22, 2019
1 parent 90718da commit e43a69a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/flutter_tools/lib/src/plugins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,35 @@ class Plugin {

final Map<String, PluginPlatform> platforms = <String, PluginPlatform>{};

if (platformsYaml[AndroidPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, AndroidPlugin.kConfigKey)) {
platforms[AndroidPlugin.kConfigKey] = AndroidPlugin.fromYaml(
name,
platformsYaml[AndroidPlugin.kConfigKey] as YamlMap,
path,
);
}

if (platformsYaml[IOSPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, IOSPlugin.kConfigKey)) {
platforms[IOSPlugin.kConfigKey] =
IOSPlugin.fromYaml(name, platformsYaml[IOSPlugin.kConfigKey] as YamlMap);
}

if (platformsYaml[LinuxPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, LinuxPlugin.kConfigKey)) {
platforms[LinuxPlugin.kConfigKey] =
LinuxPlugin.fromYaml(name, platformsYaml[LinuxPlugin.kConfigKey] as YamlMap);
}

if (platformsYaml[MacOSPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, MacOSPlugin.kConfigKey)) {
platforms[MacOSPlugin.kConfigKey] =
MacOSPlugin.fromYaml(name, platformsYaml[MacOSPlugin.kConfigKey] as YamlMap);
}

if (platformsYaml[WebPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, WebPlugin.kConfigKey)) {
platforms[WebPlugin.kConfigKey] =
WebPlugin.fromYaml(name, platformsYaml[WebPlugin.kConfigKey] as YamlMap);
}

if (platformsYaml[WindowsPlugin.kConfigKey] != null) {
if (_providesImplementationForPlatform(platformsYaml, WindowsPlugin.kConfigKey)) {
platforms[WindowsPlugin.kConfigKey] =
WindowsPlugin.fromYaml(name, platformsYaml[WindowsPlugin.kConfigKey] as YamlMap);
}
Expand Down Expand Up @@ -178,7 +178,13 @@ class Plugin {
static List<String> _validateMultiPlatformYaml(YamlMap yaml) {
bool isInvalid(String key, bool Function(YamlMap) validate) {
final dynamic value = yaml[key];
return value is YamlMap && !validate(value);
if (!(value is YamlMap)) {
return false;
}
if (value.containsKey('default_package')) {
return false;
}
return !validate(value);
}
final List<String> errors = <String>[];
if (isInvalid(AndroidPlugin.kConfigKey, AndroidPlugin.validate)) {
Expand Down Expand Up @@ -213,6 +219,16 @@ class Plugin {
return errors;
}

static bool _providesImplementationForPlatform(YamlMap platformsYaml, String platformKey) {
if (!platformsYaml.containsKey(platformKey)) {
return false;
}
if (platformsYaml[platformKey].containsKey('default_package')) {
return false;
}
return true;
}

final String name;
final String path;

Expand Down
23 changes: 23 additions & 0 deletions packages/flutter_tools/test/general.shard/plugin_parsing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,28 @@ void main() {
expect(webPlugin.fileName, 'web_plugin.dart');
expect(windowsPlugin.pluginClass, 'WinSamplePlugin');
});

test('A default_package field is allowed', () {
const String pluginYamlRaw =
'platforms:\n'
' android:\n'
' default_package: sample_package_android\n'
' ios:\n'
' default_package: sample_package_ios\n'
' linux:\n'
' default_package: sample_package_linux\n'
' macos:\n'
' default_package: sample_package_macos\n'
' web:\n'
' default_package: sample_package_web\n'
' windows:\n'
' default_package: sample_package_windows\n';

final dynamic pluginYaml = loadYaml(pluginYamlRaw);
final Plugin plugin =
Plugin.fromYaml(_kTestPluginName, _kTestPluginPath, pluginYaml);

expect(plugin.platforms, <String, PluginPlatform> {});
});
});
}

0 comments on commit e43a69a

Please sign in to comment.