Search in sources :

Example 36 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 37 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)

Example 38 with ProcessOutput

use of com.intellij.execution.process.ProcessOutput in project intellij-elixir by KronicDeth.

the class MixConfigurationForm method validateMixPath.

private boolean validateMixPath() {
    String mixPath = myMixPathSelector.getText();
    File mix = new File(mixPath);
    if (!mix.exists()) {
        return false;
    }
    if (!mix.canExecute()) {
        String reason = mix.getPath() + "is not executable.";
        LOGGER.warn("Can't detect Mix version: " + reason);
        return false;
    }
    File exeFile = mix.getAbsoluteFile();
    String exePath = exeFile.getPath();
    String workDir = exeFile.getParent();
    ProcessOutput output = null;
    boolean valid = false;
    for (String[] arguments : MIX_ARGUMENTS_ARRAY) {
        try {
            output = ElixirSystemUtil.getProcessOutput(3000, workDir, exePath, arguments);
        } catch (ExecutionException executionException) {
            LOGGER.warn(executionException);
        }
        if (output != null) {
            String transformedStdout = transformStdoutLine(output, STDOUT_LINE_TRANSFORMER);
            if (transformedStdout != null) {
                myMixVersionText.setText(transformedStdout);
                String versionString = transformedStdout.replaceAll("^[^0-9]*", "");
                // Support for the --formatter option may be added in a 1.3.x release, but I'm being conservative for now
                // and assuming it won't be released until 1.4
                ElixirSdkRelease elixirSdkRelease = ElixirSdkRelease.fromString(versionString);
                if (elixirSdkRelease != null) {
                    supportsFormatterOptionCheckBox.setSelected(elixirSdkRelease.compareTo(ElixirSdkRelease.V_1_4) >= 0);
                }
                valid = true;
                break;
            } else {
                String stderr = output.getStderr();
                StringBuilder text = new StringBuilder("N/A");
                if (StringUtil.isNotEmpty(stderr)) {
                    text.append(": Error: ").append(stderr);
                }
                myMixVersionText.setText(text.toString());
            }
        }
    }
    return valid;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) ElixirSdkRelease(org.elixir_lang.sdk.ElixirSdkRelease) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 39 with ProcessOutput

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

the class GeneralCommandLineTest method execAndGetOutput.

private static String execAndGetOutput(GeneralCommandLine commandLine) throws ExecutionException {
    ProcessOutput output = ExecUtil.execAndGetOutput(commandLine);
    int ec = output.getExitCode();
    if (ec != 0) {
        fail("Command:\n" + commandLine.getCommandLineString() + "\nStdOut:\n" + output.getStdout() + "\nStdErr:\n" + output.getStderr());
    }
    return output.getStdout();
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 40 with ProcessOutput

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

the class ProcessListUtil method parseCommandOutput.

@Nullable
private static List<ProcessInfo> parseCommandOutput(@NotNull List<String> command, @NotNull NullableFunction<String, List<ProcessInfo>> parser) {
    String output;
    try {
        ProcessOutput processOutput = ExecUtil.execAndGetOutput(new GeneralCommandLine(command));
        int exitCode = processOutput.getExitCode();
        if (exitCode != 0) {
            LOG.error("Cannot get process list, command '" + StringUtil.join(command, " ") + "' exited with code " + exitCode + ", stdout:\n" + processOutput.getStdout() + "\nstderr:\n" + processOutput.getStderr());
        }
        output = processOutput.getStdout();
    } catch (ExecutionException e) {
        LOG.error("Cannot get process list", e);
        return null;
    }
    return parser.fun(output);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

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