Search in sources :

Example 56 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class SystemInfoStatsMonitor method runEmulatorCheck.

@Nullable
private static Integer runEmulatorCheck(@NotNull String argument, @NotNull Revision lowestToolsRevisiion, @NotNull AndroidSdkHandler handler) throws ExecutionException {
    LocalPackage toolsPackage = handler.getLocalPackage(SdkConstants.FD_TOOLS, new StudioLoggerProgressIndicator(AndroidSdkInitializer.class));
    if (toolsPackage == null) {
        throw new ExecutionException("No SDK tools package");
    }
    final Revision toolsRevision = toolsPackage.getVersion();
    if (toolsRevision.compareTo(lowestToolsRevisiion) < 0) {
        return null;
    }
    File checkBinary = getEmulatorCheckBinary(handler);
    if (!checkBinary.isFile()) {
        throw new ExecutionException("No emulator-check binary in the SDK tools package");
    }
    GeneralCommandLine commandLine = new GeneralCommandLine(checkBinary.getPath(), argument);
    CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
    ProcessOutput output = process.runProcess();
    int exitCode = output.getExitCode();
    if (exitCode == EMULATOR_CHECK_ERROR_EXIT_CODE) {
        throw new ExecutionException(String.format("Emulator-check failed to check for '%s' with a generic error code %d", argument, EMULATOR_CHECK_ERROR_EXIT_CODE));
    }
    return exitCode;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) AndroidSdkInitializer(com.android.tools.idea.startup.AndroidSdkInitializer) Revision(com.android.repository.Revision) CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class AccelerationErrorSolution method createKvmInstallCommand.

@Nullable
private static GeneralCommandLine createKvmInstallCommand() {
    try {
        String version = execute("uname", "-r");
        Revision revision = toRevision(version);
        if (revision.compareTo(KARMIC_KERNEL) <= 0) {
            return generateCommand("gksudo", "aptitude -y", "install", "kvm", "libvirt-bin", "ubuntu-vm-builder", "bridge-utils");
        } else {
            return generateCommand("gksudo", "apt-get --assume-yes", "install", "qemu-kvm", "libvirt-bin", "ubuntu-vm-builder", "bridge-utils");
        }
    } catch (ExecutionException ex) {
        LOG.error(ex);
    } catch (NumberFormatException ex) {
        LOG.error(ex);
    }
    return null;
}
Also used : Revision(com.android.repository.Revision) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class AvdManagerConnection method checkAcceleration.

/**
   * Run "emulator -accel-check" to check the status for emulator acceleration on this machine.
   * Return a {@link AccelerationErrorCode}.
   */
public AccelerationErrorCode checkAcceleration() {
    if (!initIfNecessary()) {
        return AccelerationErrorCode.UNKNOWN_ERROR;
    }
    File emulatorBinary = getEmulatorBinary();
    if (!emulatorBinary.isFile()) {
        return AccelerationErrorCode.NO_EMULATOR_INSTALLED;
    }
    if (getMemorySize() < Storage.Unit.GiB.getNumberOfBytes()) {
        // TODO: The emulator -accel-check current does not check for the available memory, do it here instead:
        return AccelerationErrorCode.NOT_ENOUGH_MEMORY;
    }
    if (!hasQEMU2Installed()) {
        return AccelerationErrorCode.TOOLS_UPDATE_REQUIRED;
    }
    File checkBinary = getEmulatorCheckBinary();
    GeneralCommandLine commandLine = new GeneralCommandLine();
    if (checkBinary.isFile()) {
        commandLine.setExePath(checkBinary.getPath());
        commandLine.addParameter("accel");
    } else {
        commandLine.setExePath(emulatorBinary.getPath());
        commandLine.addParameter("-accel-check");
    }
    int exitValue;
    try {
        CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
        ProcessOutput output = process.runProcess();
        exitValue = output.getExitCode();
    } catch (ExecutionException e) {
        exitValue = AccelerationErrorCode.UNKNOWN_ERROR.getErrorCode();
    }
    if (exitValue != 0) {
        return AccelerationErrorCode.fromExitCode(exitValue);
    }
    if (!hasPlatformToolsForQEMU2Installed()) {
        return AccelerationErrorCode.PLATFORM_TOOLS_UPDATE_ADVISED;
    }
    if (!hasSystemImagesForQEMU2Installed()) {
        return AccelerationErrorCode.SYSTEM_IMAGE_UPDATE_ADVISED;
    }
    return AccelerationErrorCode.ALREADY_INSTALLED;
}
Also used : CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 59 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class AndroidRunConfigurationBase method getState.

