use of com.android.tools.idea.run.tasks.LaunchTask in project android by JetBrains.
the class LaunchTaskRunner method run.
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText(getTitle());
indicator.setIndeterminate(false);
LaunchStatus launchStatus = new ProcessHandlerLaunchStatus(myProcessHandler);
ConsolePrinter consolePrinter = new ProcessHandlerConsolePrinter(myProcessHandler);
List<ListenableFuture<IDevice>> listenableDeviceFutures = myDeviceFutures.get();
AndroidVersion androidVersion = myDeviceFutures.getDevices().size() == 1 ? myDeviceFutures.getDevices().get(0).getVersion() : null;
DebugConnectorTask debugSessionTask = myLaunchTasksProvider.getConnectDebuggerTask(launchStatus, androidVersion);
if (debugSessionTask != null && listenableDeviceFutures.size() != 1) {
launchStatus.terminateLaunch("Cannot launch a debug session on more than 1 device.");
}
if (debugSessionTask != null) {
// we need to copy over console output from the first console to the debug console once it is established
AndroidProcessText.attach(myProcessHandler);
}
DateFormat dateFormat = new SimpleDateFormat("MM/dd HH:mm:ss");
consolePrinter.stdout("\n" + dateFormat.format(new Date()) + ": Launching " + myConfigName);
for (ListenableFuture<IDevice> deviceFuture : listenableDeviceFutures) {
indicator.setText("Waiting for target device to come online");
IDevice device = waitForDevice(deviceFuture, indicator, launchStatus);
if (device == null) {
return;
}
List<LaunchTask> launchTasks = null;
try {
launchTasks = myLaunchTasksProvider.getTasks(device, launchStatus, consolePrinter);
} catch (com.intellij.execution.ExecutionException e) {
launchStatus.terminateLaunch(e.getMessage());
return;
} catch (IllegalStateException e) {
launchStatus.terminateLaunch(e.getMessage());
Logger.getInstance(LaunchTaskRunner.class).error(e);
return;
}
int totalDuration = listenableDeviceFutures.size() * getTotalDuration(launchTasks, debugSessionTask);
int elapsed = 0;
for (LaunchTask task : launchTasks) {
// perform each task
indicator.setText(task.getDescription());
if (!task.perform(device, launchStatus, consolePrinter)) {
myError = "Error " + task.getDescription();
launchStatus.terminateLaunch("Error while " + task.getDescription());
return;
}
// update progress
elapsed += task.getDuration();
indicator.setFraction((double) elapsed / totalDuration);
// check for cancellation via progress bar
if (indicator.isCanceled()) {
launchStatus.terminateLaunch("User cancelled launch");
return;
}
// check for cancellation via stop button
if (launchStatus.isLaunchTerminated()) {
return;
}
}
if (debugSessionTask != null) {
debugSessionTask.perform(myLaunchInfo, device, (ProcessHandlerLaunchStatus) launchStatus, (ProcessHandlerConsolePrinter) consolePrinter);
} else {
// we only need to inform the process handler if certain scenarios
if (// we are not doing a hot swap (in which case we are creating a new process)
myLaunchTasksProvider.createsNewProcess() && myProcessHandler instanceof AndroidProcessHandler) {
// we aren't debugging (in which case its a DebugProcessHandler)
((AndroidProcessHandler) myProcessHandler).addTargetDevice(device);
}
}
}
}
Aggregations