com.intellij.execution.process.ProcessOutputTypes Java Examples

The following examples show how to use com.intellij.execution.process.ProcessOutputTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeneralToSMTRunnerEventsConvertor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void onTestOutput(@Nonnull final TestOutputEvent testOutputEvent) {
  addToInvokeLater(() -> {
    final String testName = testOutputEvent.getName();
    final String text = testOutputEvent.getText();
    final boolean stdOut = testOutputEvent.isStdOut();
    final String fullTestName = getFullTestName(testName);
    final SMTestProxy testProxy = getProxyByFullTestName(fullTestName);
    if (testProxy == null) {
      logProblem("Test wasn't started! TestOutput event: name = {" + testName + "}, " +
                 "isStdOut = " + stdOut + ", " +
                 "text = {" + text + "}. " +
                 cannotFindFullTestNameMsg(fullTestName));
      return;
    }

    if (stdOut) {
      testProxy.addStdOutput(text, ProcessOutputTypes.STDOUT);
    } else {
      testProxy.addStdErr(text);
    }
  });
}
 
Example #2
Source File: ExternalSystemRunConfiguration.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void detachProcessImpl() {
  myTask.cancel(new ExternalSystemTaskNotificationListenerAdapter() {

    private boolean myResetGreeting = true;

    @Override
    public void onTaskOutput(@Nonnull ExternalSystemTaskId id, @Nonnull String text, boolean stdOut) {
      if (myResetGreeting) {
        notifyTextAvailable("\r", ProcessOutputTypes.SYSTEM);
        myResetGreeting = false;
      }
      notifyTextAvailable(text, stdOut ? ProcessOutputTypes.STDOUT : ProcessOutputTypes.STDERR);
    }
  });
  notifyProcessDetached();
}
 
Example #3
Source File: BuckQueryCommandHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
protected void notifyLines(Key outputType, Iterable<String> lines) {
  super.notifyLines(outputType, lines);
  if (outputType == ProcessOutputTypes.STDOUT) {
    List<String> targetList = new LinkedList<String>();
    for (String outputLine : lines) {
      if (!outputLine.isEmpty()) {
        JsonElement jsonElement = new JsonParser().parse(outputLine);
        if (jsonElement.isJsonArray()) {
          JsonArray targets = jsonElement.getAsJsonArray();

          for (JsonElement target : targets) {
            targetList.add(target.getAsString());
          }
        }
      }
    }
    actionsToExecute.apply(targetList);
  }
}
 
Example #4
Source File: GeneralIdBasedToSMTRunnerEventsConvertor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void onTestOutput(@Nonnull final TestOutputEvent testOutputEvent) {
  addToInvokeLater(() -> {
    Node node = findNode(testOutputEvent);
    if (node == null) {
      logProblem("Test wasn't started! But " + testOutputEvent + "!");
      return;
    }
    SMTestProxy testProxy = node.getProxy();

    if (testOutputEvent.isStdOut()) {
      testProxy.addStdOutput(testOutputEvent.getText(), ProcessOutputTypes.STDOUT);
    } else {
      testProxy.addStdErr(testOutputEvent.getText());
    }
  });
}
 
Example #5
Source File: SMTRunnerConsoleTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testStopCollectingOutput() {
  myResultsViewer.selectAndNotify(myResultsViewer.getTestsRootNode());
  //noinspection NullableProblems
  myConsole.attachToProcess(null);

  myEventsProcessor.onStartTesting();
  myEventsProcessor.onSuiteStarted(new TestSuiteStartedEvent("suite", null));
  final SMTestProxy suite = myEventsProcessor.getCurrentSuite();
  myEventsProcessor.onSuiteFinished(new TestSuiteFinishedEvent("suite"));
  myEventsProcessor.onUncapturedOutput("preved", ProcessOutputTypes.STDOUT);
  myEventsProcessor.onFinishTesting();

  //myResultsViewer.selectAndNotify(suite);
  //the string above doesn't update tree immediately so we should simulate update
  myConsole.getPrinter().updateOnTestSelected(suite);

  //Lets reset printer /clear console/ before selection changed to
  //get after selection event only actual ouptut
  myMockResettablePrinter.resetIfNecessary();

  //myResultsViewer.selectAndNotify(myResultsViewer.getTestsRootNode());
  //the string above doesn't update tree immediately so we should simulate update
  myConsole.getPrinter().updateOnTestSelected(myResultsViewer.getTestsRootNode());

  assertAllOutputs(myMockResettablePrinter, "preved", "","Empty test suite.\n");
}
 
