Search in sources :

Example 31 with ProcessOutput

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

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class GitExecutableDetector method runs.

/**
   * Checks if it is possible to run the specified program.
   * Made protected for tests not to start a process there.
   */
protected boolean runs(@NotNull String exec) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(exec);
    commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
    try {
        CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
        ProcessOutput result = handler.runProcess((int) TimeUnit.SECONDS.toMillis(5));
        return !result.isTimeout();
    } catch (ExecutionException e) {
        return false;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 33 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.

the class JdkPopupAction method retrieveJDKLocations.

private static ArrayList<Pair<File, String>> retrieveJDKLocations() {
    ArrayList<Pair<File, String>> jdkLocations = new ArrayList<>();
    Collection<String> homePaths = JavaSdk.getInstance().suggestHomePaths();
    for (final String path : homePaths) {
        try {
            File file = new File(path);
            File javaExe = new File(new File(file, "bin"), "java.exe");
            ProcessOutput output = ExecUtil.execAndGetOutput(new GeneralCommandLine(javaExe.getAbsolutePath(), "-version"));
            List<String> lines = output.getStderrLines();
            if (lines.isEmpty()) {
                lines = output.getStdoutLines();
            }
            StringBuilder stringBuilder = new StringBuilder();
            if (lines.size() == 3) {
                stringBuilder.append("JDK ");
                String line = lines.get(1);
                int pos = line.indexOf("(build ");
                if (pos != -1) {
                    stringBuilder.append(line.substring(pos + 7, line.length() - 1));
                }
                line = lines.get(2);
                pos = line.indexOf(" (build");
                if (pos != -1) {
                    String substring = line.substring(0, pos);
                    stringBuilder.append(" (").append(substring).append(")");
                }
            } else {
                stringBuilder.append(file.getName());
            }
            jdkLocations.add(Pair.create(file, stringBuilder.toString()));
        } catch (ExecutionException e) {
            LOG.debug(e);
        }
    }
    return jdkLocations;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ArrayList(java.util.ArrayList) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Example 34 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-plugins by JetBrains.

the class PhoneGapPluginsView method checkParams.

private PhoneGapCommandLine checkParams(Ref<String> error, Ref<String> warning, Ref<String> version, String path, String workDir) throws ExecutionException {
    boolean pathError = false;
    if (!new File(workDir).exists()) {
        pathError = true;
        workDir = myProject.getBasePath();
    }
    PhoneGapCommandLine commandLine = new PhoneGapCommandLine(path, workDir);
    if (!commandLine.isCorrectExecutable()) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.error"));
        return commandLine;
    }
    version.set(commandLine.version());
    if (pathError) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.work.path.error", commandLine.getPlatformName()));
        return commandLine;
    }
    ProcessOutput output = commandLine.pluginListRaw();
    if (!StringUtil.isEmpty(output.getStderr())) {
        error.set(PhoneGapBundle.message("phonegap.plugins.executable.work.path.error", commandLine.getPlatformName()));
        return commandLine;
    }
    if (commandLine.isOld()) {
        warning.set(PhoneGapBundle.message("phonegap.plugins.executable.version.error"));
    }
    return commandLine;
}
Also used : PhoneGapCommandLine(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) File(java.io.File)

Example 35 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-plugins by JetBrains.

the class PhoneGapTargets method list.

protected List<String> list(String executableName, Function<String, String> parser, boolean errorOut, String... params) {
    List<String> result = ContainerUtil.newArrayList();
    File deployExecutable = PathEnvironmentVariableUtil.findInPath(executableName);
    if (deployExecutable == null)
        return result;
    try {
        GeneralCommandLine line = new GeneralCommandLine(deployExecutable.getAbsolutePath());
        line.addParameters(params);
        ProcessOutput output = ExecUtil.execAndGetOutput(line);
        List<String> lines = null;
        if (errorOut) {
            if (!StringUtil.isEmpty(output.getStderr())) {
                lines = output.getStderrLines();
            }
        }
        if (lines == null) {
            lines = output.getStdoutLines();
        }
        if (output.getExitCode() != 0)
            return result;
        for (String value : lines) {
            ContainerUtil.addIfNotNull(result, parser.fun(value));
        }
    } catch (ExecutionException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    return result;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Aggregations

ProcessOutput (com.intellij.execution.process.ProcessOutput)57 File (java.io.File)22 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 ExecutionException (com.intellij.execution.ExecutionException)18 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 Nullable (org.jetbrains.annotations.Nullable)10 NotNull (org.jetbrains.annotations.NotNull)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PsiFile (com.intellij.psi.PsiFile)3 SkeletonVersionChecker.fromVersionString (com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString)3 IOException (java.io.IOException)3 PhoneGapCommandLine (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapCommandLine)2 Change (com.intellij.openapi.vcs.changes.Change)2 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)2 TempDirTestFixture (com.intellij.testFramework.fixtures.TempDirTestFixture)2