@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    validateBeforeRun(executor);
    final Module module = getConfigurationModule().getModule();
    assert module != null : "Enforced by fatal validation check in checkConfiguration.";
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null : "Enforced by fatal validation check in checkConfiguration.";
    Project project = env.getProject();
    boolean forceColdswap = !InstantRunUtils.isInvokedViaHotswapAction(env);
    boolean couldHaveHotswapped = false;
    boolean debug = false;
    if (executor instanceof DefaultDebugExecutor) {
        if (!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.");
        }
        debug = true;
    }
    DeviceFutures deviceFutures = null;
    AndroidSessionInfo info = AndroidSessionInfo.findOldSession(project, null, getUniqueID());
    if (info != null && supportsInstantRun()) {
        // if there is an existing previous session, then see if we can detect devices to fast deploy to
        deviceFutures = getFastDeployDevices(executor, facet, info);
        // that the ReRun is now a global action and doesn't really know much details about each run (and doing that seems like a hack too.)
        if (InstantRunUtils.isReRun(env)) {
            killSession(info);
            info = null;
        }
    }
    if (info != null && deviceFutures == null) {
        // If we should not be fast deploying, but there is an existing session, then terminate those sessions. Otherwise, we might end up
        // with 2 active sessions of the same launch, especially if we first think we can do a fast deploy, then end up doing a full launch
        boolean continueLaunch = promptAndKillSession(executor, project, info);
        if (!continueLaunch) {
            return null;
        }
    } else if (info != null && forceColdswap) {
        // the user could have invoked the hotswap action in this scenario, but they chose to force a coldswap (by pressing run)
        couldHaveHotswapped = true;
        // forcibly kill app in case of run action (which forces a cold swap)
        // normally, installing the apk will force kill the app, but we need to forcibly kill it in the case that there were no changes
        killSession(info);
    }
    // If we are not fast deploying, then figure out (prompting user if needed) where to deploy
    if (deviceFutures == null) {
        DeployTarget deployTarget = getDeployTarget(executor, env, debug, facet);
        if (deployTarget == null) {
            return null;
        }
        DeployTargetState deployTargetState = getDeployTargetContext().getCurrentDeployTargetState();
        if (deployTarget.hasCustomRunProfileState(executor)) {
            return deployTarget.getRunProfileState(executor, env, deployTargetState);
        }
        deviceFutures = deployTarget.getDevices(deployTargetState, facet, getDeviceCount(debug), debug, getUniqueID());
        if (deviceFutures == null) {
            // The user deliberately canceled, or some error was encountered and exposed by the chooser. Quietly exit.
            return null;
        }
    }
    if (deviceFutures.get().isEmpty()) {
        throw new ExecutionException(AndroidBundle.message("deployment.target.not.found"));
    }
    ApplicationIdProvider applicationIdProvider = getApplicationIdProvider(facet);
    InstantRunContext instantRunContext = null;
    if (supportsInstantRun() && InstantRunSettings.isInstantRunEnabled()) {
        InstantRunGradleSupport gradleSupport = canInstantRun(module, deviceFutures.getDevices());
        if (gradleSupport == TARGET_PLATFORM_NOT_INSTALLED) {
            AndroidVersion version = deviceFutures.getDevices().get(0).getVersion();
            String message = AndroidBundle.message("instant.run.quickfix.missing.platform", SdkVersionInfo.getVersionWithCodename(version));
            int result = Messages.showYesNoDialog(project, message, "Instant Run", // yes button
            "Install and Continue", // no button
            "Proceed without Instant Run", Messages.getQuestionIcon());
            if (result == Messages.OK) {
                // if ok, install platform and continue with instant run
                ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, ImmutableList.of(DetailsTypes.getPlatformPath(version)));
                if (dialog == null) {
                    LOG.warn("Unable to get quick fix wizard to install missing platform required for instant run.");
                } else if (dialog.showAndGet()) {
                    gradleSupport = SUPPORTED;
                }
            }
        }
        if (gradleSupport == SUPPORTED) {
            if (!AndroidEnableAdbServiceAction.isAdbServiceEnabled()) {
                throw new ExecutionException("Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.");
            }
            InstantRunUtils.setInstantRunEnabled(env, true);
            instantRunContext = InstantRunGradleUtils.createGradleProjectContext(facet);
        } else {
            InstantRunManager.LOG.warn("Instant Run enabled, but not doing an instant run build since: " + gradleSupport);
            String notificationText = gradleSupport.getUserNotification();
            if (notificationText != null) {
                InstantRunNotificationTask.showNotification(env.getProject(), null, notificationText);
            }
        }
    } else {
        String msg = "Not using instant run for this launch: ";
        if (InstantRunSettings.isInstantRunEnabled()) {
            msg += getType().getDisplayName() + " does not support instant run";
        } else {
            msg += "instant run is disabled";
        }
        InstantRunManager.LOG.info(msg);
    }
    // Store the chosen target on the execution environment so before-run tasks can access it.
    AndroidRunConfigContext runConfigContext = new AndroidRunConfigContext();
    env.putCopyableUserData(AndroidRunConfigContext.KEY, runConfigContext);
    runConfigContext.setTargetDevices(deviceFutures);
    runConfigContext.setSameExecutorAsPreviousSession(info != null && executor.getId().equals(info.getExecutorId()));
    runConfigContext.setCleanRerun(InstantRunUtils.isCleanReRun(env));
    runConfigContext.setForceColdSwap(forceColdswap, couldHaveHotswapped);
    // Save the instant run context so that before-run task can access it
    env.putCopyableUserData(InstantRunContext.KEY, instantRunContext);
    if (debug) {
        String error = canDebug(deviceFutures, facet, module.getName());
        if (error != null) {
            throw new ExecutionException(error);
        }
    }
    LaunchOptions launchOptions = getLaunchOptions().setDebug(debug).build();
    ProcessHandler processHandler = null;
    if (info != null && info.getExecutorId().equals(executor.getId())) {
        processHandler = info.getProcessHandler();
    }
    ApkProvider apkProvider = getApkProvider(facet, applicationIdProvider);
    LaunchTasksProviderFactory providerFactory = new AndroidLaunchTasksProviderFactory(this, env, facet, applicationIdProvider, apkProvider, deviceFutures, launchOptions, processHandler, instantRunContext);
    InstantRunStatsService.get(project).notifyBuildStarted();
    return new AndroidRunState(env, getName(), module, applicationIdProvider, getConsoleProvider(), deviceFutures, providerFactory, processHandler);
}
Also used : LaunchTasksProviderFactory(com.android.tools.idea.run.tasks.LaunchTasksProviderFactory) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ProcessHandler(com.intellij.execution.process.ProcessHandler) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 60 with ExecutionException