Example #6
Source File: TestComparisionFailedState.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void printOn(Printer printer) {
  printer.print(CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
  printer.mark();

  // Error msg
  printer.printWithAnsiColoring(myErrorMsgPresentation, ProcessOutputTypes.STDERR);

  // Diff link
  myHyperlink.printOn(printer);

  // Stacktrace
  printer.print(CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
  printer.printWithAnsiColoring(myStacktracePresentation, ProcessOutputTypes.STDERR);
  printer.print(CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
}
 
Example #7
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void resolveUsingPantsGoal(
  @NotNull final ExternalSystemTaskId id,
  @NotNull PantsCompileOptionsExecutor executor,
  final ExternalSystemTaskNotificationListener listener,
  @NotNull DataNode<ProjectData> projectDataNode
) {
  final PantsResolver dependenciesResolver = new PantsResolver(executor);
  dependenciesResolver.resolve(
    status -> listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, status)),
    new ProcessAdapter() {
      @Override
      public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
        listener.onTaskOutput(id, event.getText(), outputType == ProcessOutputTypes.STDOUT);
      }
    }
  );
  dependenciesResolver.addInfoTo(projectDataNode);
}
 
Example #8
Source File: OutputLineSplitterTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  mySplitter = new OutputLineSplitter(false) {
    @Override
    protected void onLineAvailable(@Nonnull String text, @Nonnull Key outputType, boolean tcLikeFakeOutput) {
      if (ProcessOutputTypes.STDERR != outputType && ProcessOutputTypes.SYSTEM != outputType) outputType = ProcessOutputTypes.STDOUT;
      synchronized (myOutput) {
        List<String> list = myOutput.get(outputType);
        if (list == null) {
          myOutput.put(outputType, list = new ArrayList<String>());
        }
        list.add(text);
      }
    }
  };
}
 
Example #9
Source File: OutputToGeneralTestsEventsConverterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doCheckOutptut(String outputStr, String expected, boolean splitByLines) {
  final List<String> lines;
  if (splitByLines) {
    lines = StringUtil.split(outputStr, "\n", false);
  } else {
    lines = Collections.singletonList(outputStr);
  }
  for (String line : lines) {
    myOutputConsumer.process(line, ProcessOutputTypes.STDOUT);
  }
  myOutputConsumer.flushBufferOnProcessTermination(0);

  assertEquals(expected, myEnventsProcessor.getOutput());
}
 
Example #10
Source File: BuckJsonCommandHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTextAvailable(String text, Key outputType) {
  if (ProcessOutputTypes.STDOUT.equals(outputType)) {
    mStdoutBuilder.append(text);
  } else if (ProcessOutputTypes.STDERR.equals(outputType)) {
    mStderrBuilder.append(text);
  }
}
 
Example #11
Source File: ThriftOutputConsumer.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
  if (outputType == ProcessOutputTypes.STDERR) {
    stdOutput.append(event.getText());
  }
  else if (outputType == ProcessOutputTypes.STDOUT) {
    stdOutput.append(event.getText());
  }
}
 
Example #12
Source File: TestFailedState.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void printError(@Nonnull final Printer printer, @Nonnull final List<String> errorPresentationText, final boolean setMark) {
  boolean addMark = setMark;
  for (final String errorText : errorPresentationText) {
    if (errorText != null) {
      printer.print(CompositePrintable.NEW_LINE, ConsoleViewContentType.ERROR_OUTPUT);
      if (addMark) {
        printer.mark();
        addMark = false;
      }
      printer.printWithAnsiColoring(errorText, ProcessOutputTypes.STDERR);
    }
  }
}
 
