Search in sources :

Example 1 with DebugConnectorTask

use of com.android.tools.idea.run.tasks.DebugConnectorTask 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);
            }
        }
    }
}
Also used : LaunchStatus(com.android.tools.idea.run.util.LaunchStatus) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) IDevice(com.android.ddmlib.IDevice) AndroidVersion(com.android.sdklib.AndroidVersion) Date(java.util.Date) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LaunchTask(com.android.tools.idea.run.tasks.LaunchTask) DebugConnectorTask(com.android.tools.idea.run.tasks.DebugConnectorTask) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

IDevice (com.android.ddmlib.IDevice)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 DebugConnectorTask (com.android.tools.idea.run.tasks.DebugConnectorTask)1 LaunchTask (com.android.tools.idea.run.tasks.LaunchTask)1 LaunchStatus (com.android.tools.idea.run.util.LaunchStatus)1 ProcessHandlerLaunchStatus (com.android.tools.idea.run.util.ProcessHandlerLaunchStatus)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1