Пример #1
0
  @Override
  protected JUnitProcessHandler createHandler(Executor executor) throws ExecutionException {
    final JUnitProcessHandler handler = super.createHandler(executor);
    final SearchForTestsTask[] tasks = new SearchForTestsTask[1];
    handler.addProcessListener(
        new ProcessAdapter() {
          @Override
          public void startNotified(ProcessEvent event) {
            super.startNotified(event);
            tasks[0] = (SearchForTestsTask) findTests();
          }

          @Override
          public void processTerminated(ProcessEvent event) {
            handler.removeProcessListener(this);
            if (mySearchForTestsIndicator != null && !mySearchForTestsIndicator.isCanceled()) {
              if (tasks[0] != null) {
                tasks[0].finish();
              }
            }
          }
        });
    return handler;
  }
Пример #2
0
 protected JUnitProcessHandler createHandler(Executor executor) throws ExecutionException {
   appendForkInfo(executor);
   return JUnitProcessHandler.runCommandLine(
       CommandLineBuilder.createFromJavaParameters(myJavaParameters, myProject, true));
 }
Пример #3
0
  @Override
  public ExecutionResult execute(final Executor executor, @NotNull final ProgramRunner runner)
      throws ExecutionException {
    final JUnitProcessHandler handler = createHandler(executor);
    final RunnerSettings runnerSettings = getRunnerSettings();
    JavaRunConfigurationExtensionManager.getInstance()
        .attachExtensionsToProcess(myConfiguration, handler, runnerSettings);
    final TestProxy unboundOutputRoot = new TestProxy(new RootTestInfo());
    final JUnitConsoleProperties consoleProperties =
        new JUnitConsoleProperties(myConfiguration, executor);
    final JUnitTreeConsoleView consoleView =
        new JUnitTreeConsoleView(
            consoleProperties, runnerSettings, getConfigurationSettings(), unboundOutputRoot);
    consoleView.initUI();
    consoleView.attachToProcess(handler);
    unboundOutputRoot.setPrinter(consoleView.getPrinter());
    Disposer.register(consoleView, unboundOutputRoot);
    final TestsPacketsReceiver packetsReceiver =
        new TestsPacketsReceiver(consoleView, unboundOutputRoot) {
          @Override
          public void notifyStart(TestProxy root) {
            if (!isRunning()) return;
            super.notifyStart(root);
            unboundOutputRoot.addChild(root);
            if (myConfiguration.isSaveOutputToFile()) {
              unboundOutputRoot.setOutputFilePath(myConfiguration.getOutputFilePath());
            }
            final JUnitRunningModel model = getModel();
            if (model != null) {
              handler.getOut().setDispatchListener(model.getNotifier());
              Disposer.register(
                  model,
                  new Disposable() {
                    @Override
                    public void dispose() {
                      handler.getOut().setDispatchListener(DispatchListener.DEAF);
                    }
                  });
              consoleView.attachToModel(model);
            }
          }
        };

    final DeferredActionsQueue queue = new DeferredActionsQueueImpl();
    handler.getOut().setPacketDispatcher(packetsReceiver, queue);
    handler.getErr().setPacketDispatcher(packetsReceiver, queue);

    handler.addProcessListener(
        new ProcessAdapter() {
          private boolean myStarted = false;

          @Override
          public void startNotified(ProcessEvent event) {
            myStarted = true;
          }

          @Override
          public void processTerminated(ProcessEvent event) {
            handler.removeProcessListener(this);
            if (myTempFile != null) {
              FileUtil.delete(myTempFile);
            }
            if (myListenersFile != null) {
              FileUtil.delete(myListenersFile);
            }
            IJSwingUtilities.invoke(
                new Runnable() {
                  @Override
                  public void run() {
                    try {
                      unboundOutputRoot.flush();
                      packetsReceiver.checkTerminated();
                      final JUnitRunningModel model = packetsReceiver.getModel();
                      notifyByBalloon(model, myStarted, consoleProperties);
                    } finally {
                      if (ApplicationManager.getApplication().isUnitTestMode()) {
                        Disposer.dispose(consoleView);
                      }
                    }
                  }
                });
          }

          @Override
          public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            final String text = event.getText();
            final ConsoleViewContentType consoleViewType =
                ConsoleViewContentType.getConsoleViewType(outputType);
            final Printable printable =
                new Printable() {
                  @Override
                  public void printOn(final Printer printer) {
                    printer.print(text, consoleViewType);
                  }
                };
            final Extractor extractor;
            if (consoleViewType == ConsoleViewContentType.ERROR_OUTPUT
                || consoleViewType == ConsoleViewContentType.SYSTEM_OUTPUT) {
              extractor = handler.getErr();
            } else {
              extractor = handler.getOut();
            }
            extractor.getEventsDispatcher().processOutput(printable);
          }
        });

    if (ApplicationManager.getApplication().isUnitTestMode()) {
      return new DefaultExecutionResult(null, handler);
    }

    final RerunFailedTestsAction rerunFailedTestsAction = new RerunFailedTestsAction(consoleView);
    rerunFailedTestsAction.init(consoleProperties, myEnvironment);
    rerunFailedTestsAction.setModelProvider(
        new Getter<TestFrameworkRunningModel>() {
          @Override
          public TestFrameworkRunningModel get() {
            return packetsReceiver.getModel();
          }
        });

    final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
    result.setRestartActions(rerunFailedTestsAction);
    return result;
  }