Example #13
Source File: ImportedTestContentHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
  final String currentText = StringUtil.unescapeXml(currentValue.toString());
  final boolean isTestOutput = myCurrentTest == null || TestResultsXmlFormatter.STATUS_PASSED.equals(myStatus) || myErrorOutput;
  if (isTestOutput) {
    currentValue.setLength(0);
  }
  if (TestResultsXmlFormatter.ELEM_SUITE.equals(qName)) {
    myProcessor.onSuiteFinished(new TestSuiteFinishedEvent(mySuites.pop()));
  }
  else if (TestResultsXmlFormatter.ELEM_TEST.equals(qName)) {
    final boolean isError = TestResultsXmlFormatter.STATUS_ERROR.equals(myStatus);
    if (TestResultsXmlFormatter.STATUS_FAILED.equals(myStatus) || isError) {
      myProcessor.onTestFailure(new TestFailedEvent(myCurrentTest, "", currentText, isError, null, null));
    }
    else if (TestResultsXmlFormatter.STATUS_IGNORED.equals(myStatus) || TestResultsXmlFormatter.STATUS_SKIPPED.equals(myStatus)) {
      myProcessor.onTestIgnored(new TestIgnoredEvent(myCurrentTest, "", currentText) {
        @Nonnull
        @Override
        public String getIgnoreComment() {
          return "";
        }
      });
    }
    myProcessor.onTestFinished(new TestFinishedEvent(myCurrentTest, myDuration != null ? Long.parseLong(myDuration) : -1));
    if (!TestResultsXmlFormatter.STATUS_PASSED.equals(myStatus)) {
      currentValue.setLength(0);
    }
    myCurrentTest = null;
  }
  else if (TestResultsXmlFormatter.ELEM_OUTPUT.equals(qName) && !StringUtil.isEmpty(currentText) && isTestOutput) {
    if (myCurrentTest != null) {
      myProcessor.onTestOutput(new TestOutputEvent(myCurrentTest, currentText, !myErrorOutput));
    }
    else {
      myProcessor.onUncapturedOutput(currentText, myErrorOutput ? ProcessOutputTypes.STDERR : ProcessOutputTypes.STDOUT);
    }
  }
}
 
Example #14
Source File: OutputLineSplitterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testReadingColoredStreams() throws Exception {
  final Map<Key, List<String>> written = new ConcurrentHashMap<Key, List<String>>();
  for (final Key each : ALL_TYPES) {
    written.put(each, new ArrayList<String>());
    execute(new Runnable() {
      @Override
      public void run() {
        Random r = new Random();
        for (int i = 0; i < 1000; i++) {
          String s = StringUtil.repeat("A", 100 + r.nextInt(1000)) + "\n";

          if (each == ProcessOutputTypes.STDOUT) {
            mySplitter.process(s, ALL_COLORS.get(r.nextInt(2)));
          }
          else {
            mySplitter.process(s, each);
          }
          written.get(each).add(s);
        }
      }
    }).get();
  }

  mySplitter.flush();

  for (Key eachType : ALL_TYPES) {
    assertOrderedEquals(myOutput.get(eachType), written.get(eachType));
  }
}
 
Example #15
Source File: LogView.java    From logviewer with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public MyProcessingResult processLine(String line) {
    LogCatMessage message = null;
    String continuation = null;
    boolean validContinuation = false;
    try {
        message = AndroidLogcatFormatter.tryParseMessage(line);
        continuation = message == null ? AndroidLogcatFormatter.tryParseContinuation(line) : null;
        validContinuation = continuation != null && this.myPrevHeader != null;
    } catch (Exception ignored) {
    }

    if (message == null && !validContinuation) {
        return new MyProcessingResult(ProcessOutputTypes.STDOUT, canAcceptMessage(line), null);
    } else {
        if (message != null) {
            this.myPrevHeader = message.getHeader();
            this.myCustomApplicable = this.isMessageApplicable(message);
            this.myMessageSoFar.setLength(0);
        }

        boolean isApplicable = this.myCustomApplicable;
        if (!isApplicable) {
            this.myMessageSoFar.append(line);
            this.myMessageSoFar.append('\n');
        }

        Key key = AndroidLogcatUtils.getProcessOutputType(this.myPrevHeader.getLogLevel());
        MyProcessingResult result = new MyProcessingResult(key, isApplicable, this.myMessageSoFar.toString());
        if (isApplicable) {
            this.myMessageSoFar.setLength(0);
        }

        return result;
    }
}
 
Example #16
Source File: SMTRunnerConsoleTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testAddStdOut() {
  mySimpleTest.setPrinter(myMockResettablePrinter);

  mySimpleTest.addStdOutput("one", ProcessOutputTypes.STDOUT);
  assertStdOutput(myMockResettablePrinter, "one");

  mySimpleTest.addStdErr("two");
  assertStdErr(myMockResettablePrinter, "two");

  mySimpleTest.addStdOutput("one", ProcessOutputTypes.STDOUT);
  mySimpleTest.addStdOutput("one", ProcessOutputTypes.STDOUT);
  mySimpleTest.addStdErr("two");
  mySimpleTest.addStdErr("two");
  assertAllOutputs(myMockResettablePrinter, "oneone", "twotwo", "");
}
 
