public MyRunProfile(RunConfigurationBase configuration) {
   super(
       configuration.getProject(),
       configuration.getFactory(),
       ActionsBundle.message("action.RerunFailedTests.text"));
   myConfiguration = configuration;
 }
  private static void processAvailableTraces(RunConfigurationBase configuration) {
    final String tracesDirectory = getTracesDirectory(configuration);
    final TestDiscoveryIndex coverageIndex =
        TestDiscoveryIndex.getInstance(configuration.getProject());
    synchronized (ourTracesLock) {
      final File tracesDirectoryFile = new File(tracesDirectory);
      final File[] testMethodTraces =
          tracesDirectoryFile.listFiles(
              new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                  return name.endsWith(".tr");
                }
              });
      if (testMethodTraces != null) {
        for (File testMethodTrace : testMethodTraces) {
          try {
            coverageIndex.updateFromTestTrace(testMethodTrace);
            FileUtil.delete(testMethodTrace);
          } catch (IOException e) {
            LOG.error("Can not load " + testMethodTrace, e);
          }
        }

        final String[] filesInTracedDirectories = tracesDirectoryFile.list();
        if (filesInTracedDirectories == null || filesInTracedDirectories.length == 0) {
          FileUtil.delete(tracesDirectoryFile);
        }
      }
    }
  }
  @Override
  protected void attachToProcess(
      @NotNull final RunConfigurationBase configuration,
      @NotNull final ProcessHandler handler,
      @Nullable RunnerSettings runnerSettings) {
    if (runnerSettings == null && isApplicableFor(configuration)) {
      final Alarm processTracesAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, null);
      final MessageBusConnection connection = configuration.getProject().getMessageBus().connect();
      connection.subscribe(
          SMTRunnerEventsListener.TEST_STATUS,
          new SMTRunnerEventsAdapter() {
            private List<String> myCompletedMethodNames = new ArrayList<String>();

            @Override
            public void onTestFinished(@NotNull SMTestProxy test) {
              final SMTestProxy.SMRootTestProxy root = test.getRoot();
              if ((root == null || root.getHandler() == handler)) {
                final String fullTestName = test.getLocationUrl();
                if (fullTestName != null
                    && fullTestName.startsWith(JavaTestLocator.TEST_PROTOCOL)) {
                  myCompletedMethodNames.add(
                      ((JavaTestConfigurationBase) configuration).getFrameworkPrefix()
                          + fullTestName.substring(JavaTestLocator.TEST_PROTOCOL.length() + 3));
                  if (myCompletedMethodNames.size() > 50) {
                    final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
                    myCompletedMethodNames.clear();
                    processTracesAlarm.addRequest(
                        new Runnable() {
                          @Override
                          public void run() {
                            processAvailableTraces(configuration, fullTestNames);
                          }
                        },
                        100);
                  }
                }
              }
            }

            @Override
            public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) {
              if (testsRoot.getHandler() == handler) {
                processTracesAlarm.cancelAllRequests();
                processTracesAlarm.addRequest(
                    new Runnable() {
                      @Override
                      public void run() {
                        processAvailableTraces(configuration);
                        Disposer.dispose(processTracesAlarm);
                      }
                    },
                    0);
                connection.disconnect();
              }
            }
          });
    }
  }
 public static void processGatheredCoverage(RunConfigurationBase configuration) {
   final Project project = configuration.getProject();
   if (project.isDisposed()) return;
   final CoverageDataManager coverageDataManager = CoverageDataManager.getInstance(project);
   final CoverageEnabledConfiguration coverageEnabledConfiguration =
       CoverageEnabledConfiguration.getOrCreate(configuration);
   //noinspection ConstantConditions
   final CoverageSuite coverageSuite = coverageEnabledConfiguration.getCurrentCoverageSuite();
   if (coverageSuite != null) {
     ((BaseCoverageSuite) coverageSuite).setConfiguration(configuration);
     coverageDataManager.coverageGathered(coverageSuite);
   }
 }
 private static void processAvailableTraces(
     RunConfigurationBase configuration, String[] fullTestNames) {
   final String tracesDirectory = getTracesDirectory(configuration);
   final TestDiscoveryIndex coverageIndex =
       TestDiscoveryIndex.getInstance(configuration.getProject());
   synchronized (ourTracesLock) {
     for (String fullTestName : fullTestNames) {
       final String className = StringUtil.getPackageName(fullTestName);
       final String methodName = StringUtil.getShortName(fullTestName);
       if (!StringUtil.isEmptyOrSpaces(className) && !StringUtil.isEmptyOrSpaces(methodName)) {
         final File testMethodTrace =
             new File(tracesDirectory, className + "-" + methodName + ".tr");
         if (testMethodTrace.exists()) {
           try {
             coverageIndex.updateFromTestTrace(testMethodTrace);
             FileUtil.delete(testMethodTrace);
           } catch (IOException e) {
             LOG.error("Can not load " + testMethodTrace, e);
           }
         }
       }
     }
   }
 }
 @Override
 public RunConfiguration clone() {
   return myConfiguration.clone();
 }
 @Override
 public SettingsEditor<ConfigurationPerRunnerSettings> getRunnerSettingsEditor(
     final ProgramRunner runner) {
   return myConfiguration.getRunnerSettingsEditor(runner);
 }
 @Override
 public ConfigurationPerRunnerSettings createRunnerSettings(
     final ConfigurationInfoProvider provider) {
   return myConfiguration.createRunnerSettings(provider);
 }
 @Override
 @NotNull
 public ConfigurationType getType() {
   return myConfiguration.getType();
 }
 @Override
 @NotNull
 public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
   return myConfiguration.getConfigurationEditor();
 }
 @NotNull
 private static String getTracesDirectory(RunConfigurationBase configuration) {
   return baseTestDiscoveryPathForProject(configuration.getProject())
       + File.separator
       + configuration.getUniqueID();
 }
 @Override
 public ArrayList<PredefinedLogFile> getPredefinedLogFiles() {
   return myConfiguration.getPredefinedLogFiles();
 }
Esempio n. 13
0
 @Override
 public void writeExternal(Element element) throws WriteExternalException {
   super.writeExternal(element);
   String executable = myRunnerParameters != null ? myRunnerParameters.getExecutableName() : null;
   if (executable != null) element.setAttribute(EXECUTABLE_NAME, executable);
 }
Esempio n. 14
0
 @Override
 public void readExternal(Element element) throws InvalidDataException {
   super.readExternal(element);
   myRunnerParameters = createRunnerParameters();
   myRunnerParameters.setExecutableName(element.getAttributeValue(EXECUTABLE_NAME));
 }
 @Override
 public int getUniqueID() {
   return myConfiguration.getUniqueID();
 }
 @Override
 public LogFileOptions getOptionsForPredefinedLogFile(PredefinedLogFile predefinedLogFile) {
   return myConfiguration.getOptionsForPredefinedLogFile(predefinedLogFile);
 }
 /////////////////////////////////// Delegates
 @Override
 public void readExternal(final Element element) throws InvalidDataException {
   myConfiguration.readExternal(element);
 }
 @Override
 public ArrayList<LogFileOptions> getLogFiles() {
   return myConfiguration.getLogFiles();
 }
 @Override
 public void writeExternal(final Element element) throws WriteExternalException {
   myConfiguration.writeExternal(element);
 }