Unverified Commit 4ef8088c authored by 嘟囔's avatar 嘟囔 Committed by GitHub

feat: migrate macos/application_package.dart to null-safety (#87976)

parent 4ad8c15f
...@@ -2,10 +2,6 @@ ...@@ -2,10 +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 '../application_package.dart'; import '../application_package.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
...@@ -20,7 +16,7 @@ bool _isBundleDirectory(FileSystemEntity entity) => ...@@ -20,7 +16,7 @@ bool _isBundleDirectory(FileSystemEntity entity) =>
entity is Directory && entity.path.endsWith('.app'); entity is Directory && entity.path.endsWith('.app');
abstract class MacOSApp extends ApplicationPackage { abstract class MacOSApp extends ApplicationPackage {
MacOSApp({@required String projectBundleId}) : super(id: projectBundleId); MacOSApp({required String projectBundleId}) : super(id: projectBundleId);
/// Creates a new [MacOSApp] from a macOS project directory. /// Creates a new [MacOSApp] from a macOS project directory.
factory MacOSApp.fromMacOSProject(MacOSProject project) { factory MacOSApp.fromMacOSProject(MacOSProject project) {
...@@ -35,8 +31,8 @@ abstract class MacOSApp extends ApplicationPackage { ...@@ -35,8 +31,8 @@ abstract class MacOSApp extends ApplicationPackage {
/// "~/Library/Developer/Xcode/DerivedData/" and contains an executable /// "~/Library/Developer/Xcode/DerivedData/" and contains an executable
/// which is expected to start the application and send the observatory /// which is expected to start the application and send the observatory
/// port over stdout. /// port over stdout.
factory MacOSApp.fromPrebuiltApp(FileSystemEntity applicationBinary) { static MacOSApp? fromPrebuiltApp(FileSystemEntity applicationBinary) {
final _BundleInfo bundleInfo = _executableFromBundle(applicationBinary); final _BundleInfo? bundleInfo = _executableFromBundle(applicationBinary);
if (bundleInfo == null) { if (bundleInfo == null) {
return null; return null;
} }
...@@ -50,7 +46,7 @@ abstract class MacOSApp extends ApplicationPackage { ...@@ -50,7 +46,7 @@ abstract class MacOSApp extends ApplicationPackage {
} }
/// Look up the executable name for a macOS application bundle. /// Look up the executable name for a macOS application bundle.
static _BundleInfo _executableFromBundle(FileSystemEntity applicationBundle) { static _BundleInfo? _executableFromBundle(FileSystemEntity applicationBundle) {
final FileSystemEntityType entityType = globals.fs.typeSync(applicationBundle.path); final FileSystemEntityType entityType = globals.fs.typeSync(applicationBundle.path);
if (entityType == FileSystemEntityType.notFound) { if (entityType == FileSystemEntityType.notFound) {
globals.printError('File "${applicationBundle.path}" does not exist.'); globals.printError('File "${applicationBundle.path}" does not exist.');
...@@ -109,17 +105,17 @@ abstract class MacOSApp extends ApplicationPackage { ...@@ -109,17 +105,17 @@ abstract class MacOSApp extends ApplicationPackage {
@override @override
String get displayName => id; String get displayName => id;
String applicationBundle(BuildMode buildMode); String? applicationBundle(BuildMode buildMode);
String executable(BuildMode buildMode); String? executable(BuildMode buildMode);
} }
class PrebuiltMacOSApp extends MacOSApp { class PrebuiltMacOSApp extends MacOSApp {
PrebuiltMacOSApp({ PrebuiltMacOSApp({
@required this.bundleDir, required this.bundleDir,
@required this.bundleName, required this.bundleName,
@required this.projectBundleId, required this.projectBundleId,
@required String executable, required String executable,
}) : _executable = executable, }) : _executable = executable,
super(projectBundleId: projectBundleId); super(projectBundleId: projectBundleId);
...@@ -133,10 +129,10 @@ class PrebuiltMacOSApp extends MacOSApp { ...@@ -133,10 +129,10 @@ class PrebuiltMacOSApp extends MacOSApp {
String get name => bundleName; String get name => bundleName;
@override @override
String applicationBundle(BuildMode buildMode) => bundleDir.path; String? applicationBundle(BuildMode buildMode) => bundleDir.path;
@override @override
String executable(BuildMode buildMode) => _executable; String? executable(BuildMode buildMode) => _executable;
} }
class BuildableMacOSApp extends MacOSApp { class BuildableMacOSApp extends MacOSApp {
...@@ -148,7 +144,7 @@ class BuildableMacOSApp extends MacOSApp { ...@@ -148,7 +144,7 @@ class BuildableMacOSApp extends MacOSApp {
String get name => 'macOS'; String get name => 'macOS';
@override @override
String applicationBundle(BuildMode buildMode) { String? applicationBundle(BuildMode buildMode) {
final File appBundleNameFile = project.nameFile; final File appBundleNameFile = project.nameFile;
if (!appBundleNameFile.existsSync()) { if (!appBundleNameFile.existsSync()) {
globals.printError('Unable to find app name. ${appBundleNameFile.path} does not exist'); globals.printError('Unable to find app name. ${appBundleNameFile.path} does not exist');
...@@ -163,12 +159,12 @@ class BuildableMacOSApp extends MacOSApp { ...@@ -163,12 +159,12 @@ class BuildableMacOSApp extends MacOSApp {
} }
@override @override
String executable(BuildMode buildMode) { String? executable(BuildMode buildMode) {
final String directory = applicationBundle(buildMode); final String? directory = applicationBundle(buildMode);
if (directory == null) { if (directory == null) {
return null; return null;
} }
final _BundleInfo bundleInfo = MacOSApp._executableFromBundle(globals.fs.directory(directory)); final _BundleInfo? bundleInfo = MacOSApp._executableFromBundle(globals.fs.directory(directory));
return bundleInfo?.executable; return bundleInfo?.executable;
} }
} }
......
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