Commit d911aaa6 authored by Devon Carew's avatar Devon Carew

refactot the stop command to not use DeviceStore

parent 59664e4f
......@@ -340,6 +340,7 @@ linter:
printTrace(file);
}
printTrace(cmd.join(' '));
Process process = await Process.start(
cmd[0],
cmd.sublist(1),
......
......@@ -449,8 +449,7 @@ Future<int> buildAll(
"consider renaming your 'apk/' directory to 'android/'.");
}
int result = await build(toolchain, configs, enginePath: enginePath,
target: target);
int result = await build(toolchain, configs, enginePath: enginePath, target: target);
if (result != 0)
return result;
}
......
......@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io';
import '../android/android_device.dart';
import '../application_package.dart';
import '../base/context.dart';
import '../base/logger.dart';
import '../device.dart';
......@@ -15,7 +16,6 @@ import '../ios/devices.dart';
import '../ios/simulators.dart';
import '../runner/flutter_command.dart';
import 'run.dart';
import 'stop.dart' as stop;
const String protocolVersion = '0.1.0';
......@@ -78,9 +78,9 @@ class Daemon {
this.notifyingLogger
}) {
// Set up domains.
_registerDomain(new DaemonDomain(this));
_registerDomain(new AppDomain(this));
_registerDomain(new DeviceDomain(this));
_registerDomain(daemonDomain = new DaemonDomain(this));
_registerDomain(appDomain = new AppDomain(this));
_registerDomain(deviceDomain = new DeviceDomain(this));
// Start listening.
commandStream.listen(
......@@ -89,6 +89,10 @@ class Daemon {
);
}
DaemonDomain daemonDomain;
AppDomain appDomain;
DeviceDomain deviceDomain;
final DispatchComand sendCommand;
final DaemonCommand daemonCommand;
final NotifyingLogger notifyingLogger;
......@@ -221,29 +225,30 @@ class DaemonDomain extends Domain {
}
}
/// This domain responds to methods like [start] and [stopAll].
/// This domain responds to methods like [start] and [stop].
///
/// It'll be extended to fire events for when applications start, stop, and
/// log data.
class AppDomain extends Domain {
AppDomain(Daemon daemon) : super(daemon, 'app') {
registerHandler('start', start);
registerHandler('stopAll', stopAll);
registerHandler('stop', stop);
}
Future<dynamic> start(Map<String, dynamic> args) async {
// TODO(devoncarew): We need to be able to specify the target device.
if (args['deviceId'] is! String)
throw "A 'deviceId' is required";
Device device = await _getDevice(args['deviceId']);
if (device == null)
throw "A 'projectDirectory' is required";
if (args['projectDirectory'] is! String)
throw "A 'projectDirectory' is required";
String projectDirectory = args['projectDirectory'];
if (!FileSystemEntity.isDirectorySync(projectDirectory))
throw "The '$projectDirectory' does not exist";
// We change the current working directory for the duration of the `start`
// command. This would have race conditions with other commands happening in
// parallel and doesn't play well with the caching built into `FlutterCommand`.
// We change the current working directory for the duration of the `start` command.
// TODO(devoncarew): Make flutter_tools work better with commands run from any directory.
Directory cwd = Directory.current;
Directory.current = new Directory(projectDirectory);
......@@ -259,6 +264,7 @@ class AppDomain extends Domain {
command.applicationPackages,
command.toolchain,
command.buildConfigurations,
stop: true,
target: args['target'],
route: args['route'],
checked: args['checked'] ?? true
......@@ -273,8 +279,38 @@ class AppDomain extends Domain {
return null;
}
Future<bool> stopAll(dynamic args) {
return stop.stopAll(command.devices, command.applicationPackages);
Future<bool> stop(dynamic args) async {
if (args['deviceId'] is! String)
throw "A 'deviceId' is required";
Device device = await _getDevice(args['deviceId']);
if (device == null)
throw "A 'projectDirectory' is required";
if (args['projectDirectory'] is! String)
throw "A 'projectDirectory' is required";
String projectDirectory = args['projectDirectory'];
if (!FileSystemEntity.isDirectorySync(projectDirectory))
throw "The '$projectDirectory' does not exist";
Directory cwd = Directory.current;
Directory.current = new Directory(projectDirectory);
try {
await Future.wait([
command.downloadToolchain(),
command.downloadApplicationPackages(),
], eagerError: true);
ApplicationPackage app = command.applicationPackages.getPackageForPlatform(device.platform);
return device.stopApp(app);
} finally {
Directory.current = cwd;
}
}
Future<Device> _getDevice(String deviceId) async {
List<Device> devices = await daemon.deviceDomain.getDevices();
return devices.firstWhere((Device device) => device.id == deviceId, orElse: () => null);
}
}
......@@ -312,7 +348,7 @@ class DeviceDomain extends Domain {
List<PollingDeviceDiscovery> _discoverers = <PollingDeviceDiscovery>[];
Future<List<Device>> getDevices(dynamic args) {
Future<List<Device>> getDevices([dynamic args]) {
List<Device> devices = _discoverers.expand((PollingDeviceDiscovery discoverer) {
return discoverer.devices;
}).toList();
......
......@@ -7,17 +7,16 @@ import 'dart:async';
import 'package:path/path.dart' as path;
import 'package:test/src/executable.dart' as executable;
import '../android/android_device.dart' show AndroidDevice;
import '../application_package.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/os.dart';
import '../device.dart';
import '../globals.dart';
import '../ios/simulators.dart' show SimControl, IOSSimulatorUtils;
import '../android/android_device.dart' show AndroidDevice;
import '../application_package.dart';
import 'apk.dart' as apk;
import 'run.dart';
import 'stop.dart';
/// Runs integration (a.k.a. end-to-end) tests.
///
......@@ -126,10 +125,6 @@ class DriveCommand extends RunCommandBase {
}
}
Future<int> stop() async {
return await stopAll(devices, applicationPackages) ? 0 : 2;
}
String _getTestFile() {
String appFile = path.normalize(target);
......
......@@ -6,31 +6,21 @@ import 'dart:async';
import '../application_package.dart';
import '../device.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
class StopCommand extends FlutterCommand {
final String name = 'stop';
final String description = 'Stop your Flutter app on all attached devices.';
final String description = 'Stop your Flutter app on an attached device.';
bool get requiresDevice => true;
@override
Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices();
return await stop() ? 0 : 2;
await downloadApplicationPackages();
Device device = deviceForCommand;
ApplicationPackage app = applicationPackages.getPackageForPlatform(device.platform);
printStatus('Stopping apps on ${device.name}.');
return await device.stopApp(app) ? 0 : 1;
}
Future<bool> stop() => stopAll(devices, applicationPackages);
}
Future<bool> stopAll(DeviceStore devices, ApplicationPackageStore applicationPackages) async {
bool stoppedSomething = false;
for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null)
continue;
if (await device.stopApp(package))
stoppedSomething = true;
}
return stoppedSomething;
}
......@@ -35,11 +35,11 @@ abstract class FlutterCommand extends Command {
}
Future downloadApplicationPackagesAndConnectToDevices() async {
await _downloadApplicationPackages();
await downloadApplicationPackages();
_connectToDevices();
}
Future _downloadApplicationPackages() async {
Future downloadApplicationPackages() async {
applicationPackages ??= await ApplicationPackageStore.forConfigs(buildConfigurations);
}
......
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