@Override
  public void run(@NotNull ProgressIndicator indicator) {
    myIndicator = indicator;
    myIndicator.setIndeterminate(false);

    myBuildViewService.onStart(mySessionId, myStartCompilationStamp, myRestartWork, indicator);
    Semaphore semaphore = ((CompilerManagerImpl)CompilerManager.getInstance(myProject)).getCompilationSemaphore();
    boolean acquired = false;
    try {
      if (!myCompilationStartedAutomatically || !isHeadless()) {
        // Do not acquire the semaphore for the automatically launched headless tasks.
        // Because of that Build UI controls will not be disabled and would allow the user to start build explicitly.
        // Such builds will be queued and executed after any currently running tasks.
        try {
          while (!acquired) {
            acquired = semaphore.tryAcquire(300, TimeUnit.MILLISECONDS);
            if (!acquired && !myWaitForPreviousSession) {
              return;
            }
            if (indicator.isCanceled()) {
              // give up obtaining the semaphore,
              // let compile work begin in order to stop gracefuly on cancel event
              break;
            }
          }
        }
        catch (InterruptedException ignored) {
        }
      }

      if (!isHeadless()) {
        addIndicatorDelegate();
      }
      myCompileWork.run();
    }
    catch (ProcessCanceledException ignored) {
    }
    finally {
      try {
        indicator.stop();
        myBuildViewService.onEnd(mySessionId, myExitStatus, myEndCompilationStamp);
      }
      finally {
        if (acquired) {
          semaphore.release();
        }
      }
    }
  }
@Override
  public void run(@NotNull ProgressIndicator indicator)