Example #17
Source File: SMTRunnerConsoleTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void assertOnUncapturedOutput() {
  myEventsProcessor.onUncapturedOutput("stdout", ProcessOutputTypes.STDOUT);
  myEventsProcessor.onUncapturedOutput("stderr", ProcessOutputTypes.STDERR);
  myEventsProcessor.onUncapturedOutput("system", ProcessOutputTypes.SYSTEM);

  assertAllOutputs(myMockResettablePrinter, "stdout", "stderr", "system");
}
 
Example #18
Source File: Printer.java    From consulo with Apache License 2.0 5 votes vote down vote up
default void printWithAnsiColoring(@Nonnull String text, @Nonnull Key processOutputType) {
  AnsiEscapeDecoder decoder = new AnsiEscapeDecoder();
  decoder.escapeText(text, ProcessOutputTypes.STDOUT, (text1, attributes) -> {
    ConsoleViewContentType contentType = ConsoleViewContentType.getConsoleViewType(attributes);
    if (contentType == null || contentType == ConsoleViewContentType.NORMAL_OUTPUT) {
      contentType = ConsoleViewContentType.getConsoleViewType(processOutputType);
    }
    print(text1, contentType);
  });
}
 
Example #19
Source File: Printer.java    From consulo with Apache License 2.0 5 votes vote down vote up
default void printWithAnsiColoring(@Nonnull String text, @Nonnull ConsoleViewContentType contentType) {
  AnsiEscapeDecoder decoder = new AnsiEscapeDecoder();
  decoder.escapeText(text, ProcessOutputTypes.STDOUT, (text1, attributes) -> {
    ConsoleViewContentType viewContentType = ConsoleViewContentType.getConsoleViewType(attributes);
    if (viewContentType == null) {
      viewContentType = contentType;
    }
    print(text1, viewContentType);
  });
}
 
Example #20
Source File: OutputListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
  if (outputType == ProcessOutputTypes.STDERR) {
    err.append(event.getText());
  }
  else if (outputType == ProcessOutputTypes.SYSTEM) {
    // skip
  }
  else {
    out.append(event.getText());
  }
}
 
Example #21
Source File: DefaultLogFilterModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public MyProcessingResult processLine(String line) {
  final String type = LogConsolePreferences.getType(line);
  Key contentType = type != null
                    ? LogConsolePreferences.getProcessOutputTypes(type)
                    : (LogConsolePreferences.ERROR.equals(myPrevType) ? ProcessOutputTypes.STDERR : ProcessOutputTypes.STDOUT);
  if (type != null) {
    myPrevType = type;
  }
  final boolean applicable = isApplicable(line);
  return new MyProcessingResult(contentType, applicable, null);
}
 
Example #22
Source File: BaseBuildHandler.java    From CppTools with Apache License 2.0 5 votes vote down vote up
protected final void addLineToOutput(final String line, final boolean error) {
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      consoleBuilder.getProcessHandler().notifyTextAvailable(line + "\n",error ?ProcessOutputTypes.STDERR:ProcessOutputTypes.STDOUT);
    }
  });
}
 
Example #23
Source File: ExecutionOutputParser.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Handles single output line.
 *
 * @param text       execution response
 * @param outputType output type
 */
public void onTextAvailable(@NotNull String text, @NotNull Key outputType) {
    if (outputType == ProcessOutputTypes.SYSTEM) {
        return;
    }

    if (outputType == ProcessOutputTypes.STDERR) {
        errorsReported = true;
        return;
    }

    ContainerUtil.addIfNotNull(outputs, parseOutput(StringUtil.trimEnd(text, "\n").trim()));
}
 
Example #24
Source File: ProcessFinishedListener.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void processTerminated(@NotNull ProcessEvent event) {
    long end = System.currentTimeMillis();
    Object source = event.getSource();
    if (source instanceof ProcessHandler) {
        ((ProcessHandler) source).notifyTextAvailable("Process finished in " + formatBuildTime(end - m_start) + "\n\n", ProcessOutputTypes.SYSTEM);
    }
}
 
Example #25
Source File: BlazeConsoleServiceImpl.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void print(String text, ConsoleViewContentType contentType) {
  Key<?> key =
      contentType == ConsoleViewContentType.ERROR_OUTPUT
          ? ProcessOutputTypes.STDERR
          : ProcessOutputTypes.STDOUT;
  ansiEscapeDecoder.escapeText(text, key, this);
}
 
