Unverified Commit 457972b7 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Move doctor into globals (#54912)

* Move doctor into globals

* Fix tests
parent 6f9ee13e
......@@ -242,12 +242,8 @@ Future<String> _doctorText() async {
outputPreferences: globals.outputPreferences,
);
await context.run<bool>(
body: () => doctor.diagnose(verbose: true, showColor: false),
overrides: <Type, Generator>{
Logger: () => logger,
},
);
final Doctor doctor = Doctor(logger: logger);
await doctor.diagnose(verbose: true, showColor: false);
return logger.statusText;
} on Exception catch (error, trace) {
......
......@@ -19,7 +19,6 @@ import '../base/utils.dart';
import '../cache.dart';
import '../convert.dart';
import '../dart/pub.dart';
import '../doctor.dart';
import '../features.dart';
import '../flutter_project_metadata.dart';
import '../globals.dart' as globals;
......@@ -417,9 +416,9 @@ class CreateCommand extends FlutterCommand {
final String relativeAppMain = globals.fs.path.join(relativeAppPath, 'lib', 'main.dart');
final String relativePluginPath = globals.fs.path.normalize(globals.fs.path.relative(projectDirPath));
final String relativePluginMain = globals.fs.path.join(relativePluginPath, 'lib', '$projectName.dart');
if (doctor.canLaunchAnything) {
if (globals.doctor.canLaunchAnything) {
// Let them know a summary of the state of their tooling.
await doctor.summary();
await globals.doctor.summary();
globals.printStatus('''
In order to run your $application, type:
......@@ -443,7 +442,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
globals.printStatus('');
// Give the user more detailed analysis.
await doctor.diagnose();
await globals.doctor.diagnose();
globals.printStatus('');
globals.printStatus("After installing components, run 'flutter doctor' in order to "
're-validate your setup.');
......
......@@ -8,7 +8,6 @@ import '../base/common.dart';
import '../base/utils.dart';
import '../convert.dart';
import '../device.dart';
import '../doctor.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart';
......@@ -52,7 +51,7 @@ class DevicesCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
if (!doctor.canListAnything) {
if (!globals.doctor.canListAnything) {
throwToolExit(
"Unable to locate a development device; please run 'flutter doctor' for "
'information about installing additional components.',
......
......@@ -5,7 +5,6 @@
import 'dart:async';
import '../base/common.dart';
import '../doctor.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart';
......@@ -47,7 +46,7 @@ class DoctorCommand extends FlutterCommand {
if (argResults.wasParsed('check-for-remote-artifacts')) {
final String engineRevision = stringArg('check-for-remote-artifacts');
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
final bool success = await doctor.checkRemoteArtifacts(engineRevision);
final bool success = await globals.doctor.checkRemoteArtifacts(engineRevision);
if (!success) {
throwToolExit('Artifacts for engine $engineRevision are missing or are '
'not yet available.', exitCode: 1);
......@@ -57,7 +56,7 @@ class DoctorCommand extends FlutterCommand {
'git hash.');
}
}
final bool success = await doctor.diagnose(androidLicenses: boolArg('android-licenses'), verbose: verbose);
final bool success = await globals.doctor.diagnose(androidLicenses: boolArg('android-licenses'), verbose: verbose);
return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
}
}
......@@ -33,7 +33,7 @@ class EmulatorsCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() async {
if (doctor.workflows.every((Workflow w) => !w.canListEmulators)) {
if (globals.doctor.workflows.every((Workflow w) => !w.canListEmulators)) {
throwToolExit(
'Unable to find any emulator sources. Please ensure you have some\n'
'Android AVD images ' +
......
......@@ -126,7 +126,7 @@ Future<T> runInContext<T>(
),
DevFSConfig: () => DevFSConfig(),
DeviceManager: () => DeviceManager(),
Doctor: () => const Doctor(),
Doctor: () => Doctor(logger: globals.logger),
DoctorValidatorsProvider: () => DoctorValidatorsProvider.defaultInstance,
EmulatorManager: () => EmulatorManager(),
FeatureFlags: () => const FeatureFlags(),
......
......@@ -40,8 +40,6 @@ import 'web/workflow.dart';
import 'windows/visual_studio_validator.dart';
import 'windows/windows_workflow.dart';
Doctor get doctor => context.get<Doctor>();
abstract class DoctorValidatorsProvider {
/// The singleton instance, pulled from the [AppContext].
static DoctorValidatorsProvider get instance => context.get<DoctorValidatorsProvider>();
......@@ -153,7 +151,11 @@ class ValidatorTask {
}
class Doctor {
const Doctor();
Doctor({
@required Logger logger,
}) : _logger = logger;
final Logger _logger;
List<DoctorValidator> get validators {
return DoctorValidatorsProvider.instance.validators;
......@@ -184,7 +186,7 @@ class Doctor {
/// Print a summary of the state of the tooling, as well as how to get more info.
Future<void> summary() async {
globals.printStatus(await _summaryText());
_logger.printStatus(await _summaryText());
}
Future<String> _summaryText() async {
......@@ -263,7 +265,7 @@ class Doctor {
}
if (!verbose) {
globals.printStatus('Doctor summary (to see all details, run flutter doctor -v):');
_logger.printStatus('Doctor summary (to see all details, run flutter doctor -v):');
}
bool doctorResult = true;
int issues = 0;
......@@ -307,10 +309,10 @@ class Doctor {
final String leadingBox = showColor ? result.coloredLeadingBox : result.leadingBox;
if (result.statusInfo != null) {
globals.printStatus('$leadingBox ${validator.title} (${result.statusInfo})',
_logger.printStatus('$leadingBox ${validator.title} (${result.statusInfo})',
hangingIndent: result.leadingBox.length + 1);
} else {
globals.printStatus('$leadingBox ${validator.title}',
_logger.printStatus('$leadingBox ${validator.title}',
hangingIndent: result.leadingBox.length + 1);
}
......@@ -320,7 +322,7 @@ class Doctor {
int indent = 4;
final String indicator = showColor ? message.coloredIndicator : message.indicator;
for (final String line in '$indicator ${message.message}'.split('\n')) {
globals.printStatus(line, hangingIndent: hangingIndent, indent: indent, emphasis: true);
_logger.printStatus(line, hangingIndent: hangingIndent, indent: indent, emphasis: true);
// Only do hanging indent for the first line.
hangingIndent = 0;
indent = 6;
......@@ -328,20 +330,20 @@ class Doctor {
}
}
if (verbose) {
globals.printStatus('');
_logger.printStatus('');
}
}
// Make sure there's always one line before the summary even when not verbose.
if (!verbose) {
globals.printStatus('');
_logger.printStatus('');
}
if (issues > 0) {
globals.printStatus('${showColor ? globals.terminal.color('!', TerminalColor.yellow) : '!'}'
_logger.printStatus('${showColor ? globals.terminal.color('!', TerminalColor.yellow) : '!'}'
' Doctor found issues in $issues categor${issues > 1 ? "ies" : "y"}.', hangingIndent: 2);
} else {
globals.printStatus('${showColor ? globals.terminal.color('•', TerminalColor.green) : '•'}'
_logger.printStatus('${showColor ? globals.terminal.color('•', TerminalColor.green) : '•'}'
' No issues found!', hangingIndent: 2);
}
......
......@@ -22,6 +22,7 @@ import 'base/terminal.dart';
import 'base/user_messages.dart';
import 'build_system/build_system.dart';
import 'cache.dart';
import 'doctor.dart';
import 'fuchsia/fuchsia_sdk.dart';
import 'ios/ios_workflow.dart';
import 'ios/plist_parser.dart';
......@@ -39,6 +40,7 @@ Artifacts get artifacts => context.get<Artifacts>();
BuildSystem get buildSystem => context.get<BuildSystem>();
Cache get cache => context.get<Cache>();
Config get config => context.get<Config>();
Doctor get doctor => context.get<Doctor>();
Logger get logger => context.get<Logger>();
OperatingSystemUtils get os => context.get<OperatingSystemUtils>();
PersistentToolState get persistentToolState => PersistentToolState.instance;
......
......@@ -25,7 +25,6 @@ import '../cache.dart';
import '../dart/package_map.dart';
import '../dart/pub.dart';
import '../device.dart';
import '../doctor.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart';
......@@ -762,7 +761,7 @@ abstract class FlutterCommand extends Command<void> {
/// If no device can be found that meets specified criteria,
/// then print an error message and return null.
Future<List<Device>> findAllTargetDevices() async {
if (!doctor.canLaunchAnything) {
if (!globals.doctor.canLaunchAnything) {
globals.printError(userMessages.flutterNoDevelopmentDevice);
return null;
}
......
......@@ -109,7 +109,7 @@ void testUsingContext(
AnsiTerminal: () => AnsiTerminal(platform: globals.platform, stdio: globals.stdio),
Config: () => buildConfig(globals.fs),
DeviceManager: () => FakeDeviceManager(),
Doctor: () => FakeDoctor(),
Doctor: () => FakeDoctor(globals.logger),
FlutterVersion: () => MockFlutterVersion(),
HttpClient: () => MockHttpClient(),
IOSSimulatorUtils: () {
......@@ -261,6 +261,8 @@ class FakeAndroidLicenseValidator extends AndroidLicenseValidator {
}
class FakeDoctor extends Doctor {
FakeDoctor(Logger logger) : super(logger: logger);
// True for testing.
@override
bool get canListAnything => true;
......
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