Search in sources :

Example 51 with ProcessOutput

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

the class SvnRenameTest method testCommitAfterRenameDir.

// IDEADEV-19065
@Test
public void testCommitAfterRenameDir() throws Exception {
    final VirtualFile child = prepareDirectoriesForRename();
    renameFileInCommand(child, "newchild");
    checkin();
    final ProcessOutput runResult = runSvn("log", "-q", "newchild/a.txt");
    verify(runResult);
    final List<String> lines = StringUtil.split(runResult.getStdout(), "\n");
    for (Iterator<String> iterator = lines.iterator(); iterator.hasNext(); ) {
        final String next = iterator.next();
        if (next.startsWith(LOG_SEPARATOR_START)) {
            iterator.remove();
        }
    }
    Assert.assertEquals(2, lines.size());
    Assert.assertTrue(lines.get(0).startsWith("r2 |"));
    Assert.assertTrue(lines.get(1).startsWith("r1 |"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessOutput(com.intellij.execution.process.ProcessOutput) Test(org.junit.Test)

Example 52 with ProcessOutput

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

the class GitVersion method identifyVersion.

@NotNull
public static GitVersion identifyVersion(String gitExecutable) throws TimeoutException, ExecutionException, ParseException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(gitExecutable);
    commandLine.addParameter("--version");
    commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    ProcessOutput result = indicator == null ? handler.runProcess(ExecutableValidator.TIMEOUT_MS) : handler.runProcessWithProgressIndicator(indicator);
    if (result.isTimeout()) {
        throw new TimeoutException("Couldn't identify the version of Git - stopped by timeout.");
    } else if (result.isCancelled()) {
        LOG.info("Cancelled by user. exitCode=" + result.getExitCode());
        throw new ProcessCanceledException();
    } else if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
        LOG.info("getVersion exitCode=" + result.getExitCode() + " errors: " + result.getStderr());
        // anyway trying to parse
        try {
            parse(result.getStdout());
        } catch (ParseException pe) {
            throw new ExecutionException("Errors while executing git --version. exitCode=" + result.getExitCode() + " errors: " + result.getStderr());
        }
    }
    return parse(result.getStdout());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ParseException(java.text.ParseException) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler) TimeoutException(java.util.concurrent.TimeoutException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with ProcessOutput

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

the class PyCondaManagementService method removeRepository.

@Override
public void removeRepository(String repositoryUrl) {
    final String conda = PyCondaPackageService.getCondaExecutable(mySdk.getHomeDirectory());
    final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--remove", "channels", repositoryUrl, "--force");
    final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
    try {
        final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
        final ProcessOutput result = handler.runProcess();
        final int exitCode = result.getExitCode();
        if (exitCode != 0) {
            final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? "Permission denied" : "Non-zero exit code";
            LOG.warn("Failed to remove repository " + message);
        }
        PyCondaPackageService.getInstance().removeChannel(repositoryUrl);
    } catch (ExecutionException e) {
        LOG.warn("Failed to remove repository");
    }
}
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 54 with ProcessOutput

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

the class PyCondaPackageManagerImpl method createVirtualEnv.

@NotNull
public static String createVirtualEnv(@NotNull String destinationDir, String version) throws ExecutionException {
    final String condaExecutable = PyCondaPackageService.getSystemCondaExecutable();
    if (condaExecutable == null)
        throw new PyExecutionException("Cannot find conda", "Conda", Collections.<String>emptyList(), new ProcessOutput());
    final ArrayList<String> parameters = Lists.newArrayList(condaExecutable, "create", "-p", destinationDir, "-y", "python=" + version);
    final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
    final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    final ProcessOutput result = handler.runProcessWithProgressIndicator(indicator);
    if (result.isCancelled()) {
        throw new RunCanceledByUserException();
    }
    final int exitCode = result.getExitCode();
    if (exitCode != 0) {
        final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? "Permission denied" : "Non-zero exit code";
        throw new PyExecutionException(message, "Conda", parameters, result);
    }
    final String binary = PythonSdkType.getPythonExecutable(destinationDir);
    final String binaryFallback = destinationDir + File.separator + "bin" + File.separator + "python";
    return (binary != null) ? binary : binaryFallback;
}
Also used : RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with ProcessOutput

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

the class PyCondaPackageManagerImpl method collectPackages.

@NotNull
@Override
protected List<PyPackage> collectPackages() throws ExecutionException {
    final ProcessOutput output = getCondaOutput("list", Lists.newArrayList("-e"));
    final Set<PyPackage> packages = Sets.newConcurrentHashSet(parseCondaToolOutput(output.getStdout()));
    packages.addAll(super.collectPackages());
    return Lists.newArrayList(packages);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProcessOutput (com.intellij.execution.process.ProcessOutput)66 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 File (java.io.File)23 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)16 Nullable (org.jetbrains.annotations.Nullable)13 NotNull (org.jetbrains.annotations.NotNull)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Project (com.intellij.openapi.project.Project)5 PsiFile (com.intellij.psi.PsiFile)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)4 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)3 Notification (com.intellij.notification.Notification)3 Document (com.intellij.openapi.editor.Document)3 Task (com.intellij.openapi.progress.Task)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3