Android license detector in doctor, take two (#14783)
* Revert "Revert "Add android license verification to doctor and some refactoring" (#14727)"
This reverts commit d260294752.
* Add tests, fix sdkManagerEnv and use it consistently, and rearrange Status object model
* AnsiSpinner needs to leave the cursor where it found it.
* fix tests
* Const constructor warning only shows up on windows...?
* Avoid crash if we can't find the home directory
* Make pathVarSeparator return a string in the mock
* Implement review comments
* Fix out-of-order problem on stop
This commit is contained in:
@@ -12,9 +12,11 @@ import '../base/file_system.dart';
|
||||
import '../base/io.dart' show ProcessResult;
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/version.dart';
|
||||
import '../globals.dart';
|
||||
import 'android_studio.dart' as android_studio;
|
||||
|
||||
AndroidSdk get androidSdk => context[AndroidSdk];
|
||||
|
||||
@@ -63,6 +65,9 @@ class AndroidSdk {
|
||||
_init();
|
||||
}
|
||||
|
||||
static const String _kJavaHomeEnvironmentVariable = 'JAVA_HOME';
|
||||
static const String _kJavaExecutable = 'java';
|
||||
|
||||
/// The path to the Android SDK.
|
||||
final String directory;
|
||||
|
||||
@@ -291,11 +296,56 @@ class AndroidSdk {
|
||||
return fs.path.join(directory, 'tools', 'bin', 'sdkmanager');
|
||||
}
|
||||
|
||||
/// First try Java bundled with Android Studio, then sniff JAVA_HOME, then fallback to PATH.
|
||||
static String findJavaBinary() {
|
||||
|
||||
if (android_studio.javaPath != null)
|
||||
return fs.path.join(android_studio.javaPath, 'bin', 'java');
|
||||
|
||||
final String javaHomeEnv = platform.environment[_kJavaHomeEnvironmentVariable];
|
||||
if (javaHomeEnv != null) {
|
||||
// Trust JAVA_HOME.
|
||||
return fs.path.join(javaHomeEnv, 'bin', 'java');
|
||||
}
|
||||
|
||||
// MacOS specific logic to avoid popping up a dialog window.
|
||||
// See: http://stackoverflow.com/questions/14292698/how-do-i-check-if-the-java-jdk-is-installed-on-mac.
|
||||
if (platform.isMacOS) {
|
||||
try {
|
||||
final String javaHomeOutput = runCheckedSync(<String>['/usr/libexec/java_home'], hideStdout: true);
|
||||
if (javaHomeOutput != null) {
|
||||
final List<String> javaHomeOutputSplit = javaHomeOutput.split('\n');
|
||||
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) {
|
||||
final String javaHome = javaHomeOutputSplit[0].trim();
|
||||
return fs.path.join(javaHome, 'bin', 'java');
|
||||
}
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
|
||||
// Fallback to PATH based lookup.
|
||||
return os.which(_kJavaExecutable)?.path;
|
||||
}
|
||||
|
||||
Map<String, String> _sdkManagerEnv;
|
||||
Map<String, String> get sdkManagerEnv {
|
||||
if (_sdkManagerEnv == null) {
|
||||
// If we can locate Java, then add it to the path used to run the Android SDK manager.
|
||||
_sdkManagerEnv = <String, String>{};
|
||||
final String javaBinary = findJavaBinary();
|
||||
if (javaBinary != null) {
|
||||
_sdkManagerEnv['PATH'] =
|
||||
fs.path.dirname(javaBinary) + os.pathVarSeparator + platform.environment['PATH'];
|
||||
}
|
||||
}
|
||||
return _sdkManagerEnv;
|
||||
}
|
||||
|
||||
/// Returns the version of the Android SDK manager tool or null if not found.
|
||||
String get sdkManagerVersion {
|
||||
if (!processManager.canRun(sdkManagerPath))
|
||||
throwToolExit('Android sdkmanager not found. Update to the latest Android SDK to resolve this.');
|
||||
final ProcessResult result = processManager.runSync(<String>[sdkManagerPath, '--version']);
|
||||
final ProcessResult result = processManager.runSync(<String>[sdkManagerPath, '--version'], environment: sdkManagerEnv);
|
||||
if (result.exitCode != 0) {
|
||||
throwToolExit('sdkmanager --version failed: ${result.exitCode}', exitCode: result.exitCode);
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
|
||||
// Read all $HOME/.AndroidStudio*/system/.home files. There may be several
|
||||
// pointing to the same installation, so we grab only the latest one.
|
||||
for (FileSystemEntity entity in fs.directory(homeDirPath).listSync()) {
|
||||
if (entity is Directory && entity.basename.startsWith('.AndroidStudio')) {
|
||||
final AndroidStudio studio = new AndroidStudio.fromHomeDot(entity);
|
||||
if (studio != null &&
|
||||
!_hasStudioAt(studio.directory, newerThan: studio.version)) {
|
||||
studios.removeWhere(
|
||||
(AndroidStudio other) => other.directory == studio.directory);
|
||||
studios.add(studio);
|
||||
if (fs.directory(homeDirPath).existsSync()) {
|
||||
for (FileSystemEntity entity in fs.directory(homeDirPath).listSync()) {
|
||||
if (entity is Directory && entity.basename.startsWith('.AndroidStudio')) {
|
||||
final AndroidStudio studio = new AndroidStudio.fromHomeDot(entity);
|
||||
if (studio != null && !_hasStudioAt(studio.directory, newerThan: studio.version)) {
|
||||
studios.removeWhere((AndroidStudio other) => other.directory == studio.directory);
|
||||
studios.add(studio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
@@ -17,10 +16,20 @@ import '../base/version.dart';
|
||||
import '../doctor.dart';
|
||||
import '../globals.dart';
|
||||
import 'android_sdk.dart';
|
||||
import 'android_studio.dart' as android_studio;
|
||||
|
||||
AndroidWorkflow get androidWorkflow => context.putIfAbsent(AndroidWorkflow, () => new AndroidWorkflow());
|
||||
|
||||
enum LicensesAccepted {
|
||||
none,
|
||||
some,
|
||||
all,
|
||||
unknown,
|
||||
}
|
||||
|
||||
final RegExp licenseCounts = new RegExp(r'(\d+) of (\d+) SDK package licenses? not accepted.');
|
||||
final RegExp licenseNotAccepted = new RegExp(r'licenses? not accepted', caseSensitive: false);
|
||||
final RegExp licenseAccepted = new RegExp(r'All SDK package licenses accepted.');
|
||||
|
||||
class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
AndroidWorkflow() : super('Android toolchain - develop for Android devices');
|
||||
|
||||
@@ -33,41 +42,8 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
@override
|
||||
bool get canLaunchDevices => androidSdk != null && androidSdk.validateSdkWellFormed().isEmpty;
|
||||
|
||||
static const String _kJavaHomeEnvironmentVariable = 'JAVA_HOME';
|
||||
static const String _kJavaExecutable = 'java';
|
||||
static const String _kJdkDownload = 'https://www.oracle.com/technetwork/java/javase/downloads/';
|
||||
|
||||
/// First try Java bundled with Android Studio, then sniff JAVA_HOME, then fallback to PATH.
|
||||
static String _findJavaBinary() {
|
||||
|
||||
if (android_studio.javaPath != null)
|
||||
return fs.path.join(android_studio.javaPath, 'bin', 'java');
|
||||
|
||||
final String javaHomeEnv = platform.environment[_kJavaHomeEnvironmentVariable];
|
||||
if (javaHomeEnv != null) {
|
||||
// Trust JAVA_HOME.
|
||||
return fs.path.join(javaHomeEnv, 'bin', 'java');
|
||||
}
|
||||
|
||||
// MacOS specific logic to avoid popping up a dialog window.
|
||||
// See: http://stackoverflow.com/questions/14292698/how-do-i-check-if-the-java-jdk-is-installed-on-mac.
|
||||
if (platform.isMacOS) {
|
||||
try {
|
||||
final String javaHomeOutput = runCheckedSync(<String>['/usr/libexec/java_home'], hideStdout: true);
|
||||
if (javaHomeOutput != null) {
|
||||
final List<String> javaHomeOutputSplit = javaHomeOutput.split('\n');
|
||||
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) {
|
||||
final String javaHome = javaHomeOutputSplit[0].trim();
|
||||
return fs.path.join(javaHome, 'bin', 'java');
|
||||
}
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
|
||||
// Fallback to PATH based lookup.
|
||||
return os.which(_kJavaExecutable)?.path;
|
||||
}
|
||||
|
||||
/// Returns false if we cannot determine the Java version or if the version
|
||||
/// is not compatible.
|
||||
bool _checkJavaVersion(String javaBinary, List<ValidationMessage> messages) {
|
||||
@@ -154,7 +130,7 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
}
|
||||
|
||||
// Now check for the JDK.
|
||||
final String javaBinary = _findJavaBinary();
|
||||
final String javaBinary = AndroidSdk.findJavaBinary();
|
||||
if (javaBinary == null) {
|
||||
messages.add(new ValidationMessage.error(
|
||||
'No Java Development Kit (JDK) found; You must have the environment '
|
||||
@@ -169,10 +145,59 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
return new ValidationResult(ValidationType.partial, messages, statusInfo: sdkVersionText);
|
||||
}
|
||||
|
||||
// Check for licenses.
|
||||
switch (await licensesAccepted) {
|
||||
case LicensesAccepted.all:
|
||||
messages.add(new ValidationMessage('All Android licenses accepted.'));
|
||||
break;
|
||||
case LicensesAccepted.some:
|
||||
messages.add(new ValidationMessage.hint('Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses'));
|
||||
return new ValidationResult(ValidationType.partial, messages, statusInfo: sdkVersionText);
|
||||
case LicensesAccepted.none:
|
||||
messages.add(new ValidationMessage.error('Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses'));
|
||||
return new ValidationResult(ValidationType.partial, messages, statusInfo: sdkVersionText);
|
||||
case LicensesAccepted.unknown:
|
||||
messages.add(new ValidationMessage.error('Android license status unknown.'));
|
||||
return new ValidationResult(ValidationType.partial, messages, statusInfo: sdkVersionText);
|
||||
}
|
||||
|
||||
// Success.
|
||||
return new ValidationResult(ValidationType.installed, messages, statusInfo: sdkVersionText);
|
||||
}
|
||||
|
||||
Future<LicensesAccepted> get licensesAccepted async {
|
||||
LicensesAccepted status = LicensesAccepted.unknown;
|
||||
|
||||
void _onLine(String line) {
|
||||
if (licenseAccepted.hasMatch(line)) {
|
||||
status = LicensesAccepted.all;
|
||||
} else if (licenseCounts.hasMatch(line)) {
|
||||
final Match match = licenseCounts.firstMatch(line);
|
||||
if (match.group(1) != match.group(2)) {
|
||||
status = LicensesAccepted.some;
|
||||
} else {
|
||||
status = LicensesAccepted.none;
|
||||
}
|
||||
} else if (licenseNotAccepted.hasMatch(line)) {
|
||||
// In case the format changes, a more general match will keep doctor
|
||||
// mostly working.
|
||||
status = LicensesAccepted.none;
|
||||
}
|
||||
}
|
||||
|
||||
final Process process = await runCommand(<String>[androidSdk.sdkManagerPath, '--licenses'], environment: androidSdk.sdkManagerEnv);
|
||||
process.stdin.write('n\n');
|
||||
final Future<void> output = process.stdout.transform(const Utf8Decoder(allowMalformed: true)).transform(const LineSplitter()).listen(_onLine).asFuture<void>(null);
|
||||
final Future<void> errors = process.stderr.transform(const Utf8Decoder(allowMalformed: true)).transform(const LineSplitter()).listen(_onLine).asFuture<void>(null);
|
||||
try {
|
||||
await Future.wait<void>(<Future<void>>[output, errors]).timeout(const Duration(seconds: 30));
|
||||
} catch (TimeoutException) {
|
||||
printTrace('Intentionally killing ${androidSdk.sdkManagerPath}');
|
||||
processManager.killPid(process.pid);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/// Run the Android SDK manager tool in order to accept SDK licenses.
|
||||
static Future<bool> runLicenseManager() async {
|
||||
if (androidSdk == null) {
|
||||
@@ -180,14 +205,6 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we can locate Java, then add it to the path used to run the Android SDK manager.
|
||||
final Map<String, String> sdkManagerEnv = <String, String>{};
|
||||
final String javaBinary = _findJavaBinary();
|
||||
if (javaBinary != null) {
|
||||
sdkManagerEnv['PATH'] =
|
||||
fs.path.dirname(javaBinary) + os.pathVarSeparator + platform.environment['PATH'];
|
||||
}
|
||||
|
||||
if (!processManager.canRun(androidSdk.sdkManagerPath))
|
||||
throwToolExit(
|
||||
'Android sdkmanager tool not found.\n'
|
||||
@@ -205,7 +222,7 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
|
||||
|
||||
final Process process = await runCommand(
|
||||
<String>[androidSdk.sdkManagerPath, '--licenses'],
|
||||
environment: sdkManagerEnv,
|
||||
environment: androidSdk.sdkManagerEnv,
|
||||
);
|
||||
|
||||
waitGroup<Null>(<Future<Null>>[
|
||||
|
||||
@@ -11,6 +11,8 @@ import 'io.dart';
|
||||
import 'terminal.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
const int kDefaultStatusPadding = 59;
|
||||
|
||||
abstract class Logger {
|
||||
bool get isVerbose => false;
|
||||
|
||||
@@ -47,15 +49,10 @@ abstract class Logger {
|
||||
String message, {
|
||||
String progressId,
|
||||
bool expectSlowOperation: false,
|
||||
int progressIndicatorPadding: 52,
|
||||
int progressIndicatorPadding: kDefaultStatusPadding,
|
||||
});
|
||||
}
|
||||
|
||||
class Status {
|
||||
void stop() { }
|
||||
void cancel() { }
|
||||
}
|
||||
|
||||
typedef void _FinishCallback();
|
||||
|
||||
class StdoutLogger extends Logger {
|
||||
@@ -108,25 +105,19 @@ class StdoutLogger extends Logger {
|
||||
String message, {
|
||||
String progressId,
|
||||
bool expectSlowOperation: false,
|
||||
int progressIndicatorPadding: 52,
|
||||
int progressIndicatorPadding: 59,
|
||||
}) {
|
||||
if (_status != null) {
|
||||
// Ignore nested progresses; return a no-op status object.
|
||||
return new Status();
|
||||
} else {
|
||||
if (supportsColor) {
|
||||
_status = new _AnsiStatus(
|
||||
message,
|
||||
expectSlowOperation,
|
||||
() { _status = null; },
|
||||
progressIndicatorPadding,
|
||||
);
|
||||
return _status;
|
||||
} else {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
}
|
||||
return new Status()..start();
|
||||
}
|
||||
if (terminal.supportsColor) {
|
||||
_status = new AnsiStatus(message, expectSlowOperation, () { _status = null; }, progressIndicatorPadding)..start();
|
||||
} else {
|
||||
printStatus(message);
|
||||
_status = new Status()..start();
|
||||
}
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +133,7 @@ class WindowsStdoutLogger extends StdoutLogger {
|
||||
|
||||
@override
|
||||
void writeToStdOut(String message) {
|
||||
// TODO(jcollins-g): wrong abstraction layer for this, move to [Stdio].
|
||||
stdout.write(message
|
||||
.replaceAll('✗', 'X')
|
||||
.replaceAll('✓', '√')
|
||||
@@ -185,7 +177,7 @@ class BufferLogger extends Logger {
|
||||
String message, {
|
||||
String progressId,
|
||||
bool expectSlowOperation: false,
|
||||
int progressIndicatorPadding: 52,
|
||||
int progressIndicatorPadding: kDefaultStatusPadding,
|
||||
}) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
@@ -235,7 +227,7 @@ class VerboseLogger extends Logger {
|
||||
String message, {
|
||||
String progressId,
|
||||
bool expectSlowOperation: false,
|
||||
int progressIndicatorPadding: 52,
|
||||
int progressIndicatorPadding: kDefaultStatusPadding,
|
||||
}) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
@@ -280,57 +272,140 @@ enum _LogType {
|
||||
trace
|
||||
}
|
||||
|
||||
class _AnsiStatus extends Status {
|
||||
_AnsiStatus(this.message, this.expectSlowOperation, this.onFinish, int padding) {
|
||||
stopwatch = new Stopwatch()..start();
|
||||
/// A [Status] class begins when start is called, and may produce progress
|
||||
/// information asynchronously.
|
||||
///
|
||||
/// When stop is called, summary information supported by this class is printed.
|
||||
/// If cancel is called, no summary information is displayed.
|
||||
/// The base class displays nothing at all.
|
||||
class Status {
|
||||
Status();
|
||||
|
||||
stdout.write('${message.padRight(padding)} ');
|
||||
stdout.write('${_progress[0]}');
|
||||
bool _isStarted = false;
|
||||
|
||||
factory Status.withSpinner() {
|
||||
if (terminal.supportsColor)
|
||||
return new AnsiSpinner()..start();
|
||||
return new Status()..start();
|
||||
}
|
||||
|
||||
/// Display summary information for this spinner; called by [stop].
|
||||
void summaryInformation() {}
|
||||
|
||||
/// Call to start spinning. Call this method via super at the beginning
|
||||
/// of a subclass [start] method.
|
||||
void start() {
|
||||
_isStarted = true;
|
||||
}
|
||||
|
||||
/// Call to stop spinning and delete the spinner. Print summary information,
|
||||
/// if applicable to the spinner.
|
||||
void stop() {
|
||||
if (_isStarted) {
|
||||
cancel();
|
||||
summaryInformation();
|
||||
}
|
||||
}
|
||||
|
||||
/// Call to cancel the spinner without printing any summary output. Call
|
||||
/// this method via super at the end of a subclass [cancel] method.
|
||||
void cancel() {
|
||||
_isStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// An [AnsiSpinner] is a simple animation that does nothing but implement an
|
||||
/// ASCII spinner. When stopped or canceled, the animation erases itself.
|
||||
class AnsiSpinner extends Status {
|
||||
int ticks = 0;
|
||||
Timer timer;
|
||||
|
||||
static final List<String> _progress = <String>['-', r'\', '|', r'/'];
|
||||
|
||||
void _callback(Timer _) {
|
||||
stdout.write('\b${_progress[ticks++ % _progress.length]}');
|
||||
}
|
||||
|
||||
@override
|
||||
void start() {
|
||||
super.start();
|
||||
stdout.write(' ');
|
||||
_callback(null);
|
||||
timer = new Timer.periodic(const Duration(milliseconds: 100), _callback);
|
||||
}
|
||||
|
||||
static final List<String> _progress = <String>['-', r'\', '|', r'/', '-', r'\', '|', '/'];
|
||||
@override
|
||||
/// Clears the spinner. After cancel, the cursor will be one space right
|
||||
/// of where it was when [start] was called (assuming no other input).
|
||||
void cancel() {
|
||||
if (timer?.isActive == true) {
|
||||
timer.cancel();
|
||||
// Many terminals do not interpret backspace as deleting a character,
|
||||
// but rather just moving the cursor back one.
|
||||
stdout.write('\b \b');
|
||||
}
|
||||
super.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructor writes [message] to [stdout] with padding, then starts as an
|
||||
/// [AnsiSpinner]. On [cancel] or [stop], will call [onFinish].
|
||||
/// On [stop], will additionally print out summary information in
|
||||
/// milliseconds if [expectSlowOperation] is false, as seconds otherwise.
|
||||
class AnsiStatus extends AnsiSpinner {
|
||||
AnsiStatus(this.message, this.expectSlowOperation, this.onFinish, this.padding);
|
||||
|
||||
final String message;
|
||||
final bool expectSlowOperation;
|
||||
final _FinishCallback onFinish;
|
||||
final int padding;
|
||||
|
||||
Stopwatch stopwatch;
|
||||
Timer timer;
|
||||
int index = 1;
|
||||
bool live = true;
|
||||
bool _finished = false;
|
||||
|
||||
void _callback(Timer timer) {
|
||||
stdout.write('\b${_progress[index]}');
|
||||
index = ++index % _progress.length;
|
||||
@override
|
||||
/// Writes [message] to [stdout] with padding, then begins spinning.
|
||||
void start() {
|
||||
stopwatch = new Stopwatch()..start();
|
||||
stdout.write('${message.padRight(padding)} ');
|
||||
assert(!_finished);
|
||||
super.start();
|
||||
}
|
||||
|
||||
@override
|
||||
/// Calls onFinish.
|
||||
void stop() {
|
||||
onFinish();
|
||||
|
||||
if (!live)
|
||||
return;
|
||||
live = false;
|
||||
|
||||
if (expectSlowOperation) {
|
||||
print('\b\b\b\b\b${getElapsedAsSeconds(stopwatch.elapsed).padLeft(5)}');
|
||||
} else {
|
||||
print('\b\b\b\b\b${getElapsedAsMilliseconds(stopwatch.elapsed).padLeft(5)}');
|
||||
if (!_finished) {
|
||||
onFinish();
|
||||
_finished = true;
|
||||
super.cancel();
|
||||
summaryInformation();
|
||||
}
|
||||
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
/// Backs up 4 characters and prints a (minimum) 5 character padded time. If
|
||||
/// [expectSlowOperation] is true, the time is in seconds; otherwise,
|
||||
/// milliseconds. Only backs up 4 characters because [super.cancel] backs
|
||||
/// up one.
|
||||
///
|
||||
/// Example: '\b\b\b\b 0.5s', '\b\b\b\b150ms', '\b\b\b\b1600ms'
|
||||
void summaryInformation() {
|
||||
if (expectSlowOperation) {
|
||||
stdout.writeln('\b\b\b\b${getElapsedAsSeconds(stopwatch.elapsed).padLeft(5)}');
|
||||
} else {
|
||||
stdout.writeln('\b\b\b\b${getElapsedAsMilliseconds(stopwatch.elapsed).padLeft(5)}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
/// Calls [onFinish].
|
||||
void cancel() {
|
||||
onFinish();
|
||||
|
||||
if (!live)
|
||||
return;
|
||||
live = false;
|
||||
|
||||
print('\b ');
|
||||
timer.cancel();
|
||||
if (!_finished) {
|
||||
onFinish();
|
||||
_finished = true;
|
||||
super.cancel();
|
||||
stdout.write('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ typedef String StringConverter(String string);
|
||||
typedef Future<dynamic> ShutdownHook();
|
||||
|
||||
// TODO(ianh): We have way too many ways to run subprocesses in this project.
|
||||
// Convert most of these into one or more lightweight wrappers around the
|
||||
// [ProcessManager] API using named parameters for the various options.
|
||||
// See [here](https://github.com/flutter/flutter/pull/14535#discussion_r167041161)
|
||||
// for more details.
|
||||
|
||||
/// The stage in which a [ShutdownHook] will be run. All shutdown hooks within
|
||||
/// a given stage will be started in parallel and will be guaranteed to run to
|
||||
|
||||
@@ -764,7 +764,7 @@ class NotifyingLogger extends Logger {
|
||||
String message, {
|
||||
String progressId,
|
||||
bool expectSlowOperation: false,
|
||||
int progressIndicatorPadding: 52,
|
||||
int progressIndicatorPadding: kDefaultStatusPadding,
|
||||
}) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
@@ -906,13 +906,16 @@ class _AppRunLogger extends Logger {
|
||||
}
|
||||
}
|
||||
|
||||
class _AppLoggerStatus implements Status {
|
||||
class _AppLoggerStatus extends Status {
|
||||
_AppLoggerStatus(this.logger, this.id, this.progressId);
|
||||
|
||||
final _AppRunLogger logger;
|
||||
final int id;
|
||||
final String progressId;
|
||||
|
||||
@override
|
||||
void start() {}
|
||||
|
||||
@override
|
||||
void stop() {
|
||||
logger._status = null;
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'artifacts.dart';
|
||||
import 'base/common.dart';
|
||||
import 'base/context.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/os.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process_manager.dart';
|
||||
@@ -27,6 +28,12 @@ import 'vscode/vscode_validator.dart';
|
||||
|
||||
Doctor get doctor => context[Doctor];
|
||||
|
||||
class ValidatorTask {
|
||||
ValidatorTask(this.validator, this.result);
|
||||
final DoctorValidator validator;
|
||||
final Future<ValidationResult> result;
|
||||
}
|
||||
|
||||
class Doctor {
|
||||
List<DoctorValidator> _validators;
|
||||
|
||||
@@ -56,6 +63,16 @@ class Doctor {
|
||||
return _validators;
|
||||
}
|
||||
|
||||
/// Return a list of [ValidatorTask] objects and starts validation on all
|
||||
/// objects in [validators].
|
||||
List<ValidatorTask> startValidatorTasks() {
|
||||
final List<ValidatorTask> tasks = <ValidatorTask>[];
|
||||
for (DoctorValidator validator in validators) {
|
||||
tasks.add(new ValidatorTask(validator, validator.validate()));
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
|
||||
List<Workflow> get workflows {
|
||||
return new List<Workflow>.from(validators.where((DoctorValidator validator) => validator is Workflow));
|
||||
}
|
||||
@@ -108,9 +125,14 @@ class Doctor {
|
||||
bool doctorResult = true;
|
||||
int issues = 0;
|
||||
|
||||
for (DoctorValidator validator in validators) {
|
||||
final ValidationResult result = await validator.validate();
|
||||
for (ValidatorTask validatorTask in startValidatorTasks()) {
|
||||
final DoctorValidator validator = validatorTask.validator;
|
||||
final Status status = new Status.withSpinner();
|
||||
await (validatorTask.result).then<void>((_) {
|
||||
status.stop();
|
||||
}).whenComplete(status.cancel);
|
||||
|
||||
final ValidationResult result = await validatorTask.result;
|
||||
if (result.type == ValidationType.missing) {
|
||||
doctorResult = false;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
buildSubStatus = logger.startProgress(
|
||||
line,
|
||||
expectSlowOperation: true,
|
||||
progressIndicatorPadding: 45,
|
||||
progressIndicatorPadding: kDefaultStatusPadding - 7,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
scriptOutputPipeTempDirectory?.deleteSync(recursive: true);
|
||||
printStatus(
|
||||
'Xcode build done',
|
||||
ansiAlternative: 'Xcode build done'.padRight(53)
|
||||
ansiAlternative: 'Xcode build done'.padRight(kDefaultStatusPadding + 1)
|
||||
+ '${getElapsedAsSeconds(buildStopwatch.elapsed).padLeft(5)}',
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user