use of com.intellij.execution.process.ProcessOutput 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;
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class PyStructuredDocstringFormatter method runExternalTool.
@Nullable
private static String runExternalTool(@NotNull final Module module, @NotNull final DocStringFormat format, @NotNull final String docstring) {
final Sdk sdk;
final String missingInterpreterMessage;
if (format == DocStringFormat.EPYTEXT) {
sdk = PythonSdkType.findPython2Sdk(module);
missingInterpreterMessage = PyBundle.message("QDOC.epydoc.python2.sdk.not.found");
} else {
sdk = PythonSdkType.findLocalCPython(module);
missingInterpreterMessage = PyBundle.message("QDOC.sdk.not.found");
}
if (sdk == null) {
LOG.warn("Python SDK for docstring formatter " + format + " is not found");
return "<p color=\"red\">" + missingInterpreterMessage + "</p>";
}
final String sdkHome = sdk.getHomePath();
if (sdkHome == null)
return null;
final ByteBuffer encoded = DEFAULT_CHARSET.encode(docstring);
final byte[] data = new byte[encoded.limit()];
encoded.get(data);
final ArrayList<String> arguments = Lists.newArrayList(format.getFormatterCommand());
final GeneralCommandLine commandLine = PythonHelper.DOCSTRING_FORMATTER.newCommandLine(sdk, arguments);
commandLine.setCharset(DEFAULT_CHARSET);
LOG.debug("Command for launching docstring formatter: " + commandLine.getCommandLineString());
final ProcessOutput output = PySdkUtil.getProcessOutput(commandLine, new File(sdkHome).getParent(), null, 5000, data, false);
if (!output.checkSuccess(LOG)) {
LOG.info("Malformed docstring:\n" + docstring);
return null;
}
return output.getStdout();
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class PythonSdkType method getSysPathsFromScript.
@NotNull
public static List<String> getSysPathsFromScript(@NotNull String binaryPath) throws InvalidSdkException {
// to handle the situation when PYTHONPATH contains ., we need to run the syspath script in the
// directory of the script itself - otherwise the dir in which we run the script (e.g. /usr/bin) will be added to SDK path
GeneralCommandLine cmd = PythonHelper.SYSPATH.newCommandLine(binaryPath, Lists.newArrayList());
final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(binaryPath).getParent(), getVirtualEnvExtraEnv(binaryPath), MINUTE);
if (!runResult.checkSuccess(LOG)) {
throw new InvalidSdkException(String.format("Failed to determine Python's sys.path value:\nSTDOUT: %s\nSTDERR: %s", runResult.getStdout(), runResult.getStderr()));
}
return runResult.getStdoutLines();
}
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;
}
use of com.intellij.execution.process.ProcessOutput in project intellij-plugins by JetBrains.
the class PhoneGapAddPlatformBeforeRun method executeTask.
@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, ExecutionEnvironment env, PhoneGapAddPlatformTask task) {
final PhoneGapRunConfiguration phoneGapRunConfiguration = (PhoneGapRunConfiguration) configuration;
final PhoneGapCommandLine line = phoneGapRunConfiguration.getCommandLine();
if (!line.needAddPlatform()) {
return true;
}
final Project project = configuration.getProject();
final Semaphore targetDone = new Semaphore();
final Ref<Boolean> result = new Ref<>(true);
final List<Exception> exceptions = new ArrayList<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
//Save all opened documents
FileDocumentManager.getInstance().saveAllDocuments();
targetDone.down();
new Task.Backgroundable(project, PhoneGapBundle.message("phonegap.before.task.init.title"), true) {
public boolean shouldStartInBackground() {
return true;
}
public void run(@NotNull final ProgressIndicator indicator) {
try {
String platform = phoneGapRunConfiguration.getPlatform();
assert platform != null;
ProcessOutput output = line.platformAdd(platform);
if (output.getExitCode() != 0) {
ExecutionHelper.showOutput(project, output, PhoneGapBundle.message("phonegap.before.task.init.title"), null, true);
result.set(false);
}
} catch (final Exception e) {
exceptions.add(e);
result.set(false);
} finally {
targetDone.up();
}
}
}.queue();
}, ModalityState.NON_MODAL);
if (!targetDone.waitFor(TimeUnit.MINUTES.toMillis(2))) {
ExecutionHelper.showErrors(project, ContainerUtil.createMaybeSingletonList(new RuntimeException("Timeout")), PhoneGapBundle.message("phonegap.before.task.init.error"), null);
} else if (!exceptions.isEmpty()) {
ExecutionHelper.showErrors(project, exceptions, PhoneGapBundle.message("phonegap.before.task.init.error"), null);
}
return result.get();
}
Aggregations