Skip to content

Commit

Permalink
Make Logger required when injected in flutter_tool (flutter#114111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman committed Oct 27, 2022
1 parent c6f6095 commit 28ab431
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 84 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ List<FlutterCommand> generateCommands({
DebugAdapterCommand(verboseHelp: verboseHelp),
DevicesCommand(verboseHelp: verboseHelp),
DoctorCommand(verbose: verbose),
DowngradeCommand(verboseHelp: verboseHelp),
DowngradeCommand(verboseHelp: verboseHelp, logger: globals.logger),
DriveCommand(verboseHelp: verboseHelp,
fileSystem: globals.fs,
logger: globals.logger,
Expand Down
14 changes: 7 additions & 7 deletions packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,35 @@ class DaemonCommand extends FlutterCommand {
class _DaemonServer {
_DaemonServer({
this.port,
this.logger,
required this.logger,
this.notifyingLogger,
});

final int? port;

/// Stdout logger used to print general server-related errors.
final Logger? logger;
final Logger logger;

// Logger that sends the message to the other end of daemon connection.
final NotifyingLogger? notifyingLogger;

Future<void> run() async {
final ServerSocket serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, port!);
logger!.printStatus('Daemon server listening on ${serverSocket.port}');
logger.printStatus('Daemon server listening on ${serverSocket.port}');

final StreamSubscription<Socket> subscription = serverSocket.listen(
(Socket socket) async {
// We have to listen to socket.done. Otherwise when the connection is
// reset, we will receive an uncatchable exception.
// https://github.com/dart-lang/sdk/issues/25518
final Future<void> socketDone = socket.done.catchError((Object error, StackTrace stackTrace) {
logger!.printError('Socket error: $error');
logger!.printTrace('$stackTrace');
logger.printError('Socket error: $error');
logger.printTrace('$stackTrace');
});
final Daemon daemon = Daemon(
DaemonConnection(
daemonStreams: DaemonStreams.fromSocket(socket, logger: logger!),
logger: logger!,
daemonStreams: DaemonStreams.fromSocket(socket, logger: logger),
logger: logger,
),
notifyingLogger: notifyingLogger,
);
Expand Down
14 changes: 6 additions & 8 deletions packages/flutter_tools/lib/src/commands/downgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DowngradeCommand extends FlutterCommand {
DowngradeCommand({
bool verboseHelp = false,
PersistentToolState? persistentToolState,
Logger? logger,
required Logger logger,
ProcessManager? processManager,
FlutterVersion? flutterVersion,
Terminal? terminal,
Expand Down Expand Up @@ -64,7 +64,7 @@ class DowngradeCommand extends FlutterCommand {
PersistentToolState? _persistentToolState;
ProcessUtils? _processUtils;
ProcessManager? _processManager;
Logger? _logger;
final Logger _logger;
Stdio? _stdio;
FileSystem? _fileSystem;

Expand All @@ -83,11 +83,10 @@ class DowngradeCommand extends FlutterCommand {
// values when being created. Fields must be lazily instantiated in runCommand,
// at least until the zone injection is refactored.
_terminal ??= globals.terminal;
_logger ??= globals.logger;
_flutterVersion ??= globals.flutterVersion;
_persistentToolState ??= globals.persistentToolState;
_processManager ??= globals.processManager;
_processUtils ??= ProcessUtils(processManager: _processManager!, logger: _logger!);
_processUtils ??= ProcessUtils(processManager: _processManager!, logger: _logger);
_stdio ??= globals.stdio;
_fileSystem ??= globals.fs;
String workingDirectory = Cache.flutterRoot!;
Expand Down Expand Up @@ -128,19 +127,18 @@ class DowngradeCommand extends FlutterCommand {
// If there is a terminal attached, prompt the user to confirm the downgrade.
final Stdio stdio = _stdio!;
final Terminal terminal = _terminal!;
final Logger logger = _logger!;
if (stdio.hasTerminal && boolArgDeprecated('prompt')) {
terminal.usesTerminalUi = true;
final String result = await terminal.promptForCharInput(
const <String>['y', 'n'],
prompt: 'Downgrade flutter to version $humanReadableVersion?',
logger: logger,
logger: _logger,
);
if (result == 'n') {
return FlutterCommandResult.success();
}
} else {
logger.printStatus('Downgrading Flutter to version $humanReadableVersion');
_logger.printStatus('Downgrading Flutter to version $humanReadableVersion');
}

// To downgrade the tool, we perform a git checkout --hard, and then
Expand Down Expand Up @@ -175,7 +173,7 @@ class DowngradeCommand extends FlutterCommand {
);
}
await FlutterVersion.resetFlutterVersionFreshnessCheck();
logger.printStatus('Success');
_logger.printStatus('Success');
return FlutterCommandResult.success();
}

Expand Down
26 changes: 13 additions & 13 deletions packages/flutter_tools/lib/src/commands/drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DriveCommand extends RunCommandBase {
@visibleForTesting FlutterDriverFactory? flutterDriverFactory,
@visibleForTesting this.signalsToHandle = const <ProcessSignal>{ProcessSignal.sigint, ProcessSignal.sigterm},
required FileSystem fileSystem,
required Logger? logger,
required Logger logger,
required Platform platform,
required this.signals,
}) : _flutterDriverFactory = flutterDriverFactory,
Expand Down Expand Up @@ -171,7 +171,7 @@ class DriveCommand extends RunCommandBase {

FlutterDriverFactory? _flutterDriverFactory;
final FileSystem _fileSystem;
final Logger? _logger;
final Logger _logger;
final FileSystemUtils _fsUtils;

@override
Expand Down Expand Up @@ -222,20 +222,20 @@ class DriveCommand extends RunCommandBase {
throwToolExit(null);
}
if (screenshot != null && !device.supportsScreenshot) {
_logger!.printError('Screenshot not supported for ${device.name}.');
_logger.printError('Screenshot not supported for ${device.name}.');
}

final bool web = device is WebServerDevice || device is ChromiumDevice;
_flutterDriverFactory ??= FlutterDriverFactory(
applicationPackageFactory: ApplicationPackageFactory.instance!,
logger: _logger!,
logger: _logger,
processUtils: globals.processUtils,
dartSdkPath: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path,
devtoolsLauncher: DevtoolsLauncher.instance!,
);
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
_fileSystem.file('.packages'),
logger: _logger!,
logger: _logger,
throwOnError: false,
);
final DriverService driverService = _flutterDriverFactory!.createDriverService(web);
Expand Down Expand Up @@ -297,7 +297,7 @@ class DriveCommand extends RunCommandBase {
);
// If the test is sent a signal, take a screenshot before exiting
final Map<ProcessSignal, Object> screenshotTokens = _registerScreenshotCallbacks((ProcessSignal signal) async {
_logger!.printError('Caught $signal');
_logger.printError('Caught $signal');
await _takeScreenshot(device);
});
final int testResult = await testResultFuture;
Expand All @@ -309,7 +309,7 @@ class DriveCommand extends RunCommandBase {
}

if (boolArgDeprecated('keep-app-running')) {
_logger!.printStatus('Leaving the application running.');
_logger.printStatus('Leaving the application running.');
} else {
final File? skslFile = stringArgDeprecated('write-sksl-on-exit') != null
? _fileSystem.file(stringArgDeprecated('write-sksl-on-exit'))
Expand All @@ -332,7 +332,7 @@ class DriveCommand extends RunCommandBase {
}

Map<ProcessSignal, Object> _registerScreenshotCallbacks(Function(ProcessSignal) callback) {
_logger!.printTrace('Registering signal handlers...');
_logger.printTrace('Registering signal handlers...');
final Map<ProcessSignal, Object> tokens = <ProcessSignal, Object>{};
for (final ProcessSignal signal in signalsToHandle) {
tokens[signal] = signals.addHandler(signal, callback);
Expand All @@ -341,7 +341,7 @@ class DriveCommand extends RunCommandBase {
}

void _unregisterScreenshotCallbacks(Map<ProcessSignal, Object> tokens) {
_logger!.printTrace('Unregistering signal handlers...');
_logger.printTrace('Unregistering signal handlers...');
for (final MapEntry<ProcessSignal, Object> entry in tokens.entries) {
signals.removeHandler(entry.key, entry.value);
}
Expand All @@ -362,7 +362,7 @@ class DriveCommand extends RunCommandBase {
// for the corresponding test file relative to it.
if (!_fileSystem.path.isRelative(appFile)) {
if (!_fileSystem.path.isWithin(packageDir, appFile)) {
_logger!.printError(
_logger.printError(
'Application file $appFile is outside the package directory $packageDir'
);
return null;
Expand All @@ -374,7 +374,7 @@ class DriveCommand extends RunCommandBase {
final List<String> parts = _fileSystem.path.split(appFile);

if (parts.length < 2) {
_logger!.printError(
_logger.printError(
'Application file $appFile must reside in one of the sub-directories '
'of the package structure, not in the root directory.'
);
Expand Down Expand Up @@ -402,9 +402,9 @@ class DriveCommand extends RunCommandBase {
'png',
);
await device.takeScreenshot(outputFile);
_logger!.printStatus('Screenshot written to ${outputFile.path}');
_logger.printStatus('Screenshot written to ${outputFile.path}');
} on Exception catch (error) {
_logger!.printError('Error taking screenshot: $error');
_logger.printError('Error taking screenshot: $error');
}
}
}
1 change: 0 additions & 1 deletion packages/flutter_tools/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ class RunCommand extends RunCommandBase {
ipv6: ipv6,
debuggingOptions: await createDebuggingOptions(webMode),
stayResident: stayResident,
urlTunneller: null,
fileSystem: globals.fs,
usage: globals.flutterUsage,
logger: globals.logger,
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/devtools_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {
DevtoolsServerLauncher({
required ProcessManager processManager,
required String dartExecutable,
required Logger? logger,
required Logger logger,
required BotDetector botDetector,
}) : _processManager = processManager,
_dartExecutable = dartExecutable,
Expand All @@ -31,7 +31,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {

final ProcessManager _processManager;
final String _dartExecutable;
final Logger? _logger;
final Logger _logger;
final BotDetector _botDetector;
final Completer<void> _processStartCompleter = Completer<void>();

Expand Down Expand Up @@ -73,7 +73,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {
_devToolsProcess!.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen(_logger!.printError);
.listen(_logger.printError);

final bool runningOnBot = await _botDetector.isRunningOnBot;
devToolsProcessExit = _devToolsProcess!.exitCode.then(
Expand All @@ -86,7 +86,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {

devToolsUrl = await completer.future;
} on Exception catch (e, st) {
_logger!.printError('Failed to launch DevTools: $e', stackTrace: st);
_logger.printError('Failed to launch DevTools: $e', stackTrace: st);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class WebDriverService extends DriverService {
disablePortPublication: debuggingOptions.disablePortPublication,
),
stayResident: true,
urlTunneller: null,
flutterProject: FlutterProject.current(),
fileSystem: globals.fs,
usage: globals.flutterUsage,
Expand Down

0 comments on commit 28ab431

Please sign in to comment.