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);
           }
         }
       }
     }
   }
 }
 @NotNull
 private static String getTracesDirectory(RunConfigurationBase configuration) {
   return baseTestDiscoveryPathForProject(configuration.getProject())
       + File.separator
       + configuration.getUniqueID();
 }