コード例 #1
0
 public void writeExternal(final Element element) throws WriteExternalException {
   super.writeExternal(element);
   JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
   writeModule(element);
   DefaultJDOMExternalizer.writeExternal(this, element);
   final Data persistentData = getPersistentData();
   DefaultJDOMExternalizer.writeExternal(persistentData, element);
   EnvironmentVariablesComponent.writeExternal(element, persistentData.getEnvs());
   final String dirName = persistentData.getDirName();
   if (!dirName.isEmpty()) {
     final Element dirNameElement = new Element("dir");
     dirNameElement.setAttribute("value", FileUtil.toSystemIndependentName(dirName));
     element.addContent(dirNameElement);
   }
   final Element patternsElement = new Element(PATTERNS_EL_NAME);
   for (String o : persistentData.getPatterns()) {
     final Element patternElement = new Element(PATTERN_EL_NAME);
     patternElement.setAttribute(TEST_CLASS_ATT_NAME, o);
     patternsElement.addContent(patternElement);
   }
   final String forkMode = getForkMode();
   if (!forkMode.equals("none")) {
     final Element forkModeElement = new Element("fork_mode");
     forkModeElement.setAttribute("value", forkMode);
     element.addContent(forkModeElement);
   }
   element.addContent(patternsElement);
   PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
 }
コード例 #2
0
 public void readExternal(final Element element) throws InvalidDataException {
   PathMacroManager.getInstance(getProject()).expandPaths(element);
   super.readExternal(element);
   JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
   readModule(element);
   DefaultJDOMExternalizer.readExternal(this, element);
   DefaultJDOMExternalizer.readExternal(getPersistentData(), element);
   EnvironmentVariablesComponent.readExternal(element, getPersistentData().getEnvs());
   final Element patternsElement = element.getChild(PATTERNS_EL_NAME);
   if (patternsElement != null) {
     final Set<String> tests = new LinkedHashSet<String>();
     for (Object o : patternsElement.getChildren(PATTERN_EL_NAME)) {
       Element patternElement = (Element) o;
       tests.add(patternElement.getAttributeValue(TEST_CLASS_ATT_NAME));
     }
     myData.setPatterns(tests);
   }
   final Element forkModeElement = element.getChild("fork_mode");
   if (forkModeElement != null) {
     final String mode = forkModeElement.getAttributeValue("value");
     if (mode != null) {
       setForkMode(mode);
     }
   }
   final Element dirNameElement = element.getChild("dir");
   if (dirNameElement != null) {
     final String dirName = dirNameElement.getAttributeValue("value");
     getPersistentData().setDirName(FileUtil.toSystemDependentName(dirName));
   }
 }
コード例 #3
0
 public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
   SettingsEditorGroup<JUnitConfiguration> group = new SettingsEditorGroup<JUnitConfiguration>();
   group.addEditor(
       ExecutionBundle.message("run.configuration.configuration.tab.title"),
       new JUnitConfigurable(getProject()));
   JavaRunConfigurationExtensionManager.getInstance().appendEditors(this, group);
   group.addEditor(
       ExecutionBundle.message("logs.tab.title"), new LogConfigurationPanel<JUnitConfiguration>());
   return group;
 }
コード例 #4
0
 @Override
 public void checkConfiguration() throws RuntimeConfigurationException {
   final TestNGTestObject testObject = TestNGTestObject.fromConfig(this);
   if (testObject != null) {
     testObject.checkConfiguration();
   }
   JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
   ProgramParametersUtil.checkWorkingDirectoryExist(
       this, getProject(), getConfigurationModule().getModule());
   JavaParametersUtil.checkAlternativeJRE(this);
   // TODO add various checks here
 }
コード例 #5
0
  @Override
  public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
    writeModule(element);
    DefaultJDOMExternalizer.writeExternal(this, element);
    DefaultJDOMExternalizer.writeExternal(getPersistantData(), element);
    EnvironmentVariablesComponent.writeExternal(element, getPersistantData().getEnvs());

    Element propertiesElement = element.getChild("properties");

    if (propertiesElement == null) {
      propertiesElement = new Element("properties");
      element.addContent(propertiesElement);
    }

    Map<String, String> properties = getPersistantData().TEST_PROPERTIES;
    for (Map.Entry<String, String> entry : properties.entrySet()) {
      Element property = new Element("property");
      property.setAttribute("name", entry.getKey());
      property.setAttribute("value", entry.getValue());
      propertiesElement.addContent(property);
    }

    Element listenersElement = element.getChild("listeners");
    if (listenersElement == null) {
      listenersElement = new Element("listeners");
      element.addContent(listenersElement);
    }

    List<String> listeners = getPersistantData().TEST_LISTENERS;
    for (String listener : listeners) {
      Element listenerElement = new Element("listener");
      listenerElement.setAttribute("class", listener);
      listenersElement.addContent(listenerElement);
    }
    final Set<String> patterns = getPersistantData().getPatterns();
    if (!patterns.isEmpty()) {
      final Element patternsElement = new Element(PATTERNS_EL_NAME);
      for (String o : patterns) {
        final Element patternElement = new Element(PATTERN_EL_NAME);
        patternElement.setAttribute(TEST_CLASS_ATT_NAME, o);
        patternsElement.addContent(patternElement);
      }
      element.addContent(patternsElement);
    }
  }
