Unverified Commit 4807f806 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove globals from logger (#78353)

parent 4b879c31
......@@ -9,7 +9,6 @@ import 'dart:async';
import 'package:meta/meta.dart';
import '../convert.dart';
import '../globals.dart' as globals;
import 'io.dart';
import 'terminal.dart' show Terminal, TerminalColor, OutputPreferences;
import 'utils.dart';
......@@ -132,6 +131,10 @@ abstract class Logger {
int progressIndicatorPadding = kDefaultStatusPadding,
});
/// A [SilentStatus] or an [AnsiSpinner] (depending on whether the
/// terminal is fancy enough), already started.
Status startSpinner({ VoidCallback onFinish });
/// Send an event to be emitted.
///
/// Only surfaces a value in machine modes, Loggers may ignore this message in
......@@ -214,6 +217,11 @@ class DelegatingLogger implements Logger {
);
}
@override
Status startSpinner({VoidCallback onFinish}) {
return _delegate.startSpinner(onFinish: onFinish);
}
@override
bool get supportsColor => _delegate.supportsColor;
......@@ -374,6 +382,22 @@ class StdoutLogger extends Logger {
return _status;
}
@override
Status startSpinner({ VoidCallback onFinish }) {
if (terminal.supportsColor) {
return AnsiSpinner(
onFinish: onFinish,
stopwatch: _stopwatchFactory.createStopwatch(),
terminal: terminal,
stdio: _stdio,
)..start();
}
return SilentStatus(
onFinish: onFinish,
stopwatch: _stopwatchFactory.createStopwatch(),
)..start();
}
void _clearStatus() {
_status = null;
}
......@@ -534,6 +558,14 @@ class BufferLogger extends Logger {
)..start();
}
@override
Status startSpinner({VoidCallback onFinish}) {
return SilentStatus(
stopwatch: _stopwatchFactory.createStopwatch(),
onFinish: onFinish,
)..start();
}
@override
void clear() {
_error.clear();
......@@ -731,26 +763,6 @@ abstract class Status {
@required Stopwatch stopwatch,
}) : _stopwatch = stopwatch;
/// A [SilentStatus] or an [AnsiSpinner] (depending on whether the
/// terminal is fancy enough), already started.
factory Status.withSpinner({
@required Stopwatch stopwatch,
@required Terminal terminal,
VoidCallback onFinish,
}) {
if (terminal.supportsColor) {
return AnsiSpinner(
onFinish: onFinish,
stopwatch: stopwatch,
terminal: terminal,
)..start();
}
return SilentStatus(
onFinish: onFinish,
stopwatch: stopwatch,
)..start();
}
final VoidCallback onFinish;
@protected
......@@ -822,10 +834,10 @@ class SummaryStatus extends Status {
@required Stopwatch stopwatch,
this.padding = kDefaultStatusPadding,
VoidCallback onFinish,
Stdio stdio,
@required Stdio stdio,
}) : assert(message != null),
assert(padding != null),
_stdio = stdio ?? globals.stdio,
_stdio = stdio,
super(
onFinish: onFinish,
stopwatch: stopwatch,
......@@ -890,8 +902,8 @@ class AnsiSpinner extends Status {
@required Stopwatch stopwatch,
@required Terminal terminal,
VoidCallback onFinish,
Stdio stdio,
}) : _stdio = stdio ?? globals.stdio,
@required Stdio stdio,
}) : _stdio = stdio,
_terminal = terminal,
super(
onFinish: onFinish,
......
......@@ -1024,6 +1024,7 @@ class NotifyingLogger extends DelegatingLogger {
@required Duration timeout,
String progressId,
bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding,
}) {
assert(timeout != null);
......@@ -1152,6 +1153,7 @@ class AppRunLogger extends DelegatingLogger {
@required Duration timeout,
String progressId,
bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding,
}) {
final int id = _nextProgressId++;
......
......@@ -357,7 +357,6 @@ Future<T> runInContext<T>(
processManager: globals.processManager,
platform: globals.platform,
fileSystem: globals.fs,
terminal: globals.terminal,
usage: globals.flutterUsage,
),
},
......
......@@ -308,10 +308,7 @@ class Doctor {
for (final ValidatorTask validatorTask in startValidatorTasks()) {
final DoctorValidator validator = validatorTask.validator;
final Status status = Status.withSpinner(
stopwatch: Stopwatch(),
terminal: globals.terminal,
);
final Status status = _logger.startSpinner();
ValidationResult result;
try {
result = await validatorTask.result;
......
......@@ -246,7 +246,6 @@ class XcodeProjectInterpreter {
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required Terminal terminal,
@required Usage usage,
}) {
return XcodeProjectInterpreter._(
......@@ -254,7 +253,6 @@ class XcodeProjectInterpreter {
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
terminal: terminal,
usage: usage,
);
}
......@@ -264,14 +262,12 @@ class XcodeProjectInterpreter {
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required Terminal terminal,
@required Usage usage,
int majorVersion,
int minorVersion,
int patchVersion,
}) : _platform = platform,
_fileSystem = fileSystem,
_terminal = terminal,
_logger = logger,
_processUtils = ProcessUtils(logger: logger, processManager: processManager),
_operatingSystemUtils = OperatingSystemUtils(
......@@ -307,7 +303,6 @@ class XcodeProjectInterpreter {
processManager: processManager,
usage: TestUsage(),
logger: BufferLogger.test(),
terminal: Terminal.test(),
majorVersion: majorVersion,
minorVersion: minorVersion,
patchVersion: patchVersion,
......@@ -318,7 +313,6 @@ class XcodeProjectInterpreter {
final FileSystem _fileSystem;
final ProcessUtils _processUtils;
final OperatingSystemUtils _operatingSystemUtils;
final Terminal _terminal;
final Logger _logger;
final Usage _usage;
......@@ -415,10 +409,7 @@ class XcodeProjectInterpreter {
String scheme,
Duration timeout = const Duration(minutes: 1),
}) async {
final Status status = Status.withSpinner(
stopwatch: Stopwatch(),
terminal: _terminal,
);
final Status status = _logger.startSpinner();
final List<String> showBuildSettingsCommand = <String>[
...xcrunCommand(),
'xcodebuild',
......
......@@ -760,6 +760,7 @@ class StreamLogger extends Logger {
@required Duration timeout,
String progressId,
bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding,
}) {
_log('[progress] $message');
......@@ -768,6 +769,14 @@ class StreamLogger extends Logger {
)..start();
}
@override
Status startSpinner({ VoidCallback onFinish }) {
return SilentStatus(
stopwatch: Stopwatch(),
onFinish: onFinish,
)..start();
}
bool _interrupt = false;
void interrupt() {
......
......@@ -18,7 +18,6 @@ import 'package:meta/meta.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
......@@ -659,7 +658,7 @@ void main() {
expect(lines[3], equals('0123456789' * 3));
});
testUsingContext('AppRunLogger writes plain text statuses when no app is active', () async {
testWithoutContext('AppRunLogger writes plain text statuses when no app is active', () async {
final BufferLogger buffer = BufferLogger.test();
final AppRunLogger logger = AppRunLogger(parent: buffer);
......
......@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/project.dart';
......@@ -41,7 +40,6 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: processManager,
terminal: Terminal.test(),
usage: null,
);
});
......@@ -101,7 +99,6 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: null,
);
});
......@@ -218,7 +215,6 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(),
);
fileSystem.file(xcodebuild).deleteSync();
......@@ -422,7 +418,6 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(),
);
......@@ -449,7 +444,6 @@ void main() {
fileSystem: fileSystem,
platform: platform,
processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(),
);
......
......@@ -628,7 +628,7 @@ class FakeStatusLogger extends DelegatingLogger {
Status status;
@override
Status startProgress(String message, {Duration timeout, String progressId, bool multilineOutput = false, int progressIndicatorPadding = kDefaultStatusPadding}) {
Status startProgress(String message, {Duration timeout, String progressId, bool multilineOutput = false, bool includeTiming = true, int progressIndicatorPadding = kDefaultStatusPadding}) {
return status;
}
}
......
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