Example #26
Source File: BlazeXmlToTestEventsConverter.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void processTestSuite(
    GeneralTestEventsProcessor processor,
    BlazeTestEventsHandler eventsHandler,
    Label label,
    @Nullable Kind kind,
    TestSuite suite) {
  if (!hasRunChild(suite)) {
    return;
  }
  // only include the innermost 'testsuite' element
  boolean logSuite = !eventsHandler.ignoreSuite(label, kind, suite);
  if (suite.name != null && logSuite) {
    TestSuiteStarted suiteStarted =
        new TestSuiteStarted(eventsHandler.suiteDisplayName(label, kind, suite.name));
    String locationUrl = eventsHandler.suiteLocationUrl(label, kind, suite.name);
    processor.onSuiteStarted(new TestSuiteStartedEvent(suiteStarted, locationUrl));
  }

  for (TestSuite child : suite.testSuites) {
    processTestSuite(processor, eventsHandler, label, kind, child);
  }
  for (TestSuite decorator : suite.testDecorators) {
    processTestSuite(processor, eventsHandler, label, kind, decorator);
  }
  for (TestCase test : suite.testCases) {
    processTestCase(processor, eventsHandler, label, kind, suite, test);
  }

  if (suite.sysOut != null) {
    processor.onUncapturedOutput(suite.sysOut, ProcessOutputTypes.STDOUT);
  }
  if (suite.sysErr != null) {
    processor.onUncapturedOutput(suite.sysErr, ProcessOutputTypes.STDERR);
  }

  if (suite.name != null && logSuite) {
    processor.onSuiteFinished(
        new TestSuiteFinishedEvent(eventsHandler.suiteDisplayName(label, kind, suite.name)));
  }
}
 
Example #27
Source File: BuckCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
protected void onTextAvailable(final String text, final Key outputType) {
  Iterator<String> lines = LineHandlerHelper.splitText(text).iterator();
  // We only care about STDERR for buck outputs
  if (ProcessOutputTypes.STDERR == outputType) {
    notifyLines(outputType, lines, mStderrLine);
  }
}
 
Example #28
Source File: PantsIntegrationTestCase.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
protected RunResult runWithConfiguration(RunConfiguration configuration) {
  PantsMakeBeforeRun.replaceDefaultMakeWithPantsMake(configuration);
  PantsMakeBeforeRun.setRunConfigurationWorkingDirectory(configuration);
  PantsJUnitRunnerAndConfigurationSettings runnerAndConfigurationSettings =
    new PantsJUnitRunnerAndConfigurationSettings(configuration);
  ExecutionEnvironmentBuilder environmentBuilder =
    ExecutionUtil.createEnvironment(DefaultRunExecutor.getRunExecutorInstance(), runnerAndConfigurationSettings);
  ExecutionEnvironment environment = environmentBuilder.build();

  List<String> output = new ArrayList<>();
  List<String> errors = new ArrayList<>();
  ProcessAdapter processAdapter = new ProcessAdapter() {
    @Override
    public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
      if (outputType == ProcessOutputTypes.STDOUT) {
        output.add(event.getText());
      }
      else if (outputType == ProcessOutputTypes.STDERR) {
        errors.add(event.getText());
      }
    }
  };

  ProgramRunnerUtil.executeConfiguration(environment, false, false);
  OSProcessHandler handler = (OSProcessHandler) environment.getContentToReuse().getProcessHandler();
  handler.addProcessListener(processAdapter);
  assertTrue(handler.waitFor());

  return new RunResult(handler.getExitCode(), output, errors);
}
 
Example #29
Source File: BuckCommandHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Notify listeners for each complete line. Note that in the case of stderr, the last line is
 * saved.
 */
protected void notifyLines(final Key outputType, final Iterable<String> lines) {
  if (outputType == ProcessOutputTypes.STDERR) {
    StringBuilder stderr = new StringBuilder();
    for (String line : lines) {
      // Check if the line has at least one character or digit
      if (CHARACTER_DIGITS_PATTERN.matcher(line).matches()) {
        stderr.append(line);
      }
    }
    if (stderr.length() != 0) {
      buckModule.getBuckEventsConsumer().consumeConsoleEvent(stderr.toString());
    }
  }
}
 
Example #30
Source File: BuckToGeneralTestEventsConverter.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeTestRunStarted(long timestamp) {
  final GeneralTestEventsProcessor processor = getProcessor();
  if (processor == null) {
    return;
  }
  processor.onUncapturedOutput(
      "Test run started at " + DateFormatUtil.formatTimeWithSeconds(new Date(timestamp)) + "\n",
      ProcessOutputTypes.STDOUT);
}