コード例 #6
0
  @Override
  public void readExternal(Element element) throws InvalidDataException {
    PathMacroManager.getInstance(getProject()).expandPaths(element);
    super.readExternal(element);
    JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
    readModule(element);
    DefaultJDOMExternalizer.readExternal(this, element);
    DefaultJDOMExternalizer.readExternal(getPersistantData(), element);
    EnvironmentVariablesComponent.readExternal(element, getPersistantData().getEnvs());

    Map<String, String> properties = getPersistantData().TEST_PROPERTIES;
    properties.clear();
    Element propertiesElement = element.getChild("properties");
    if (propertiesElement != null) {
      List<Element> children = propertiesElement.getChildren("property");
      for (Element property : children) {
        properties.put(property.getAttributeValue("name"), property.getAttributeValue("value"));
      }
    }

    List<String> listeners = getPersistantData().TEST_LISTENERS;
    listeners.clear();
    Element listenersElement = element.getChild("listeners");
    if (listenersElement != null) {
      List<Element> children = listenersElement.getChildren("listener");
      for (Element listenerClassName : children) {
        listeners.add(listenerClassName.getAttributeValue("class"));
      }
    }
    final Element patternsElement = element.getChild(PATTERNS_EL_NAME);
    if (patternsElement != null) {
      final LinkedHashSet<String> tests = new LinkedHashSet<String>();
      for (Object o : patternsElement.getChildren(PATTERN_EL_NAME)) {
        Element patternElement = (Element) o;
        tests.add(patternElement.getAttributeValue(TEST_CLASS_ATT_NAME));
      }
      getPersistantData().setPatterns(tests);
    }
  }
コード例 #7
0
  protected ExecutionResult startSMRunner(Executor executor) throws ExecutionException {
    if (!isSmRunnerUsed()) {
      return null;
    }
    getJavaParameters()
        .getVMParametersList()
        .addProperty("idea." + getFrameworkId() + ".sm_runner");

    final RunnerSettings runnerSettings = getRunnerSettings();

    final SMTRunnerConsoleProperties testConsoleProperties =
        getConfiguration().createTestConsoleProperties(executor);
    testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);

    final BaseTestsOutputConsoleView consoleView =
        SMTestRunnerConnectionUtil.createConsole(getFrameworkName(), testConsoleProperties);
    final SMTestRunnerResultsForm viewer = ((SMTRunnerConsoleView) consoleView).getResultsViewer();
    Disposer.register(getConfiguration().getProject(), consoleView);

    final OSProcessHandler handler = createHandler(executor);
    consoleView.attachToProcess(handler);
    handler.addProcessListener(
        new ProcessAdapter() {
          @Override
          public void startNotified(ProcessEvent event) {
            if (getConfiguration().isSaveOutputToFile()) {
              viewer.getRoot().setOutputFilePath(getConfiguration().getOutputFilePath());
            }
          }

          @Override
          public void processTerminated(ProcessEvent event) {
            Runnable runnable =
                new Runnable() {
                  public void run() {
                    viewer.getRoot().flush();
                    deleteTempFiles();
                    clear();
                  }
                };
            UIUtil.invokeLaterIfNeeded(runnable);
            handler.removeProcessListener(this);
          }
        });

    AbstractRerunFailedTestsAction rerunFailedTestsAction =
        testConsoleProperties.createRerunFailedTestsAction(consoleView);
    LOG.assertTrue(rerunFailedTestsAction != null);
    rerunFailedTestsAction.setModelProvider(
        new Getter<TestFrameworkRunningModel>() {
          @Override
          public TestFrameworkRunningModel get() {
            return viewer;
          }
        });

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

    JavaRunConfigurationExtensionManager.getInstance()
        .attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
    return result;
  }
コード例 #8
0
 public void checkConfiguration() throws RuntimeConfigurationException {
   myData.getTestObject(getProject(), this).checkConfiguration();
   JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
 }
コード例 #9
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;
  }