use of com.intellij.execution.ExecutionException in project android by JetBrains.

the class AndroidRunState method execute.

@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    ProcessHandler processHandler;
    ConsoleView console;
    String applicationId;
    try {
        applicationId = myApplicationIdProvider.getPackageName();
    } catch (ApkProvisionException e) {
        throw new ExecutionException("Unable to obtain application id", e);
    }
    // TODO: this class is independent of gradle, except for this hack
    AndroidModuleModel model = AndroidModuleModel.get(myModule);
    if (InstantRunSettings.isInstantRunEnabled() && InstantRunGradleUtils.getIrSupportStatus(model, null) == InstantRunGradleSupport.SUPPORTED) {
        assert model != null;
        InstantRunBuildInfo info = InstantRunGradleUtils.getBuildInfo(model);
        if (info != null && !info.isCompatibleFormat()) {
            throw new ExecutionException("This version of Android Studio is incompatible with the Gradle Plugin used. " + "Try disabling Instant Run (or updating either the IDE or the Gradle plugin to " + "the latest version)");
        }
    }
    LaunchTasksProvider launchTasksProvider = myLaunchTasksProviderFactory.get();
    if (launchTasksProvider.createsNewProcess()) {
        // and the new one).
        if (myPreviousSessionProcessHandler != null) {
            myPreviousSessionProcessHandler.detachProcess();
        }
        processHandler = new AndroidProcessHandler(applicationId, launchTasksProvider.monitorRemoteProcess());
        console = attachConsole(processHandler, executor);
    } else {
        assert myPreviousSessionProcessHandler != null : "No process handler from previous session, yet current tasks don't create one";
        processHandler = myPreviousSessionProcessHandler;
        console = null;
    }
    LaunchInfo launchInfo = new LaunchInfo(executor, runner, myEnv, myConsoleProvider);
    LaunchTaskRunner task = new LaunchTaskRunner(myModule.getProject(), myLaunchConfigName, launchInfo, processHandler, myDeviceFutures, launchTasksProvider);
    ProgressManager.getInstance().run(task);
    return console == null ? null : new DefaultExecutionResult(console, processHandler);
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ConsoleView(com.intellij.execution.ui.ConsoleView) LaunchTasksProvider(com.android.tools.idea.run.tasks.LaunchTasksProvider) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExecutionException (com.intellij.execution.ExecutionException)154 NotNull (org.jetbrains.annotations.NotNull)42 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)39 IOException (java.io.IOException)35 File (java.io.File)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Sdk (com.intellij.openapi.projectRoots.Sdk)20 Nullable (org.jetbrains.annotations.Nullable)20 Project (com.intellij.openapi.project.Project)19 ProcessHandler (com.intellij.execution.process.ProcessHandler)17 ProcessOutput (com.intellij.execution.process.ProcessOutput)17 Module (com.intellij.openapi.module.Module)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Key (com.intellij.openapi.util.Key)12 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)10 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 JavaParameters (com.intellij.execution.configurations.JavaParameters)7 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ArrayList (java.util.ArrayList)7