Search in sources :

Example 21 with ProcessOutput

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

the class PyCondaPackageService method updatePackagesCache.

public void updatePackagesCache() {
    final String condaPython = getCondaPython();
    if (condaPython == null) {
        LOG.warn("Could not find conda python interpreter");
        return;
    }
    final String path = PythonHelpersLocator.getHelperPath("conda_packaging_tool.py");
    final String runDirectory = new File(condaPython).getParent();
    final String[] command = { condaPython, path, "listall" };
    final ProcessOutput output = PySdkUtil.getProcessOutput(runDirectory, command);
    if (output.getExitCode() != 0) {
        LOG.warn("Failed to get list of conda packages");
        LOG.warn(StringUtil.join(command, " "));
        return;
    }
    final List<String> lines = output.getStdoutLines();
    for (String line : lines) {
        final List<String> split = StringUtil.split(line, "\t");
        if (split.size() < 2)
            continue;
        final String aPackage = CONDA_PACKAGES.get(split.get(0));
        if (aPackage != null) {
            if (VersionComparatorUtil.compare(aPackage, split.get(1)) < 0)
                CONDA_PACKAGES.put(split.get(0), split.get(1));
        } else {
            CONDA_PACKAGES.put(split.get(0), split.get(1));
        }
        if (PACKAGES_TO_RELEASES.containsKey(split.get(0))) {
            final List<String> versions = PACKAGES_TO_RELEASES.get(split.get(0));
            if (!versions.contains(split.get(1))) {
                versions.add(split.get(1));
            }
        } else {
            final ArrayList<String> versions = new ArrayList<>();
            versions.add(split.get(1));
            PACKAGES_TO_RELEASES.put(split.get(0), versions);
        }
    }
    LAST_TIME_CHECKED = System.currentTimeMillis();
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 22 with ProcessOutput

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

the class SvnTestCase method runAndVerifyAcrossLocks.

/**
   * @param verifier - if returns true, try again
   */
public static void runAndVerifyAcrossLocks(File workingDir, final TestClientRunner runner, final String[] input, final Processor<ProcessOutput> verifier, final Processor<ProcessOutput> primitiveVerifier) throws IOException {
    for (int i = 0; i < 5; i++) {
        final ProcessOutput output = runner.runClient("svn", null, workingDir, input);
        if (output.getExitCode() == 0) {
            if (verifier.process(output)) {
                continue;
            }
            return;
        }
        if (!StringUtil.isEmptyOrSpaces(output.getStderr())) {
            final String stderr = output.getStderr();
            /*svn: E155004: Working copy '' locked.
        svn: E155004: '' is already locked.
        svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)*/
            if (stderr.contains("E155004") && stderr.contains("is already locked")) {
                continue;
            }
        }
        // will throw assertion
        if (verifier.process(output)) {
            continue;
        }
        return;
    }
    final ProcessOutput output = runner.runClient("svn", null, workingDir, input);
    primitiveVerifier.process(output);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 23 with ProcessOutput

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

the class CmdInfoClient method execute.

private String execute(@NotNull List<String> parameters, @NotNull File path) throws SvnBindException {
    // workaround: separately capture command output - used in exception handling logic to overcome svn 1.8 issue (see below)
    final ProcessOutput output = new ProcessOutput();
    LineCommandListener listener = new LineCommandAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (outputType == ProcessOutputTypes.STDOUT) {
                output.appendStdout(line);
            }
        }
    };
    try {
        CommandExecutor command = execute(myVcs, SvnTarget.fromFile(path), SvnCommandName.info, parameters, listener);
        return command.getOutput();
    } catch (SvnBindException e) {
        final String text = StringUtil.notNullize(e.getMessage());
        if (text.contains("W155010")) {
            // files should be parsed from output
            return output.getStdout();
        }
        // "E155007: '' is not a working copy"
        if (text.contains("is not a working copy") && StringUtil.isNotEmpty(output.getStdout())) {
            // but the requested info is still in the output except root closing tag
            return output.getStdout() + "</info>";
        }
        throw e;
    }
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) Key(com.intellij.openapi.util.Key)

Example 24 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 25 with ProcessOutput

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

the class ExecutableValidator method doCheckExecutable.

protected static boolean doCheckExecutable(@NotNull String executable, @NotNull List<String> processParameters) {
    try {
        GeneralCommandLine commandLine = new GeneralCommandLine();
        commandLine.setExePath(executable);
        commandLine.addParameters(processParameters);
        commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
        CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
        ProcessOutput result = handler.runProcess(TIMEOUT_MS);
        boolean timeout = result.isTimeout();
        int exitCode = result.getExitCode();
        String stderr = result.getStderr();
        if (timeout) {
            LOG.warn("Validation of " + executable + " failed with a timeout");
        }
        if (exitCode != 0) {
            LOG.warn("Validation of " + executable + " failed with a non-zero exit code: " + exitCode);
        }
        if (!stderr.isEmpty()) {
            LOG.warn("Validation of " + executable + " failed with a non-empty error output: " + stderr);
        }
        return !timeout && exitCode == 0 && stderr.isEmpty();
    } catch (Throwable t) {
        LOG.warn(t);
        return false;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

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