use of com.intellij.execution.process.CapturingProcessHandler 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());
}
use of com.intellij.execution.process.CapturingProcessHandler 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");
}
}
use of com.intellij.execution.process.CapturingProcessHandler 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;
}
use of com.intellij.execution.process.CapturingProcessHandler in project intellij-community by JetBrains.
the class PyCondaPackageManagerImpl method getCondaOutput.
private ProcessOutput getCondaOutput(@NotNull final String command, List<String> arguments) throws ExecutionException {
final Sdk sdk = getSdk();
final String condaExecutable = PyCondaPackageService.getCondaExecutable(sdk.getHomeDirectory());
if (condaExecutable == null)
throw new PyExecutionException("Cannot find conda", "Conda", Collections.<String>emptyList(), new ProcessOutput());
final String path = getCondaDirectory();
if (path == null)
throw new PyExecutionException("Empty conda name for " + sdk.getHomePath(), command, arguments);
final ArrayList<String> parameters = Lists.newArrayList(condaExecutable, command, "-p", path);
parameters.addAll(arguments);
final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
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";
throw new PyExecutionException(message, "Conda", parameters, result);
}
return result;
}
Aggregations