use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class HgPushParseTest method testValid.
@Test
public void testValid() {
ProcessOutput processOutput = new ProcessOutput(0);
processOutput.appendStdout(myOutput);
assertEquals(" Wrong commits number for " + myOutput, myExpected, HgPusher.getNumberOfPushedCommits(new HgCommandResult(processOutput)));
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class SvnTestCase method runAndVerifyAcrossLocks.
/**
* @param verifier - if returns true, try again
*/
public static void runAndVerifyAcrossLocks(File workingDir, final TestClientRunner runner, final String[] input, final Processor<ProcessOutput> verifier, final Processor<ProcessOutput> primitiveVerifier) throws IOException {
for (int i = 0; i < 5; i++) {
final ProcessOutput output = runner.runClient("svn", null, workingDir, input);
if (output.getExitCode() == 0) {
if (verifier.process(output)) {
continue;
}
return;
}
if (!StringUtil.isEmptyOrSpaces(output.getStderr())) {
final String stderr = output.getStderr();
/*svn: E155004: Working copy '' locked.
svn: E155004: '' is already locked.
svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)*/
if (stderr.contains("E155004") && stderr.contains("is already locked")) {
continue;
}
}
// will throw assertion
if (verifier.process(output)) {
continue;
}
return;
}
final ProcessOutput output = runner.runClient("svn", null, workingDir, input);
primitiveVerifier.process(output);
}
use of com.intellij.execution.process.ProcessOutput in project intellij-community by JetBrains.
the class CmdInfoClient method execute.
private String execute(@NotNull List<String> parameters, @NotNull File path) throws SvnBindException {
// workaround: separately capture command output - used in exception handling logic to overcome svn 1.8 issue (see below)
final ProcessOutput output = new ProcessOutput();
LineCommandListener listener = new LineCommandAdapter() {
@Override
public void onLineAvailable(String line, Key outputType) {
if (outputType == ProcessOutputTypes.STDOUT) {
output.appendStdout(line);
}
}
};
try {
CommandExecutor command = execute(myVcs, SvnTarget.fromFile(path), SvnCommandName.info, parameters, listener);
return command.getOutput();
} catch (SvnBindException e) {
final String text = StringUtil.notNullize(e.getMessage());
if (text.contains("W155010")) {
// files should be parsed from output
return output.getStdout();
}
// "E155007: '' is not a working copy"
if (text.contains("is not a working copy") && StringUtil.isNotEmpty(output.getStdout())) {
// but the requested info is still in the output except root closing tag
return output.getStdout() + "</info>";
}
throw e;
}
}
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());
}
}
}
Aggregations