Search in sources :

Example 1 with CapturingAnsiEscapesAwareProcessHandler

use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler 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 2 with CapturingAnsiEscapesAwareProcessHandler

use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler 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 3 with CapturingAnsiEscapesAwareProcessHandler

use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler in project android by JetBrains.

the class Haxm method runInstaller.

private void runInstaller(InstallContext installContext, GeneralCommandLine commandLine) {
    try {
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        if (progressIndicator != null) {
            progressIndicator.setIndeterminate(true);
            progressIndicator.setText(RUNNING_INTEL_HAXM_INSTALLER_MESSAGE);
        }
        installContext.print(RUNNING_INTEL_HAXM_INSTALLER_MESSAGE + "\n", ConsoleViewContentType.SYSTEM_OUTPUT);
        CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
        final StringBuffer output = new StringBuffer();
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                output.append(event.getText());
                super.onTextAvailable(event, outputType);
            }
        });
        myProgressStep.attachToProcess(process);
        int exitCode = process.runProcess().getExitCode();
        // More testing of bash scripts invocation with intellij process wrappers might be useful.
        if (exitCode != INTEL_HAXM_INSTALLER_EXIT_CODE_SUCCESS) {
            // According to the installer docs for Windows, installer may signify that a reboot is required
            if (SystemInfo.isWindows && exitCode == INTEL_HAXM_INSTALLER_EXIT_CODE_REBOOT_REQUIRED) {
                String rebootMessage = "Reboot required: HAXM installation succeeded, however the installer reported that a reboot is " + "required in order for the changes to take effect";
                installContext.print(rebootMessage, ConsoleViewContentType.NORMAL_OUTPUT);
                AccelerationErrorSolution.promptAndRebootAsync(rebootMessage, ModalityState.NON_MODAL);
                myHaxmInstallerSuccessfullyCompleted = true;
                return;
            }
            // HAXM is not required so we do not stop setup process if this install failed.
            if (myInstallationIntention == HaxmInstallationIntention.UNINSTALL) {
                installContext.print("HAXM uninstallation failed", ConsoleViewContentType.ERROR_OUTPUT);
            } else {
                installContext.print(String.format("HAXM installation failed. To install HAXM follow the instructions found at: %s", SystemInfo.isWindows ? FirstRunWizardDefaults.HAXM_WINDOWS_INSTALL_URL : FirstRunWizardDefaults.HAXM_MAC_INSTALL_URL), ConsoleViewContentType.ERROR_OUTPUT);
            }
            Matcher m = Pattern.compile("installation log:\\s*\"(.*)\"").matcher(output.toString());
            if (m.find()) {
                String file = m.group(1);
                installContext.print(String.format("Installer log is located at %s", file), ConsoleViewContentType.ERROR_OUTPUT);
                try {
                    installContext.print("Installer log contents:\n", ConsoleViewContentType.ERROR_OUTPUT);
                    installContext.print(FileUtil.loadFile(new File(file), "UTF-16"), ConsoleViewContentType.NORMAL_OUTPUT);
                } catch (IOException e) {
                    installContext.print("Failed to read installer output log.\n", ConsoleViewContentType.ERROR_OUTPUT);
                }
            }
            progressIndicator.setFraction(1);
            myHaxmInstallerSuccessfullyCompleted = false;
            return;
        }
        progressIndicator.setFraction(1);
        myHaxmInstallerSuccessfullyCompleted = true;
    } catch (ExecutionException e) {
        installContext.print("Unable to run Intel HAXM installer: " + e.getMessage() + "\n", ConsoleViewContentType.ERROR_OUTPUT);
        LOG.warn(e);
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Key(com.intellij.openapi.util.Key)

Example 4 with CapturingAnsiEscapesAwareProcessHandler

use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler in project android by JetBrains.

the class CheckSdkOperation method checkCanRunSdkTool.

private static boolean checkCanRunSdkTool(File executable) throws ExecutionException {
    GeneralCommandLine commandLine = new GeneralCommandLine(executable.getAbsolutePath());
    CapturingAnsiEscapesAwareProcessHandler handler = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
    final int exitCode = handler.runProcess().getExitCode();
    // 1 means help was printed
    return exitCode == 1;
}
Also used : CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 5 with CapturingAnsiEscapesAwareProcessHandler

use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler in project android by JetBrains.

the class AccelerationErrorSolution method execute.

private static String execute(@NotNull GeneralCommandLine commandLine) throws ExecutionException {
    int exitValue;
    CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
    ProcessOutput output = process.runProcess();
    exitValue = output.getExitCode();
    if (exitValue == 0) {
        return output.getStdout();
    } else {
        throw new ExecutionException(String.format("Error running: %1$s", process.getCommandLine()));
    }
}
Also used : CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)6 ExecutionException (com.intellij.execution.ExecutionException)5 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)4 ProcessOutput (com.intellij.execution.process.ProcessOutput)3 File (java.io.File)3 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)2 ProcessEvent (com.intellij.execution.process.ProcessEvent)2 Key (com.intellij.openapi.util.Key)2 IOException (java.io.IOException)2 Revision (com.android.repository.Revision)1 LocalPackage (com.android.repository.api.LocalPackage)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 AndroidSdkInitializer (com.android.tools.idea.startup.AndroidSdkInitializer)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Matcher (java.util.regex.Matcher)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1