Skip to content

Commit

Permalink
[flutter_tool] partial null safety migration of tool source code (#10…
Browse files Browse the repository at this point in the history
…5798)
  • Loading branch information
jonahwilliams authored Jun 15, 2022
1 parent a7ddb9b commit 9203448
Show file tree
Hide file tree
Showing 48 changed files with 1,932 additions and 2,025 deletions.
1 change: 1 addition & 0 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ Future<void> _runGeneralToolTests() async {
_toolsPath,
testPaths: <String>[path.join('test', 'general.shard')],
enableFlutterToolAsserts: false,

// Detect unit test time regressions (poor time delay handling, etc).
// This overrides the 15 minute default for tools tests.
// See the README.md and dart_test.yaml files in the flutter_tools package.
Expand Down
28 changes: 12 additions & 16 deletions packages/flutter_tools/lib/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:meta/meta.dart';

import 'runner.dart' as runner;
import 'src/artifacts.dart';
import 'src/base/context.dart';
Expand Down Expand Up @@ -110,7 +106,7 @@ Future<void> main(List<String> args) async {
// devtools source code.
DevtoolsLauncher: () => DevtoolsServerLauncher(
processManager: globals.processManager,
dartExecutable: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
dartExecutable: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path,
logger: globals.logger,
botDetector: globals.botDetector,
),
Expand All @@ -134,8 +130,8 @@ Future<void> main(List<String> args) async {
}

List<FlutterCommand> generateCommands({
@required bool verboseHelp,
@required bool verbose,
required bool verboseHelp,
required bool verbose,
}) => <FlutterCommand>[
AnalyzeCommand(
verboseHelp: verboseHelp,
Expand All @@ -144,7 +140,7 @@ List<FlutterCommand> generateCommands({
processManager: globals.processManager,
logger: globals.logger,
terminal: globals.terminal,
artifacts: globals.artifacts,
artifacts: globals.artifacts!,
),
AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem),
AttachCommand(verboseHelp: verboseHelp),
Expand Down Expand Up @@ -210,9 +206,9 @@ List<FlutterCommand> generateCommands({
/// Our logger class hierarchy and runtime requirements are overly complicated.
class LoggerFactory {
LoggerFactory({
@required Terminal terminal,
@required Stdio stdio,
@required OutputPreferences outputPreferences,
required Terminal terminal,
required Stdio stdio,
required OutputPreferences outputPreferences,
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
}) : _terminal = terminal,
_stdio = stdio,
Expand All @@ -226,11 +222,11 @@ class LoggerFactory {

/// Create the appropriate logger for the current platform and configuration.
Logger createLogger({
@required bool verbose,
@required bool prefixedErrors,
@required bool machine,
@required bool daemon,
@required bool windows,
required bool verbose,
required bool prefixedErrors,
required bool machine,
required bool daemon,
required bool windows,
}) {
Logger logger;
if (windows) {
Expand Down
34 changes: 17 additions & 17 deletions packages/flutter_tools/lib/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8


import 'dart:async';

Expand Down Expand Up @@ -31,9 +31,9 @@ Future<int> run(
bool muteCommandLogging = false,
bool verbose = false,
bool verboseHelp = false,
bool reportCrashes,
String flutterVersion,
Map<Type, Generator> overrides,
bool? reportCrashes,
String? flutterVersion,
Map<Type, Generator>? overrides,
}) async {
if (muteCommandLogging) {
// Remove the verbose option; for help and doctor, users don't need to see
Expand All @@ -55,8 +55,8 @@ Future<int> run(
);

String getVersion() => flutterVersion ?? globals.flutterVersion.getVersionString(redactUnknownBranches: true);
Object firstError;
StackTrace firstStackTrace;
Object? firstError;
StackTrace? firstStackTrace;
return runZoned<Future<int>>(() async {
try {
await runner.run(args);
Expand All @@ -74,22 +74,22 @@ Future<int> run(
// This catches all exceptions to send to crash logging, etc.
firstError = error;
firstStackTrace = stackTrace;
return _handleToolError(error, stackTrace, verbose, args, reportCrashes, getVersion);
return _handleToolError(error, stackTrace, verbose, args, reportCrashes!, getVersion);
}
}, onError: (Object error, StackTrace stackTrace) async { // ignore: deprecated_member_use
// If sending a crash report throws an error into the zone, we don't want
// to re-try sending the crash report with *that* error. Rather, we want
// to send the original error that triggered the crash report.
firstError ??= error;
firstStackTrace ??= stackTrace;
await _handleToolError(firstError, firstStackTrace, verbose, args, reportCrashes, getVersion);
await _handleToolError(firstError!, firstStackTrace, verbose, args, reportCrashes!, getVersion);
});
}, overrides: overrides);
}

Future<int> _handleToolError(
dynamic error,
StackTrace stackTrace,
Object error,
StackTrace? stackTrace,
bool verbose,
List<String> args,
bool reportCrashes,
Expand All @@ -102,7 +102,7 @@ Future<int> _handleToolError(
return _exit(64);
} else if (error is ToolExit) {
if (error.message != null) {
globals.printError(error.message);
globals.printError(error.message!);
}
if (verbose) {
globals.printError('\n$stackTrace\n');
Expand Down Expand Up @@ -138,7 +138,7 @@ Future<int> _handleToolError(
);
await crashReportSender.sendReport(
error: error,
stackTrace: stackTrace,
stackTrace: stackTrace!,
getFlutterVersion: getFlutterVersion,
command: args.join(' '),
);
Expand All @@ -159,17 +159,17 @@ Future<int> _handleToolError(
final CrashDetails details = CrashDetails(
command: _crashCommand(args),
error: error,
stackTrace: stackTrace,
stackTrace: stackTrace!,
doctorText: doctorText,
);
final File file = await _createLocalCrashReport(details);
await globals.crashReporter.informUser(details, file);
await globals.crashReporter!.informUser(details, file);

return _exit(1);
// This catch catches all exceptions to ensure the message below is printed.
} catch (error) { // ignore: avoid_catches_without_on_clauses
} catch (error, st) { // ignore: avoid_catches_without_on_clauses
globals.stdio.stderrWrite(
'Unable to generate crash report due to secondary error: $error\n'
'Unable to generate crash report due to secondary error: $error\n$st\n'
'${globals.userMessages.flutterToolBugInstructions}\n',
);
// Any exception thrown here (including one thrown by `_exit()`) will
Expand Down Expand Up @@ -241,7 +241,7 @@ Future<int> _exit(int code) async {
}

// Run shutdown hooks before flushing logs
await globals.shutdownHooks.runShutdownHooks();
await globals.shutdownHooks!.runShutdownHooks();

final Completer<void> completer = Completer<void>();

Expand Down
22 changes: 11 additions & 11 deletions packages/flutter_tools/lib/src/android/android_workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class AndroidValidator extends DoctorValidator {
/// SDK have been accepted.
class AndroidLicenseValidator extends DoctorValidator {
AndroidLicenseValidator({
required AndroidSdk androidSdk,
required AndroidSdk? androidSdk,
required Platform platform,
required OperatingSystemUtils operatingSystemUtils,
required FileSystem fileSystem,
Expand All @@ -291,7 +291,7 @@ class AndroidLicenseValidator extends DoctorValidator {
_userMessages = userMessages,
super('Android license subvalidator');

final AndroidSdk _androidSdk;
final AndroidSdk? _androidSdk;
final AndroidStudio? _androidStudio;
final Stdio _stdio;
final OperatingSystemUtils _operatingSystemUtils;
Expand All @@ -309,13 +309,13 @@ class AndroidLicenseValidator extends DoctorValidator {
final List<ValidationMessage> messages = <ValidationMessage>[];

// Match pre-existing early termination behavior
if (_androidSdk == null || _androidSdk.latestVersion == null ||
_androidSdk.validateSdkWellFormed().isNotEmpty ||
if (_androidSdk == null || _androidSdk?.latestVersion == null ||
_androidSdk!.validateSdkWellFormed().isNotEmpty ||
! await _checkJavaVersionNoOutput()) {
return ValidationResult(ValidationType.missing, messages);
}

final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk.latestVersion!.buildToolsVersionName);
final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk!.latestVersion!.buildToolsVersionName);

// Check for licenses.
switch (await licensesAccepted) {
Expand Down Expand Up @@ -392,8 +392,8 @@ class AndroidLicenseValidator extends DoctorValidator {

try {
final Process process = await _processManager.start(
<String>[_androidSdk.sdkManagerPath!, '--licenses'],
environment: _androidSdk.sdkManagerEnv,
<String>[_androidSdk!.sdkManagerPath!, '--licenses'],
environment: _androidSdk!.sdkManagerEnv,
);
process.stdin.write('n\n');
// We expect logcat streams to occasionally contain invalid utf-8,
Expand Down Expand Up @@ -432,8 +432,8 @@ class AndroidLicenseValidator extends DoctorValidator {

try {
final Process process = await _processManager.start(
<String>[_androidSdk.sdkManagerPath!, '--licenses'],
environment: _androidSdk.sdkManagerEnv,
<String>[_androidSdk!.sdkManagerPath!, '--licenses'],
environment: _androidSdk!.sdkManagerEnv,
);

// The real stdin will never finish streaming. Pipe until the child process
Expand Down Expand Up @@ -463,15 +463,15 @@ class AndroidLicenseValidator extends DoctorValidator {
return exitCode == 0;
} on ProcessException catch (e) {
throwToolExit(_userMessages.androidCannotRunSdkManager(
_androidSdk.sdkManagerPath ?? '',
_androidSdk?.sdkManagerPath ?? '',
e.toString(),
_platform,
));
}
}

bool _canRunSdkManager() {
final String? sdkManagerPath = _androidSdk.sdkManagerPath;
final String? sdkManagerPath = _androidSdk?.sdkManagerPath;
if (sdkManagerPath == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
/// Creates a new AndroidApk based on the information in the Android manifest.
static Future<AndroidApk?> fromAndroidProject(
AndroidProject androidProject, {
required AndroidSdk androidSdk,
required AndroidSdk? androidSdk,
required ProcessManager processManager,
required UserMessages userMessages,
required ProcessUtils processUtils,
Expand All @@ -113,7 +113,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
// the application Id, so we need to look at what was actually built.
return AndroidApk.fromApk(
apkFile,
androidSdk: androidSdk,
androidSdk: androidSdk!,
processManager: processManager,
logger: logger,
userMessages: userMessages,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/base/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ class SettingsFile {

/// Given a data structure which is a Map of String to dynamic values, return
/// the same structure (`Map<String, dynamic>`) with the correct runtime types.
Map<String, dynamic>? castStringKeyedMap(dynamic untyped) {
Map<String, Object?>? castStringKeyedMap(Object? untyped) {
final Map<dynamic, dynamic>? map = untyped as Map<dynamic, dynamic>?;
return map?.cast<String, dynamic>();
return map?.cast<String, Object?>();
}

/// Smallest column that will be used for text wrapping. If the requested column
Expand Down
Loading

0 comments on commit 9203448

Please sign in to comment.