Unverified Commit 3c24f167 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate platform_plugins to null safety (#78943)

parent bd940073
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
import 'base/common.dart'; import 'base/common.dart';
...@@ -35,11 +32,11 @@ abstract class NativeOrDartPlugin { ...@@ -35,11 +32,11 @@ abstract class NativeOrDartPlugin {
/// the [pluginClass] that will be the entry point to the plugin's native code. /// the [pluginClass] that will be the entry point to the plugin's native code.
class AndroidPlugin extends PluginPlatform { class AndroidPlugin extends PluginPlatform {
AndroidPlugin({ AndroidPlugin({
@required this.name, required this.name,
@required this.package, required this.package,
@required this.pluginClass, required this.pluginClass,
@required this.pluginPath, required this.pluginPath,
@required FileSystem fileSystem, required FileSystem fileSystem,
}) : _fileSystem = fileSystem; }) : _fileSystem = fileSystem;
factory AndroidPlugin.fromYaml(String name, YamlMap yaml, String pluginPath, FileSystem fileSystem) { factory AndroidPlugin.fromYaml(String name, YamlMap yaml, String pluginPath, FileSystem fileSystem) {
...@@ -88,7 +85,7 @@ class AndroidPlugin extends PluginPlatform { ...@@ -88,7 +85,7 @@ class AndroidPlugin extends PluginPlatform {
}; };
} }
Set<String> _cachedEmbeddingVersion; Set<String>? _cachedEmbeddingVersion;
/// Returns the version of the Android embedding. /// Returns the version of the Android embedding.
Set<String> get _supportedEmbedings => _cachedEmbeddingVersion ??= _getSupportedEmbeddings(); Set<String> get _supportedEmbedings => _cachedEmbeddingVersion ??= _getSupportedEmbeddings();
...@@ -118,7 +115,7 @@ class AndroidPlugin extends PluginPlatform { ...@@ -118,7 +115,7 @@ class AndroidPlugin extends PluginPlatform {
) )
]; ];
File mainPluginClass; File? mainPluginClass;
bool mainClassFound = false; bool mainClassFound = false;
for (final String mainClassCandidate in mainClassCandidates) { for (final String mainClassCandidate in mainClassCandidates) {
mainPluginClass = _fileSystem.file(mainClassCandidate); mainPluginClass = _fileSystem.file(mainClassCandidate);
...@@ -127,7 +124,7 @@ class AndroidPlugin extends PluginPlatform { ...@@ -127,7 +124,7 @@ class AndroidPlugin extends PluginPlatform {
break; break;
} }
} }
if (!mainClassFound) { if (mainPluginClass == null || !mainClassFound) {
assert(mainClassCandidates.length <= 2); assert(mainClassCandidates.length <= 2);
throwToolExit( throwToolExit(
"The plugin `$name` doesn't have a main class defined in ${mainClassCandidates.join(' or ')}. " "The plugin `$name` doesn't have a main class defined in ${mainClassCandidates.join(' or ')}. "
...@@ -158,9 +155,9 @@ class AndroidPlugin extends PluginPlatform { ...@@ -158,9 +155,9 @@ class AndroidPlugin extends PluginPlatform {
/// will be the entry point to the plugin's native code. /// will be the entry point to the plugin's native code.
class IOSPlugin extends PluginPlatform { class IOSPlugin extends PluginPlatform {
const IOSPlugin({ const IOSPlugin({
@required this.name, required this.name,
this.classPrefix, required this.classPrefix,
@required this.pluginClass, required this.pluginClass,
}); });
factory IOSPlugin.fromYaml(String name, YamlMap yaml) { factory IOSPlugin.fromYaml(String name, YamlMap yaml) {
...@@ -204,7 +201,7 @@ class IOSPlugin extends PluginPlatform { ...@@ -204,7 +201,7 @@ class IOSPlugin extends PluginPlatform {
/// [pluginClass] will be the entry point to the plugin's native code. /// [pluginClass] will be the entry point to the plugin's native code.
class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin {
const MacOSPlugin({ const MacOSPlugin({
@required this.name, required this.name,
this.pluginClass, this.pluginClass,
this.dartPluginClass, this.dartPluginClass,
}); });
...@@ -212,7 +209,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -212,7 +209,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin {
factory MacOSPlugin.fromYaml(String name, YamlMap yaml) { factory MacOSPlugin.fromYaml(String name, YamlMap yaml) {
assert(validate(yaml)); assert(validate(yaml));
// Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497.
String pluginClass = yaml[kPluginClass] as String; String? pluginClass = yaml[kPluginClass] as String;
if (pluginClass == 'none') { if (pluginClass == 'none') {
pluginClass = null; pluginClass = null;
} }
...@@ -233,8 +230,8 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -233,8 +230,8 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin {
static const String kConfigKey = 'macos'; static const String kConfigKey = 'macos';
final String name; final String name;
final String pluginClass; final String? pluginClass;
final String dartPluginClass; final String? dartPluginClass;
@override @override
bool isNative() => pluginClass != null; bool isNative() => pluginClass != null;
...@@ -255,7 +252,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -255,7 +252,7 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin {
/// [pluginClass] will be the entry point to the plugin's native code. /// [pluginClass] will be the entry point to the plugin's native code.
class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{
const WindowsPlugin({ const WindowsPlugin({
@required this.name, required this.name,
this.pluginClass, this.pluginClass,
this.dartPluginClass, this.dartPluginClass,
}) : assert(pluginClass != null || dartPluginClass != null); }) : assert(pluginClass != null || dartPluginClass != null);
...@@ -263,7 +260,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{ ...@@ -263,7 +260,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{
factory WindowsPlugin.fromYaml(String name, YamlMap yaml) { factory WindowsPlugin.fromYaml(String name, YamlMap yaml) {
assert(validate(yaml)); assert(validate(yaml));
// Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497.
String pluginClass = yaml[kPluginClass] as String; String? pluginClass = yaml[kPluginClass] as String;
if (pluginClass == 'none') { if (pluginClass == 'none') {
pluginClass = null; pluginClass = null;
} }
...@@ -284,8 +281,8 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{ ...@@ -284,8 +281,8 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{
static const String kConfigKey = 'windows'; static const String kConfigKey = 'windows';
final String name; final String name;
final String pluginClass; final String? pluginClass;
final String dartPluginClass; final String? dartPluginClass;
@override @override
bool isNative() => pluginClass != null; bool isNative() => pluginClass != null;
...@@ -295,7 +292,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{ ...@@ -295,7 +292,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{
return <String, dynamic>{ return <String, dynamic>{
'name': name, 'name': name,
if (pluginClass != null) 'class': pluginClass, if (pluginClass != null) 'class': pluginClass,
if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass), if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass!),
if (dartPluginClass != null) 'dartPluginClass': dartPluginClass, if (dartPluginClass != null) 'dartPluginClass': dartPluginClass,
}; };
} }
...@@ -307,7 +304,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{ ...@@ -307,7 +304,7 @@ class WindowsPlugin extends PluginPlatform implements NativeOrDartPlugin{
/// [pluginClass] will be the entry point to the plugin's native code. /// [pluginClass] will be the entry point to the plugin's native code.
class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
const LinuxPlugin({ const LinuxPlugin({
@required this.name, required this.name,
this.pluginClass, this.pluginClass,
this.dartPluginClass, this.dartPluginClass,
}) : assert(pluginClass != null || dartPluginClass != null); }) : assert(pluginClass != null || dartPluginClass != null);
...@@ -315,7 +312,7 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -315,7 +312,7 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
factory LinuxPlugin.fromYaml(String name, YamlMap yaml) { factory LinuxPlugin.fromYaml(String name, YamlMap yaml) {
assert(validate(yaml)); assert(validate(yaml));
// Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497.
String pluginClass = yaml[kPluginClass] as String; String? pluginClass = yaml[kPluginClass] as String;
if (pluginClass == 'none') { if (pluginClass == 'none') {
pluginClass = null; pluginClass = null;
} }
...@@ -336,8 +333,8 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -336,8 +333,8 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
static const String kConfigKey = 'linux'; static const String kConfigKey = 'linux';
final String name; final String name;
final String pluginClass; final String? pluginClass;
final String dartPluginClass; final String? dartPluginClass;
@override @override
bool isNative() => pluginClass != null; bool isNative() => pluginClass != null;
...@@ -347,7 +344,7 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -347,7 +344,7 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
return <String, dynamic>{ return <String, dynamic>{
'name': name, 'name': name,
if (pluginClass != null) 'class': pluginClass, if (pluginClass != null) 'class': pluginClass,
if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass), if (pluginClass != null) 'filename': _filenameForCppClass(pluginClass!),
if (dartPluginClass != null) 'dartPluginClass': dartPluginClass, if (dartPluginClass != null) 'dartPluginClass': dartPluginClass,
}; };
} }
...@@ -360,9 +357,9 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { ...@@ -360,9 +357,9 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin {
/// containing the code. /// containing the code.
class WebPlugin extends PluginPlatform { class WebPlugin extends PluginPlatform {
const WebPlugin({ const WebPlugin({
@required this.name, required this.name,
@required this.pluginClass, required this.pluginClass,
@required this.fileName, required this.fileName,
}); });
factory WebPlugin.fromYaml(String name, YamlMap yaml) { factory WebPlugin.fromYaml(String name, YamlMap yaml) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment