use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class StudyCheckTask method getTestOutput.
@Nullable
private StudyTestsOutputParser.TestsOutput getTestOutput(@NotNull ProgressIndicator indicator) {
final CapturingProcessHandler handler = new CapturingProcessHandler(myTestProcess, null, myCommandLine);
final ProcessOutput output = handler.runProcessWithProgressIndicator(indicator);
if (indicator.isCanceled()) {
ApplicationManager.getApplication().invokeLater(() -> StudyCheckUtils.showTestResultPopUp("Check cancelled", MessageType.WARNING.getPopupBackground(), myProject));
}
myRunTestFile = !output.getStdout().contains(DO_NOT_RUN_ON_CHECK);
final Course course = StudyTaskManager.getInstance(myProject).getCourse();
if (course != null) {
final StudyTestsOutputParser.TestsOutput testsOutput = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive());
String stderr = output.getStderr();
if (!stderr.isEmpty() && output.getStdout().isEmpty()) {
//log error output of tests
LOG.info("#educational " + stderr);
return new StudyTestsOutputParser.TestsOutput(false, stderr);
}
return testsOutput;
}
return null;
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class StudySmartChecker method smartCheck.
public static void smartCheck(@NotNull final AnswerPlaceholder placeholder, @NotNull final Project project, @NotNull final VirtualFile answerFile, @NotNull final TaskFile answerTaskFile, @NotNull final TaskFile usersTaskFile, @NotNull final StudyTestRunner testRunner, @NotNull final VirtualFile virtualFile, @NotNull final Document usersDocument) {
VirtualFile fileWindows = null;
File resourceFile = null;
VirtualFile windowCopy = null;
try {
final int index = placeholder.getIndex();
String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document windowDocument = documentManager.getDocument(windowCopy);
if (windowDocument != null) {
resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
if (windowTaskFile == null) {
return;
}
EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
windowDocument.addDocumentListener(listener);
int start = placeholder.getOffset();
int end = start + placeholder.getRealLength();
final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
int userStart = userAnswerPlaceholder.getOffset();
int userEnd = userStart + userAnswerPlaceholder.getRealLength();
String text = usersDocument.getText(new TextRange(userStart, userEnd));
windowDocument.replaceString(start, end, text);
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
final ProcessOutput output = handler.runProcess();
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null) {
boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
}
}
} catch (ExecutionException | IOException e) {
LOG.error(e);
} finally {
StudyUtils.deleteFile(windowCopy);
StudyUtils.deleteFile(fileWindows);
if (resourceFile != null && resourceFile.exists() && !resourceFile.delete()) {
LOG.error("failed to delete", resourceFile.getPath());
}
}
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class PyRemotePackageManagerImpl method getPythonProcessOutput.
@NotNull
@Override
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, boolean showProgress, @Nullable final String workingDir) throws ExecutionException {
final Sdk sdk = getSdk();
final String homePath = sdk.getHomePath();
if (homePath == null) {
throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
}
final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
//remote interpreter
final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
RemoteSdkCredentials remoteSdkCredentials;
if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
try {
remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
} catch (InterruptedException e) {
LOG.error(e);
remoteSdkCredentials = null;
} catch (ExecutionException e) {
throw analyzeException(e, helperPath, args);
}
if (manager != null && remoteSdkCredentials != null) {
if (askForSudo) {
askForSudo = !manager.ensureCanWrite(null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
}
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
}
if (manager != null) {
final List<String> cmdline = new ArrayList<>();
cmdline.add(homePath);
cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
cmdline.addAll(Collections2.transform(args, new Function<String, String>() {
@Override
public String apply(@Nullable String input) {
return quoteIfNeeded(input);
}
}));
ProcessOutput processOutput;
do {
final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData = (PyRemoteSdkAdditionalDataBase) sdkData;
final PyRemotePathMapper pathMapper = manager.setupMappings(null, remoteSdkAdditionalData, null);
try {
processOutput = PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData).executeRemoteProcess(null, ArrayUtil.toStringArray(cmdline), workingDir, manager, remoteSdkAdditionalData, pathMapper, askForSudo, true);
} catch (InterruptedException e) {
throw new ExecutionException(e);
}
if (askForSudo && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
continue;
}
break;
} while (true);
return processOutput;
} else {
throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
}
} else {
throw new PyExecutionException("Invalid remote SDK", helperPath, args);
}
}
use of com.intellij.execution.process.ProcessOutput 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.process.ProcessOutput in project intellij-community by JetBrains.
the class PyCondaPackageService method updateChannels.
public void updateChannels() {
final String condaPython = getCondaPython();
if (condaPython == null)
return;
final String path = PythonHelpersLocator.getHelperPath("conda_packaging_tool.py");
final String runDirectory = new File(condaPython).getParent();
final ProcessOutput output = PySdkUtil.getProcessOutput(runDirectory, new String[] { condaPython, path, "channels" });
if (output.getExitCode() != 0)
return;
final List<String> lines = output.getStdoutLines();
for (String line : lines) {
CONDA_CHANNELS.add(line);
}
LAST_TIME_CHECKED = System.currentTimeMillis();
}
Aggregations