Search in sources :

Example 1 with DeviceFutures

use of com.android.tools.idea.run.DeviceFutures in project intellij by bazelbuild.

the class BlazeAndroidRunConfigurationRunner method getRunProfileState.

@Override
@Nullable
public final RunProfileState getRunProfileState(final Executor executor, ExecutionEnvironment env) throws ExecutionException {
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null : "Enforced by fatal validation check in createRunner.";
    final Project project = env.getProject();
    runContext.augmentEnvironment(env);
    boolean isDebug = executor instanceof DefaultDebugExecutor;
    if (isDebug && !AndroidSdkUtils.activateDdmsIfNecessary(facet.getModule().getProject())) {
        throw new ExecutionException("Unable to obtain debug bridge. " + "Please check if there is a different tool using adb that is active.");
    }
    AndroidSessionInfo info = AndroidSessionInfo.findOldSession(project, null, runConfigId);
    BlazeAndroidDeviceSelector deviceSelector = runContext.getDeviceSelector();
    BlazeAndroidDeviceSelector.DeviceSession deviceSession = deviceSelector.getDevice(project, facet, deployTargetManager, executor, env, info, isDebug, runConfigId);
    if (deviceSession == null) {
        return null;
    }
    DeployTarget deployTarget = deviceSession.deployTarget;
    if (deployTarget != null && deployTarget.hasCustomRunProfileState(executor)) {
        DeployTargetState deployTargetState = deployTargetManager.getCurrentDeployTargetState();
        return deployTarget.getRunProfileState(executor, env, deployTargetState);
    }
    DeviceFutures deviceFutures = deviceSession.deviceFutures;
    if (deviceFutures == null) {
        // Quietly exit.
        return null;
    }
    if (deviceFutures.get().isEmpty()) {
        throw new ExecutionException(AndroidBundle.message("deployment.target.not.found"));
    }
    if (isDebug) {
        String error = canDebug(deviceFutures, facet, module.getName());
        if (error != null) {
            throw new ExecutionException(error);
        }
    }
    LaunchOptions.Builder launchOptionsBuilder = getDefaultLaunchOptions().setDebug(isDebug);
    runContext.augmentLaunchOptions(launchOptionsBuilder);
    // Store the run context on the execution environment so before-run tasks can access it.
    env.putCopyableUserData(RUN_CONTEXT_KEY, runContext);
    env.putCopyableUserData(DEVICE_SESSION_KEY, deviceSession);
    return new BlazeAndroidRunState(module, env, getName(), launchOptionsBuilder, isDebug, deviceSession, runContext);
}
Also used : AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) LaunchOptions(com.android.tools.idea.run.LaunchOptions) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DeployTarget(com.android.tools.idea.run.editor.DeployTarget) DeployTargetState(com.android.tools.idea.run.editor.DeployTargetState) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DeviceFutures

use of com.android.tools.idea.run.DeviceFutures in project intellij by bazelbuild.

the class BlazeApkBuildStepMobileInstall method build.

@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
    ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {

        @Override
        protected Void execute(BlazeContext context) {
            DeviceFutures deviceFutures = deviceSession.deviceFutures;
            assert deviceFutures != null;
            IDevice device = resolveDevice(context, deviceFutures);
            if (device == null) {
                return null;
            }
            BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
            command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
            // Redundant, but we need this to get around bug in bazel.
            // https://github.com/bazelbuild/bazel/issues/4922
            command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
            if (USE_SDK_ADB.getValue()) {
                File adb = AndroidSdkUtils.getAdb(project);
                if (adb != null) {
                    command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
                }
            }
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
            BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
            command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
            SaveUtil.saveAllFiles();
            int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            FileCaches.refresh(project);
            if (retVal != 0) {
                context.setHasError();
                return null;
            }
            deployInfo = deployInfoHelper.readDeployInfo(context);
            if (deployInfo == null) {
                IssueOutput.error("Could not read apk deploy info from build").submit(context);
            }
            return null;
        }
    };
    ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
    try {
        Futures.get(buildFuture, ExecutionException.class);
    } catch (ExecutionException e) {
        context.setHasError();
    } catch (CancellationException e) {
        context.setCancelled();
    }
    return context.shouldContinue();
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) IDevice(com.android.ddmlib.IDevice) DeviceFutures(com.android.tools.idea.run.DeviceFutures) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

Aggregations

DeviceFutures (com.android.tools.idea.run.DeviceFutures)2 ExecutionException (com.intellij.execution.ExecutionException)2 IDevice (com.android.ddmlib.IDevice)1 AndroidSessionInfo (com.android.tools.idea.run.AndroidSessionInfo)1 LaunchOptions (com.android.tools.idea.run.LaunchOptions)1 DeployTarget (com.android.tools.idea.run.editor.DeployTarget)1 DeployTargetState (com.android.tools.idea.run.editor.DeployTargetState)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)1 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)1 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 ScopedTask (com.google.idea.blaze.base.scope.ScopedTask)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 CancellationException (java.util.concurrent.CancellationException)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 Nullable (org.jetbrains.annotations.Nullable)1