First pass at using platform abstraction for plugins (#92672)

This commit is contained in:
Jeff Ward
2022-03-09 17:10:21 -05:00
committed by GitHub
parent e8af40f06b
commit 0aab22807c
12 changed files with 203 additions and 75 deletions

View File

@@ -31,7 +31,7 @@ TaskFunction dartPluginRegistryTest({
'io.flutter.devicelab',
'--platforms',
'macos',
'plugin_platform_implementation',
'aplugin_platform_implementation',
],
environment: environment,
);
@@ -39,9 +39,9 @@ TaskFunction dartPluginRegistryTest({
final File pluginMain = File(path.join(
tempDir.absolute.path,
'plugin_platform_implementation',
'aplugin_platform_implementation',
'lib',
'plugin_platform_implementation.dart',
'aplugin_platform_implementation.dart',
));
if (!pluginMain.existsSync()) {
return TaskResult.failure('${pluginMain.path} does not exist');
@@ -49,9 +49,9 @@ TaskFunction dartPluginRegistryTest({
// Patch plugin main dart file.
await pluginMain.writeAsString('''
class PluginPlatformInterfaceMacOS {
class ApluginPlatformInterfaceMacOS {
static void registerWith() {
print('PluginPlatformInterfaceMacOS.registerWith() was called');
print('ApluginPlatformInterfaceMacOS.registerWith() was called');
}
}
''', flush: true);
@@ -59,18 +59,18 @@ class PluginPlatformInterfaceMacOS {
// Patch plugin main pubspec file.
final File pluginImplPubspec = File(path.join(
tempDir.absolute.path,
'plugin_platform_implementation',
'aplugin_platform_implementation',
'pubspec.yaml',
));
String pluginImplPubspecContent = await pluginImplPubspec.readAsString();
pluginImplPubspecContent = pluginImplPubspecContent.replaceFirst(
' pluginClass: PluginPlatformImplementationPlugin',
' pluginClass: PluginPlatformImplementationPlugin\n'
' dartPluginClass: PluginPlatformInterfaceMacOS\n',
' pluginClass: ApluginPlatformImplementationPlugin',
' pluginClass: ApluginPlatformImplementationPlugin\n'
' dartPluginClass: ApluginPlatformInterfaceMacOS\n',
);
pluginImplPubspecContent = pluginImplPubspecContent.replaceFirst(
' platforms:\n',
' implements: plugin_platform_interface\n'
' implements: aplugin_platform_interface\n'
' platforms:\n');
await pluginImplPubspec.writeAsString(pluginImplPubspecContent,
flush: true);
@@ -85,28 +85,28 @@ class PluginPlatformInterfaceMacOS {
'io.flutter.devicelab',
'--platforms',
'macos',
'plugin_platform_interface',
'aplugin_platform_interface',
],
environment: environment,
);
});
final File pluginInterfacePubspec = File(path.join(
tempDir.absolute.path,
'plugin_platform_interface',
'aplugin_platform_interface',
'pubspec.yaml',
));
String pluginInterfacePubspecContent =
await pluginInterfacePubspec.readAsString();
pluginInterfacePubspecContent =
pluginInterfacePubspecContent.replaceFirst(
' pluginClass: PluginPlatformInterfacePlugin',
' default_package: plugin_platform_implementation\n');
' pluginClass: ApluginPlatformInterfacePlugin',
' default_package: aplugin_platform_implementation\n');
pluginInterfacePubspecContent =
pluginInterfacePubspecContent.replaceFirst(
'dependencies:',
'dependencies:\n'
' plugin_platform_implementation:\n'
' path: ../plugin_platform_implementation\n');
' aplugin_platform_implementation:\n'
' path: ../aplugin_platform_implementation\n');
await pluginInterfacePubspec.writeAsString(pluginInterfacePubspecContent,
flush: true);
@@ -136,8 +136,8 @@ class PluginPlatformInterfaceMacOS {
appPubspecContent = appPubspecContent.replaceFirst(
'dependencies:',
'dependencies:\n'
' plugin_platform_interface:\n'
' path: ../plugin_platform_interface\n');
' aplugin_platform_interface:\n'
' path: ../aplugin_platform_interface\n');
await appPubspec.writeAsString(appPubspecContent, flush: true);
section('Flutter run for macos');
@@ -153,7 +153,7 @@ class PluginPlatformInterfaceMacOS {
.transform<String>(const LineSplitter())
.listen((String line) {
if (line.contains(
'PluginPlatformInterfaceMacOS.registerWith() was called')) {
'ApluginPlatformInterfaceMacOS.registerWith() was called')) {
registryExecutedCompleter.complete();
}
print('stdout: $line');