Search in sources :

Example 1 with ProcessOutput

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)));
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) ProcessOutput(com.intellij.execution.process.ProcessOutput) Test(org.junit.Test)

Example 2 with 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);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 3 with ProcessOutput

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;
    }
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) Key(com.intellij.openapi.util.Key)

Example 4 with ProcessOutput

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;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ProcessOutput

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());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) TextRange(com.intellij.openapi.util.TextRange) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) ProcessOutput(com.intellij.execution.process.ProcessOutput) Course(com.jetbrains.edu.learning.courseFormat.Course) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) File(java.io.File) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler) EduDocumentListener(com.jetbrains.edu.learning.core.EduDocumentListener)

Aggregations

ProcessOutput (com.intellij.execution.process.ProcessOutput)66 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 File (java.io.File)23 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)16 Nullable (org.jetbrains.annotations.Nullable)13 NotNull (org.jetbrains.annotations.NotNull)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Project (com.intellij.openapi.project.Project)5 PsiFile (com.intellij.psi.PsiFile)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)4 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)3 Notification (com.intellij.notification.Notification)3 Document (com.intellij.openapi.editor.Document)3 Task (com.intellij.openapi.progress.Task)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3