Search in sources :

Example 1 with DeployTarget

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

the class BlazeAndroidRunConfigurationDeployTargetManager method getDeployTarget.

@Nullable
DeployTarget getDeployTarget(Executor executor, ExecutionEnvironment env, AndroidFacet facet, int runConfigId) throws ExecutionException {
    DeployTargetProvider currentTargetProvider = getCurrentDeployTargetProvider();
    DeployTarget deployTarget;
    if (currentTargetProvider.requiresRuntimePrompt()) {
        deployTarget = currentTargetProvider.showPrompt(executor, env, facet, getDeviceCount(), isAndroidTest, deployTargetStates, runConfigId, (device) -> LaunchCompatibility.YES);
        if (deployTarget == null) {
            return null;
        }
    } else {
        deployTarget = currentTargetProvider.getDeployTarget();
    }
    return deployTarget;
}
Also used : JDOMExternalizable(com.intellij.openapi.util.JDOMExternalizable) ImmutableMap(com.google.common.collect.ImmutableMap) DeployTarget(com.android.tools.idea.run.editor.DeployTarget) ExecutionException(com.intellij.execution.ExecutionException) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) TargetSelectionMode(com.android.tools.idea.run.TargetSelectionMode) DeployTargetState(com.android.tools.idea.run.editor.DeployTargetState) Executor(com.intellij.execution.Executor) InvalidDataException(com.intellij.openapi.util.InvalidDataException) DefaultJDOMExternalizer(com.intellij.openapi.util.DefaultJDOMExternalizer) ValidationError(com.android.tools.idea.run.ValidationError) List(java.util.List) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) LaunchCompatibility(com.android.tools.idea.run.LaunchCompatibility) Map(java.util.Map) DeployTargetProvider(com.android.tools.idea.run.editor.DeployTargetProvider) WriteExternalException(com.intellij.openapi.util.WriteExternalException) DeviceCount(com.android.tools.idea.run.DeviceCount) Element(org.jdom.Element) Nullable(javax.annotation.Nullable) DeployTargetProvider(com.android.tools.idea.run.editor.DeployTargetProvider) DeployTarget(com.android.tools.idea.run.editor.DeployTarget) Nullable(javax.annotation.Nullable)

Example 2 with DeployTarget

use of com.android.tools.idea.run.editor.DeployTarget 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)

Aggregations

DeployTarget (com.android.tools.idea.run.editor.DeployTarget)2 DeployTargetState (com.android.tools.idea.run.editor.DeployTargetState)2 ExecutionException (com.intellij.execution.ExecutionException)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 AndroidSessionInfo (com.android.tools.idea.run.AndroidSessionInfo)1 DeviceCount (com.android.tools.idea.run.DeviceCount)1 DeviceFutures (com.android.tools.idea.run.DeviceFutures)1 LaunchCompatibility (com.android.tools.idea.run.LaunchCompatibility)1 LaunchOptions (com.android.tools.idea.run.LaunchOptions)1 TargetSelectionMode (com.android.tools.idea.run.TargetSelectionMode)1 ValidationError (com.android.tools.idea.run.ValidationError)1 DeployTargetProvider (com.android.tools.idea.run.editor.DeployTargetProvider)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Executor (com.intellij.execution.Executor)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 Project (com.intellij.openapi.project.Project)1 DefaultJDOMExternalizer (com.intellij.openapi.util.DefaultJDOMExternalizer)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 JDOMExternalizable (com.intellij.openapi.util.JDOMExternalizable)1