use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class PyCondaManagementService method addRepository.
@Override
public void addRepository(String repositoryUrl) {
final String conda = PyCondaPackageService.getCondaExecutable(mySdk.getHomeDirectory());
final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--add", "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 add repository " + message);
}
PyCondaPackageService.getInstance().addChannel(repositoryUrl);
} catch (ExecutionException e) {
LOG.warn("Failed to add repository");
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class PySdkUtil method getProcessOutput.
public static ProcessOutput getProcessOutput(@NotNull GeneralCommandLine cmd, @Nullable String homePath, @Nullable @NonNls Map<String, String> extraEnv, int timeout, @Nullable byte[] stdin, boolean needEOFMarker) {
if (homePath == null || !new File(homePath).exists()) {
return new ProcessOutput();
}
final Map<String, String> systemEnv = System.getenv();
final Map<String, String> expandedCmdEnv = mergeEnvVariables(systemEnv, cmd.getEnvironment());
final Map<String, String> env = extraEnv != null ? mergeEnvVariables(expandedCmdEnv, extraEnv) : expandedCmdEnv;
PythonEnvUtil.resetHomePathChanges(homePath, env);
try {
final GeneralCommandLine commandLine = cmd.withWorkDirectory(homePath).withEnvironment(env);
final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine);
if (stdin != null) {
final OutputStream processInput = processHandler.getProcessInput();
assert processInput != null;
processInput.write(stdin);
if (SystemInfo.isWindows && needEOFMarker) {
processInput.write(SUBSTITUTE);
processInput.flush();
} else {
processInput.close();
}
}
return processHandler.runProcess(timeout);
} catch (ExecutionException | IOException e) {
return getOutputForException(e);
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method ignoredTestMethod.
@Test
public void ignoredTestMethod() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
TestObject state = configuration.getState(executor, environment);
JavaParameters parameters = state.getJavaParameters();
parameters.setUseDynamicClasspath(getProject());
GeneralCommandLine commandLine = parameters.toCommandLine();
StringBuffer buf = new StringBuffer();
StringBuffer err = new StringBuffer();
OSProcessHandler process = new OSProcessHandler(commandLine);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
try {
if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
buf.append(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
err.append(text);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
process.startNotify();
process.waitFor();
process.destroyProcess();
String testOutput = buf.toString();
assertEmpty(err.toString());
switch(myJUnitVersion) {
//shouldn't work for old versions
case "4.4":
//shouldn't work for old versions
case "4.5":
break;
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class GenerateBinaryStubsFix method generateSkeletonsForList.
private boolean generateSkeletonsForList(@NotNull final PySkeletonRefresher refresher, ProgressIndicator indicator, @Nullable final String currentBinaryFilesPath) throws InvalidSdkException {
final PySkeletonGenerator generator = new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
indicator.setIndeterminate(false);
final String homePath = mySdk.getHomePath();
if (homePath == null)
return false;
GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName));
final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(homePath).getParent(), PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000);
if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
final String extraPath = runResult.getStdout();
final PySkeletonGenerator.ListBinariesResult binaries = generator.listBinaries(mySdk, extraPath);
final List<String> names = Lists.newArrayList(binaries.modules.keySet());
Collections.sort(names);
final int size = names.size();
for (int i = 0; i != size; ++i) {
final String name = names.get(i);
indicator.setFraction((double) i / size);
if (needBinaryList(name)) {
indicator.setText2(name);
final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
final String modulePath = item != null ? item.getPath() : "";
//noinspection unchecked
refresher.generateSkeleton(name, modulePath, new ArrayList<>(), Consumer.EMPTY_CONSUMER);
}
}
}
return true;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-community by JetBrains.
the class Pep8ExternalAnnotator method doAnnotate.
@Nullable
@Override
public Results doAnnotate(State collectedInfo) {
if (collectedInfo == null)
return null;
ArrayList<String> options = Lists.newArrayList();
if (!collectedInfo.ignoredErrors.isEmpty()) {
options.add("--ignore=" + DEFAULT_IGNORED_ERRORS + "," + StringUtil.join(collectedInfo.ignoredErrors, ","));
}
if (collectedInfo.hangClosingBrackets) {
options.add("--hang-closing");
}
options.add("--max-line-length=" + collectedInfo.margin);
options.add("-");
GeneralCommandLine cmd = PythonHelper.PYCODESTYLE.newCommandLine(collectedInfo.interpreterPath, options);
ProcessOutput output = PySdkUtil.getProcessOutput(cmd, new File(collectedInfo.interpreterPath).getParent(), ImmutableMap.of("PYTHONBUFFERED", "1"), 10000, collectedInfo.fileText.getBytes(), false);
Results results = new Results(collectedInfo.level);
if (output.isTimeout()) {
LOG.info("Timeout running pycodestyle.py");
} else if (output.getStderrLines().isEmpty()) {
for (String line : output.getStdoutLines()) {
final Problem problem = parseProblem(line);
if (problem != null) {
results.problems.add(problem);
}
}
} else if (((ApplicationInfoImpl) ApplicationInfo.getInstance()).isEAP()) {
LOG.info("Error running pycodestyle.py: " + output.getStderr());
}
return results;
}
Aggregations