forked from firka/flutter
Declare locals as final where not reassigned (dev) (#8574)
This commit is contained in:
@@ -118,7 +118,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
/// [workingDevice].
|
||||
@override
|
||||
Future<Null> chooseWorkingDevice() async {
|
||||
List<Device> allDevices = (await discoverDevices())
|
||||
final List<Device> allDevices = (await discoverDevices())
|
||||
.map((String id) => new AndroidDevice(deviceId: id))
|
||||
.toList();
|
||||
|
||||
@@ -131,9 +131,9 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<List<String>> discoverDevices() async {
|
||||
List<String> output = (await eval(adbPath, <String>['devices', '-l'], canFail: false))
|
||||
final List<String> output = (await eval(adbPath, <String>['devices', '-l'], canFail: false))
|
||||
.trim().split('\n');
|
||||
List<String> results = <String>[];
|
||||
final List<String> results = <String>[];
|
||||
for (String line in output) {
|
||||
// Skip lines like: * daemon started successfully *
|
||||
if (line.startsWith('* daemon '))
|
||||
@@ -143,10 +143,10 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
continue;
|
||||
|
||||
if (_kDeviceRegex.hasMatch(line)) {
|
||||
Match match = _kDeviceRegex.firstMatch(line);
|
||||
final Match match = _kDeviceRegex.firstMatch(line);
|
||||
|
||||
String deviceID = match[1];
|
||||
String deviceState = match[2];
|
||||
final String deviceID = match[1];
|
||||
final String deviceState = match[2];
|
||||
|
||||
if (!const <String>['unauthorized', 'offline'].contains(deviceState)) {
|
||||
results.add(deviceID);
|
||||
@@ -161,10 +161,10 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<Map<String, HealthCheckResult>> checkDevices() async {
|
||||
Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
for (String deviceId in await discoverDevices()) {
|
||||
try {
|
||||
AndroidDevice device = new AndroidDevice(deviceId: deviceId);
|
||||
final AndroidDevice device = new AndroidDevice(deviceId: deviceId);
|
||||
// Just a smoke test that we can read wakefulness state
|
||||
// TODO(yjbanov): check battery level
|
||||
await device._getWakefulness();
|
||||
@@ -240,8 +240,8 @@ class AndroidDevice implements Device {
|
||||
///
|
||||
/// See: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/PowerManagerInternal.java
|
||||
Future<String> _getWakefulness() async {
|
||||
String powerInfo = await shellEval('dumpsys', <String>['power']);
|
||||
String wakefulness = grep('mWakefulness=', from: powerInfo).single.split('=')[1].trim();
|
||||
final String powerInfo = await shellEval('dumpsys', <String>['power']);
|
||||
final String wakefulness = grep('mWakefulness=', from: powerInfo).single.split('=')[1].trim();
|
||||
return wakefulness;
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ class AndroidDevice implements Device {
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
|
||||
String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
|
||||
Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
|
||||
final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
|
||||
final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
|
||||
return <String, dynamic>{
|
||||
'total_kb': int.parse(match.group(1)),
|
||||
};
|
||||
@@ -295,7 +295,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
/// [workingDevice].
|
||||
@override
|
||||
Future<Null> chooseWorkingDevice() async {
|
||||
List<IosDevice> allDevices = (await discoverDevices())
|
||||
final List<IosDevice> allDevices = (await discoverDevices())
|
||||
.map((String id) => new IosDevice(deviceId: id))
|
||||
.toList();
|
||||
|
||||
@@ -309,7 +309,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
@override
|
||||
Future<List<String>> discoverDevices() async {
|
||||
// TODO: use the -k UniqueDeviceID option, which requires much less parsing.
|
||||
List<String> iosDeviceIds = grep('UniqueDeviceID', from: await eval('ideviceinfo', <String>[]))
|
||||
final List<String> iosDeviceIds = grep('UniqueDeviceID', from: await eval('ideviceinfo', <String>[]))
|
||||
.map((String line) => line.split(' ').last).toList();
|
||||
|
||||
if (iosDeviceIds.isEmpty)
|
||||
@@ -320,7 +320,7 @@ class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
|
||||
@override
|
||||
Future<Map<String, HealthCheckResult>> checkDevices() async {
|
||||
Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
|
||||
for (String deviceId in await discoverDevices()) {
|
||||
// TODO: do a more meaningful connectivity check than just recording the ID
|
||||
results['ios-device-$deviceId'] = new HealthCheckResult.success();
|
||||
@@ -376,13 +376,13 @@ class IosDevice implements Device {
|
||||
|
||||
/// Path to the `adb` executable.
|
||||
String get adbPath {
|
||||
String androidHome = Platform.environment['ANDROID_HOME'];
|
||||
final String androidHome = Platform.environment['ANDROID_HOME'];
|
||||
|
||||
if (androidHome == null)
|
||||
throw 'ANDROID_HOME environment variable missing. This variable must '
|
||||
'point to the Android SDK directory containing platform-tools.';
|
||||
|
||||
File adbPath = file(path.join(androidHome, 'platform-tools/adb'));
|
||||
final File adbPath = file(path.join(androidHome, 'platform-tools/adb'));
|
||||
|
||||
if (!adbPath.existsSync()) throw 'adb not found at: $adbPath';
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Future<num> runBenchmark(Benchmark benchmark, {
|
||||
}) async {
|
||||
await benchmark.init();
|
||||
|
||||
List<num> allRuns = <num>[];
|
||||
final List<num> allRuns = <num>[];
|
||||
|
||||
num minValue;
|
||||
|
||||
@@ -46,7 +46,7 @@ Future<num> runBenchmark(Benchmark benchmark, {
|
||||
print('');
|
||||
|
||||
try {
|
||||
num result = await benchmark.run();
|
||||
final num result = await benchmark.run();
|
||||
allRuns.add(result);
|
||||
|
||||
if (minValue == null || result < minValue) {
|
||||
|
||||
@@ -43,7 +43,7 @@ Future<TaskResult> task(TaskFunction task) {
|
||||
print('${rec.level.name}: ${rec.time}: ${rec.message}');
|
||||
});
|
||||
|
||||
_TaskRunner runner = new _TaskRunner(task);
|
||||
final _TaskRunner runner = new _TaskRunner(task);
|
||||
runner.keepVmAliveUntilTaskRunRequested();
|
||||
return runner.whenDone;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class _TaskRunner {
|
||||
_TaskRunner(this.task) {
|
||||
registerExtension('ext.cocoonRunTask',
|
||||
(String method, Map<String, String> parameters) async {
|
||||
TaskResult result = await run();
|
||||
final TaskResult result = await run();
|
||||
return new ServiceExtensionResponse.result(JSON.encode(result.toJson()));
|
||||
});
|
||||
registerExtension('ext.cocoonRunnerReady',
|
||||
@@ -78,7 +78,7 @@ class _TaskRunner {
|
||||
Future<TaskResult> run() async {
|
||||
try {
|
||||
_taskStarted = true;
|
||||
TaskResult result = await _performTask().timeout(taskTimeout);
|
||||
final TaskResult result = await _performTask().timeout(taskTimeout);
|
||||
_completer.complete(result);
|
||||
return result;
|
||||
} on TimeoutException catch (_) {
|
||||
@@ -117,11 +117,11 @@ class _TaskRunner {
|
||||
}
|
||||
|
||||
Future<TaskResult> _performTask() {
|
||||
Completer<TaskResult> completer = new Completer<TaskResult>();
|
||||
final Completer<TaskResult> completer = new Completer<TaskResult>();
|
||||
Chain.capture(() async {
|
||||
completer.complete(await task());
|
||||
}, onError: (dynamic taskError, Chain taskErrorStack) {
|
||||
String message = 'Task failed: $taskError';
|
||||
final String message = 'Task failed: $taskError';
|
||||
stderr
|
||||
..writeln(message)
|
||||
..writeln('\nStack trace:')
|
||||
@@ -210,7 +210,7 @@ class TaskResult {
|
||||
/// "reason": failure reason string valid only for unsuccessful results
|
||||
/// }
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> json = <String, dynamic>{
|
||||
final Map<String, dynamic> json = <String, dynamic>{
|
||||
'success': succeeded,
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'utils.dart';
|
||||
|
||||
/// Loads manifest data from `manifest.yaml` file or from [yaml], if present.
|
||||
Manifest loadTaskManifest([ String yaml ]) {
|
||||
dynamic manifestYaml = yaml == null
|
||||
final dynamic manifestYaml = yaml == null
|
||||
? loadYaml(file('manifest.yaml').readAsStringSync())
|
||||
: loadYamlNode(yaml);
|
||||
|
||||
@@ -33,7 +33,7 @@ class ManifestTask {
|
||||
@required this.stage,
|
||||
@required this.requiredAgentCapabilities,
|
||||
}) {
|
||||
String taskName = 'task "$name"';
|
||||
final String taskName = 'task "$name"';
|
||||
_checkIsNotBlank(name, 'Task name', taskName);
|
||||
_checkIsNotBlank(description, 'Task description', taskName);
|
||||
_checkIsNotBlank(stage, 'Task stage', taskName);
|
||||
@@ -84,7 +84,7 @@ ManifestTask _validateAndParseTask(dynamic taskName, dynamic taskYaml) {
|
||||
'required_agent_capabilities',
|
||||
]);
|
||||
|
||||
List<String> capabilities = _validateAndParseCapabilities(taskName, taskYaml['required_agent_capabilities']);
|
||||
final List<String> capabilities = _validateAndParseCapabilities(taskName, taskYaml['required_agent_capabilities']);
|
||||
return new ManifestTask._(
|
||||
name: taskName,
|
||||
description: taskYaml['description'],
|
||||
@@ -96,7 +96,7 @@ ManifestTask _validateAndParseTask(dynamic taskName, dynamic taskYaml) {
|
||||
List<String> _validateAndParseCapabilities(String taskName, dynamic capabilitiesYaml) {
|
||||
_checkType(capabilitiesYaml is List, capabilitiesYaml, 'required_agent_capabilities', 'list');
|
||||
for (int i = 0; i < capabilitiesYaml.length; i++) {
|
||||
dynamic capability = capabilitiesYaml[i];
|
||||
final dynamic capability = capabilitiesYaml[i];
|
||||
_checkType(capability is String, capability, 'required_agent_capabilities[$i]', 'string');
|
||||
}
|
||||
return capabilitiesYaml;
|
||||
|
||||
@@ -23,13 +23,13 @@ const Duration taskTimeoutWithGracePeriod = const Duration(minutes: 11);
|
||||
/// Running the task in [silent] mode will suppress standard output from task
|
||||
/// processes and only print standard errors.
|
||||
Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) async {
|
||||
String taskExecutable = 'bin/tasks/$taskName.dart';
|
||||
final String taskExecutable = 'bin/tasks/$taskName.dart';
|
||||
|
||||
if (!file(taskExecutable).existsSync())
|
||||
throw 'Executable Dart file not found: $taskExecutable';
|
||||
|
||||
int vmServicePort = await findAvailablePort();
|
||||
Process runner = await startProcess(dartBin, <String>[
|
||||
final int vmServicePort = await findAvailablePort();
|
||||
final Process runner = await startProcess(dartBin, <String>[
|
||||
'--enable-vm-service=$vmServicePort',
|
||||
'--no-pause-isolates-on-exit',
|
||||
taskExecutable,
|
||||
@@ -41,7 +41,7 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
runnerFinished = true;
|
||||
});
|
||||
|
||||
StreamSubscription<String> stdoutSub = runner.stdout
|
||||
final StreamSubscription<String> stdoutSub = runner.stdout
|
||||
.transform(const Utf8Decoder())
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
@@ -50,7 +50,7 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
}
|
||||
});
|
||||
|
||||
StreamSubscription<String> stderrSub = runner.stderr
|
||||
final StreamSubscription<String> stderrSub = runner.stderr
|
||||
.transform(const Utf8Decoder())
|
||||
.transform(const LineSplitter())
|
||||
.listen((String line) {
|
||||
@@ -59,9 +59,9 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
|
||||
String waitingFor = 'connection';
|
||||
try {
|
||||
VMIsolateRef isolate = await _connectToRunnerIsolate(vmServicePort);
|
||||
final VMIsolateRef isolate = await _connectToRunnerIsolate(vmServicePort);
|
||||
waitingFor = 'task completion';
|
||||
Map<String, dynamic> taskResult =
|
||||
final Map<String, dynamic> taskResult =
|
||||
await isolate.invokeExtension('ext.cocoonRunTask').timeout(taskTimeoutWithGracePeriod);
|
||||
waitingFor = 'task process to exit';
|
||||
await runner.exitCode.timeout(const Duration(seconds: 1));
|
||||
@@ -81,8 +81,8 @@ Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) as
|
||||
}
|
||||
|
||||
Future<VMIsolateRef> _connectToRunnerIsolate(int vmServicePort) async {
|
||||
String url = 'ws://localhost:$vmServicePort/ws';
|
||||
DateTime started = new DateTime.now();
|
||||
final String url = 'ws://localhost:$vmServicePort/ws';
|
||||
final DateTime started = new DateTime.now();
|
||||
|
||||
// TODO(yjbanov): due to lack of imagination at the moment the handshake with
|
||||
// the task process is very rudimentary and requires this small
|
||||
@@ -97,10 +97,10 @@ Future<VMIsolateRef> _connectToRunnerIsolate(int vmServicePort) async {
|
||||
await (await WebSocket.connect(url)).close();
|
||||
|
||||
// Look up the isolate.
|
||||
VMServiceClient client = new VMServiceClient.connect(url);
|
||||
VM vm = await client.getVM();
|
||||
VMIsolateRef isolate = vm.isolates.single;
|
||||
String response = await isolate.invokeExtension('ext.cocoonRunnerReady');
|
||||
final VMServiceClient client = new VMServiceClient.connect(url);
|
||||
final VM vm = await client.getVM();
|
||||
final VMIsolateRef isolate = vm.isolates.single;
|
||||
final String response = await isolate.invokeExtension('ext.cocoonRunnerReady');
|
||||
if (response != 'ready') throw 'not ready yet';
|
||||
return isolate;
|
||||
} catch (error) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class HealthCheckResult {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
StringBuffer buf = new StringBuffer(succeeded ? 'succeeded' : 'failed');
|
||||
final StringBuffer buf = new StringBuffer(succeeded ? 'succeeded' : 'failed');
|
||||
if (details != null && details.trim().isNotEmpty) {
|
||||
buf.writeln();
|
||||
// Indent details by 4 spaces
|
||||
@@ -89,7 +89,7 @@ Directory dir(String path) => new Directory(path);
|
||||
File file(String path) => new File(path);
|
||||
|
||||
void copy(File sourceFile, Directory targetDirectory, {String name}) {
|
||||
File target = file(
|
||||
final File target = file(
|
||||
path.join(targetDirectory.path, name ?? path.basename(sourceFile.path)));
|
||||
target.writeAsBytesSync(sourceFile.readAsBytesSync());
|
||||
}
|
||||
@@ -118,7 +118,7 @@ void section(String title) {
|
||||
|
||||
Future<String> getDartVersion() async {
|
||||
// The Dart VM returns the version text to stderr.
|
||||
ProcessResult result = Process.runSync(dartBin, <String>['--version']);
|
||||
final ProcessResult result = Process.runSync(dartBin, <String>['--version']);
|
||||
String version = result.stderr.trim();
|
||||
|
||||
// Convert:
|
||||
@@ -146,13 +146,13 @@ Future<String> getCurrentFlutterRepoCommit() {
|
||||
Future<DateTime> getFlutterRepoCommitTimestamp(String commit) {
|
||||
// git show -s --format=%at 4b546df7f0b3858aaaa56c4079e5be1ba91fbb65
|
||||
return inDirectory(flutterDirectory, () async {
|
||||
String unixTimestamp = await eval('git', <String>[
|
||||
final String unixTimestamp = await eval('git', <String>[
|
||||
'show',
|
||||
'-s',
|
||||
'--format=%at',
|
||||
commit,
|
||||
]);
|
||||
int secondsSinceEpoch = int.parse(unixTimestamp);
|
||||
final int secondsSinceEpoch = int.parse(unixTimestamp);
|
||||
return new DateTime.fromMillisecondsSinceEpoch(secondsSinceEpoch * 1000);
|
||||
});
|
||||
}
|
||||
@@ -163,17 +163,17 @@ Future<Process> startProcess(
|
||||
Map<String, String> environment,
|
||||
String workingDirectory,
|
||||
}) async {
|
||||
String command = '$executable ${arguments?.join(" ") ?? ""}';
|
||||
final String command = '$executable ${arguments?.join(" ") ?? ""}';
|
||||
print('Executing: $command');
|
||||
environment ??= <String, String>{};
|
||||
environment['BOT'] = 'true';
|
||||
Process process = await Process.start(
|
||||
final Process process = await Process.start(
|
||||
executable,
|
||||
arguments,
|
||||
environment: environment,
|
||||
workingDirectory: workingDirectory ?? cwd,
|
||||
);
|
||||
ProcessInfo processInfo = new ProcessInfo(command, process);
|
||||
final ProcessInfo processInfo = new ProcessInfo(command, process);
|
||||
_runningProcesses.add(processInfo);
|
||||
|
||||
process.exitCode.whenComplete(() {
|
||||
@@ -207,7 +207,7 @@ Future<int> exec(
|
||||
Map<String, String> environment,
|
||||
bool canFail: false,
|
||||
}) async {
|
||||
Process process = await startProcess(executable, arguments, environment: environment);
|
||||
final Process process = await startProcess(executable, arguments, environment: environment);
|
||||
|
||||
process.stdout
|
||||
.transform(UTF8.decoder)
|
||||
@@ -218,7 +218,7 @@ Future<int> exec(
|
||||
.transform(const LineSplitter())
|
||||
.listen(stderr.writeln);
|
||||
|
||||
int exitCode = await process.exitCode;
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable failed with exit code $exitCode.');
|
||||
@@ -235,12 +235,12 @@ Future<String> eval(
|
||||
Map<String, String> environment,
|
||||
bool canFail: false,
|
||||
}) async {
|
||||
Process process = await startProcess(executable, arguments, environment: environment);
|
||||
final Process process = await startProcess(executable, arguments, environment: environment);
|
||||
process.stderr.listen((List<int> data) {
|
||||
stderr.add(data);
|
||||
});
|
||||
String output = await UTF8.decodeStream(process.stdout);
|
||||
int exitCode = await process.exitCode;
|
||||
final String output = await UTF8.decodeStream(process.stdout);
|
||||
final int exitCode = await process.exitCode;
|
||||
|
||||
if (exitCode != 0 && !canFail)
|
||||
fail('Executable failed with exit code $exitCode.');
|
||||
@@ -253,7 +253,7 @@ Future<int> flutter(String command, {
|
||||
bool canFail: false,
|
||||
Map<String, String> environment,
|
||||
}) {
|
||||
List<String> args = <String>[command]..addAll(options);
|
||||
final List<String> args = <String>[command]..addAll(options);
|
||||
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ Future<String> evalFlutter(String command, {
|
||||
bool canFail: false,
|
||||
Map<String, String> environment,
|
||||
}) {
|
||||
List<String> args = <String>[command]..addAll(options);
|
||||
final List<String> args = <String>[command]..addAll(options);
|
||||
return eval(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ String get dartBin =>
|
||||
Future<int> dart(List<String> args) => exec(dartBin, args);
|
||||
|
||||
Future<dynamic> inDirectory(dynamic directory, Future<dynamic> action()) async {
|
||||
String previousCwd = cwd;
|
||||
final String previousCwd = cwd;
|
||||
try {
|
||||
cd(directory);
|
||||
return await action();
|
||||
@@ -303,7 +303,7 @@ void cd(dynamic directory) {
|
||||
Directory get flutterDirectory => dir('../..').absolute;
|
||||
|
||||
String requireEnvVar(String name) {
|
||||
String value = Platform.environment[name];
|
||||
final String value = Platform.environment[name];
|
||||
|
||||
if (value == null) fail('$name environment variable is missing. Quitting.');
|
||||
|
||||
@@ -313,7 +313,7 @@ String requireEnvVar(String name) {
|
||||
T requireConfigProperty<T>(Map<String, dynamic> map, String propertyName) {
|
||||
if (!map.containsKey(propertyName))
|
||||
fail('Configuration property not found: $propertyName');
|
||||
T result = map[propertyName];
|
||||
final T result = map[propertyName];
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ Iterable<String> grep(Pattern pattern, {@required String from}) {
|
||||
///
|
||||
/// }
|
||||
Future<Null> runAndCaptureAsyncStacks(Future<Null> callback()) {
|
||||
Completer<Null> completer = new Completer<Null>();
|
||||
final Completer<Null> completer = new Completer<Null>();
|
||||
Chain.capture(() async {
|
||||
await callback();
|
||||
completer.complete();
|
||||
@@ -441,7 +441,7 @@ Future<int> findAvailablePort() async {
|
||||
int port = 20000;
|
||||
while (true) {
|
||||
try {
|
||||
ServerSocket socket =
|
||||
final ServerSocket socket =
|
||||
await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, port);
|
||||
await socket.close();
|
||||
return port;
|
||||
|
||||
Reference in New Issue
Block a user