Merge pull request #2378 from devoncarew/refactor_stop
refactor the stop command to not use DeviceStore
This commit is contained in:
commit
e1f476b6d0
@ -340,6 +340,7 @@ linter:
|
|||||||
printTrace(file);
|
printTrace(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printTrace(cmd.join(' '));
|
||||||
Process process = await Process.start(
|
Process process = await Process.start(
|
||||||
cmd[0],
|
cmd[0],
|
||||||
cmd.sublist(1),
|
cmd.sublist(1),
|
||||||
|
@ -449,8 +449,7 @@ Future<int> buildAll(
|
|||||||
"consider renaming your 'apk/' directory to 'android/'.");
|
"consider renaming your 'apk/' directory to 'android/'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = await build(toolchain, configs, enginePath: enginePath,
|
int result = await build(toolchain, configs, enginePath: enginePath, target: target);
|
||||||
target: target);
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import 'dart:convert';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import '../android/android_device.dart';
|
import '../android/android_device.dart';
|
||||||
|
import '../application_package.dart';
|
||||||
import '../base/context.dart';
|
import '../base/context.dart';
|
||||||
import '../base/logger.dart';
|
import '../base/logger.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
@ -15,7 +16,6 @@ import '../ios/devices.dart';
|
|||||||
import '../ios/simulators.dart';
|
import '../ios/simulators.dart';
|
||||||
import '../runner/flutter_command.dart';
|
import '../runner/flutter_command.dart';
|
||||||
import 'run.dart';
|
import 'run.dart';
|
||||||
import 'stop.dart' as stop;
|
|
||||||
|
|
||||||
const String protocolVersion = '0.1.0';
|
const String protocolVersion = '0.1.0';
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ class Daemon {
|
|||||||
this.notifyingLogger
|
this.notifyingLogger
|
||||||
}) {
|
}) {
|
||||||
// Set up domains.
|
// Set up domains.
|
||||||
_registerDomain(new DaemonDomain(this));
|
_registerDomain(daemonDomain = new DaemonDomain(this));
|
||||||
_registerDomain(new AppDomain(this));
|
_registerDomain(appDomain = new AppDomain(this));
|
||||||
_registerDomain(new DeviceDomain(this));
|
_registerDomain(deviceDomain = new DeviceDomain(this));
|
||||||
|
|
||||||
// Start listening.
|
// Start listening.
|
||||||
commandStream.listen(
|
commandStream.listen(
|
||||||
@ -89,6 +89,10 @@ class Daemon {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DaemonDomain daemonDomain;
|
||||||
|
AppDomain appDomain;
|
||||||
|
DeviceDomain deviceDomain;
|
||||||
|
|
||||||
final DispatchComand sendCommand;
|
final DispatchComand sendCommand;
|
||||||
final DaemonCommand daemonCommand;
|
final DaemonCommand daemonCommand;
|
||||||
final NotifyingLogger notifyingLogger;
|
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
|
/// It'll be extended to fire events for when applications start, stop, and
|
||||||
/// log data.
|
/// log data.
|
||||||
class AppDomain extends Domain {
|
class AppDomain extends Domain {
|
||||||
AppDomain(Daemon daemon) : super(daemon, 'app') {
|
AppDomain(Daemon daemon) : super(daemon, 'app') {
|
||||||
registerHandler('start', start);
|
registerHandler('start', start);
|
||||||
registerHandler('stopAll', stopAll);
|
registerHandler('stop', stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> start(Map<String, dynamic> args) async {
|
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)
|
if (args['projectDirectory'] is! String)
|
||||||
throw "A 'projectDirectory' is required";
|
throw "A 'projectDirectory' is required";
|
||||||
|
|
||||||
String projectDirectory = args['projectDirectory'];
|
String projectDirectory = args['projectDirectory'];
|
||||||
if (!FileSystemEntity.isDirectorySync(projectDirectory))
|
if (!FileSystemEntity.isDirectorySync(projectDirectory))
|
||||||
throw "The '$projectDirectory' does not exist";
|
throw "The '$projectDirectory' does not exist";
|
||||||
|
|
||||||
// We change the current working directory for the duration of the `start`
|
// We change the current working directory for the duration of the `start` command.
|
||||||
// command. This would have race conditions with other commands happening in
|
|
||||||
// parallel and doesn't play well with the caching built into `FlutterCommand`.
|
|
||||||
// TODO(devoncarew): Make flutter_tools work better with commands run from any directory.
|
// TODO(devoncarew): Make flutter_tools work better with commands run from any directory.
|
||||||
Directory cwd = Directory.current;
|
Directory cwd = Directory.current;
|
||||||
Directory.current = new Directory(projectDirectory);
|
Directory.current = new Directory(projectDirectory);
|
||||||
@ -259,6 +264,7 @@ class AppDomain extends Domain {
|
|||||||
command.applicationPackages,
|
command.applicationPackages,
|
||||||
command.toolchain,
|
command.toolchain,
|
||||||
command.buildConfigurations,
|
command.buildConfigurations,
|
||||||
|
stop: true,
|
||||||
target: args['target'],
|
target: args['target'],
|
||||||
route: args['route'],
|
route: args['route'],
|
||||||
checked: args['checked'] ?? true
|
checked: args['checked'] ?? true
|
||||||
@ -273,8 +279,38 @@ class AppDomain extends Domain {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> stopAll(dynamic args) {
|
Future<bool> stop(dynamic args) async {
|
||||||
return stop.stopAll(command.devices, command.applicationPackages);
|
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>[];
|
List<PollingDeviceDiscovery> _discoverers = <PollingDeviceDiscovery>[];
|
||||||
|
|
||||||
Future<List<Device>> getDevices(dynamic args) {
|
Future<List<Device>> getDevices([dynamic args]) {
|
||||||
List<Device> devices = _discoverers.expand((PollingDeviceDiscovery discoverer) {
|
List<Device> devices = _discoverers.expand((PollingDeviceDiscovery discoverer) {
|
||||||
return discoverer.devices;
|
return discoverer.devices;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
@ -7,17 +7,16 @@ import 'dart:async';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:test/src/executable.dart' as executable;
|
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/common.dart';
|
||||||
import '../base/file_system.dart';
|
import '../base/file_system.dart';
|
||||||
import '../base/os.dart';
|
import '../base/os.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../ios/simulators.dart' show SimControl, IOSSimulatorUtils;
|
import '../ios/simulators.dart' show SimControl, IOSSimulatorUtils;
|
||||||
import '../android/android_device.dart' show AndroidDevice;
|
|
||||||
import '../application_package.dart';
|
|
||||||
import 'apk.dart' as apk;
|
import 'apk.dart' as apk;
|
||||||
import 'run.dart';
|
import 'run.dart';
|
||||||
import 'stop.dart';
|
|
||||||
|
|
||||||
/// Runs integration (a.k.a. end-to-end) tests.
|
/// 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 _getTestFile() {
|
||||||
String appFile = path.normalize(target);
|
String appFile = path.normalize(target);
|
||||||
|
|
||||||
|
@ -6,31 +6,21 @@ import 'dart:async';
|
|||||||
|
|
||||||
import '../application_package.dart';
|
import '../application_package.dart';
|
||||||
import '../device.dart';
|
import '../device.dart';
|
||||||
|
import '../globals.dart';
|
||||||
import '../runner/flutter_command.dart';
|
import '../runner/flutter_command.dart';
|
||||||
|
|
||||||
class StopCommand extends FlutterCommand {
|
class StopCommand extends FlutterCommand {
|
||||||
final String name = 'stop';
|
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
|
@override
|
||||||
Future<int> runInProject() async {
|
Future<int> runInProject() async {
|
||||||
await downloadApplicationPackagesAndConnectToDevices();
|
await downloadApplicationPackages();
|
||||||
return await stop() ? 0 : 2;
|
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 {
|
Future downloadApplicationPackagesAndConnectToDevices() async {
|
||||||
await _downloadApplicationPackages();
|
await downloadApplicationPackages();
|
||||||
_connectToDevices();
|
_connectToDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _downloadApplicationPackages() async {
|
Future downloadApplicationPackages() async {
|
||||||
applicationPackages ??= await ApplicationPackageStore.forConfigs(buildConfigurations);
|
applicationPackages ??= await ApplicationPackageStore.forConfigs(buildConfigurations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user