@Override
 public synchronized void setFraction(double fraction) {
   super.setFraction(fraction);
   if (myOriginal.isRunning()) {
     myOriginal.setFraction(fraction);
   }
 }
 @Override
 public synchronized void setText2(String text) {
   super.setText2(text);
   if (myOriginal.isRunning()) {
     myOriginal.setText2(text);
   }
 }
Пример #3
0
  private void prepareMessageView() {
    if (!myIndicator.isRunning()) {
      return;
    }
    if (myMessageViewWasPrepared.getAndSet(true)) {
      return;
    }

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                final Project project = myProject;
                if (project == null || project.isDisposed()) {
                  return;
                }
                synchronized (myMessageViewLock) {
                  // clear messages from the previous compilation
                  if (myErrorTreeView == null) {
                    // if message view != null, the contents has already been cleared
                    removeAllContents(project, null);
                  }
                }
              }
            });
  }
Пример #4
0
  public synchronized void stop() {
    if (myOriginal.isRunning()) {
      myOriginal.stop();
    } else {
      myStartupAlarm.cancelAllRequests();
    }

    // needed only for correct assertion of !progress.isRunning() in
    // ApplicationImpl.runProcessWithProgressSynchroniously
    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            semaphore.waitFor();
            if (myDialog != null) {
              // System.out.println("myDialog.destroyProcess()");
              myDialog.close(DialogWrapper.OK_EXIT_CODE);
              myDialog = null;
            }
          }
        });

    super.stop(); // should be last to not leaveModal before closing the dialog
    semaphore.up();
  }
  private void removeCommitFromQueue(@NotNull Document document) {
    synchronized (documentsToCommit) {
      ProgressIndicator indicator = document.getUserData(COMMIT_PROGRESS);

      if (indicator != null && indicator.isRunning()) {
        indicator.stop(); // mark document as removed

        log("Removed from queue", document, false);
      }
      // let our thread know that queue must be polled again
      wakeUpQueue();
    }
  }
  @Override
  public synchronized void stop() {
    if (myOriginal.isRunning()) {
      myOriginal.stop();
    } else {
      myStartupAlarm.cancelAllRequests();

      if (!myOriginalStarted && myOriginal instanceof Disposable) {
        // dispose original because start & stop were not called so original progress might not have
        // released its resources
        Disposer.dispose(((Disposable) myOriginal));
      }
    }

    // needed only for correct assertion of !progress.isRunning() in
    // ApplicationImpl.runProcessWithProgressSynchroniously
    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            semaphore.waitFor();
            if (myDialog != null) {
              // System.out.println("myDialog.destroyProcess()");
              myDialog.close(DialogWrapper.OK_EXIT_CODE);
              myDialog = null;
            }
          }
        });

    try {
      super.stop(); // should be last to not leaveModal before closing the dialog
    } finally {
      semaphore.up();
    }
  }
Пример #7
0
  @Override
  public synchronized void initStateFrom(@NotNull final ProgressIndicator indicator) {
    myRunning = indicator.isRunning();
    myCanceled = indicator.isCanceled();
    myFraction = indicator.getFraction();
    myIndeterminate = indicator.isIndeterminate();
    myText = indicator.getText();

    myText2 = indicator.getText2();

    myFraction = indicator.getFraction();

    if (indicator instanceof ProgressIndicatorStacked) {
      ProgressIndicatorStacked stacked = (ProgressIndicatorStacked) indicator;

      myNonCancelableCount = stacked.getNonCancelableCount();

      myTextStack = new Stack<String>(stacked.getTextStack());

      myText2Stack = new Stack<String>(stacked.getText2Stack());

      myFractionStack = new DoubleArrayList(stacked.getFractionStack());
    }
  }
  // returns finish commit Runnable (to be invoked later in EDT), or null on failure
  private Runnable commitUnderProgress(
      @NotNull final Document document,
      @NotNull final Project project,
      final PsiFile excludeFile,
      @NotNull final ProgressIndicator indicator,
      final boolean synchronously,
      @NotNull final Object reason) {
    final List<Processor<Document>> finishRunnables = new SmartList<Processor<Document>>();
    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            if (project.isDisposed()) return;
            final PsiDocumentManagerImpl documentManager =
                (PsiDocumentManagerImpl) PsiDocumentManager.getInstance(project);
            final FileViewProvider viewProvider = documentManager.getCachedViewProvider(document);
            if (viewProvider == null) return;
            final List<PsiFile> psiFiles = viewProvider.getAllFiles();
            for (PsiFile file : psiFiles) {
              if (file.isValid() && file != excludeFile) {
                Processor<Document> finishRunnable =
                    doCommit(document, file, indicator, synchronously, documentManager);
                if (finishRunnable != null) {
                  finishRunnables.add(finishRunnable);
                }
              }
            }
          }
        };
    if (synchronously) {
      ApplicationManager.getApplication().assertWriteAccessAllowed();
      runnable.run();
    } else {
      if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(runnable)) {
        log(
            "Could not start readaction",
            document,
            synchronously,
            ApplicationManager.getApplication().isReadAccessAllowed(),
            Thread.currentThread());
        return null;
      }
    }

    boolean canceled = indicator.isCanceled();
    if (synchronously) {
      assert !canceled;
    }
    if (canceled || !indicator.isRunning()) {
      assert !synchronously;
      return null;
    }
    if (!synchronously
        && !changeCommitStage(
            document,
            CommitStage.QUEUED_TO_COMMIT,
            CommitStage.WAITING_FOR_PSI_APPLY,
            synchronously)) {
      return null;
    }

    Runnable finishRunnable =
        new Runnable() {
          @Override
          public void run() {
            if (project.isDisposed()) return;

            PsiDocumentManagerImpl documentManager =
                (PsiDocumentManagerImpl) PsiDocumentManager.getInstance(project);

            CommitStage stage = getCommitStage(document);
            log("Finish", document, synchronously, project);
            if (stage
                != (synchronously
                    ? CommitStage.ABOUT_TO_BE_SYNC_COMMITTED
                    : CommitStage.WAITING_FOR_PSI_APPLY)) {
              return; // there must be a synchronous commit sneaked in between queued commit and
                      // finish commit, or just document changed meanwhile
            }

            boolean success = false;
            try {
              success =
                  documentManager.finishCommit(document, finishRunnables, synchronously, reason);
              log(
                  "Finished",
                  document,
                  synchronously,
                  success,
                  Arrays.asList(documentManager.getUncommittedDocuments()));
              if (synchronously) {
                assert success;
              }
            } finally {
              if (success) {
                success =
                    synchronously
                        || changeCommitStage(
                            document,
                            CommitStage.WAITING_FOR_PSI_APPLY,
                            CommitStage.COMMITTED,
                            false);
              }
            }
            List<Document> unc = Arrays.asList(documentManager.getUncommittedDocuments());
            log("after call finish commit", document, synchronously, unc, success);
            if (synchronously || success) {
              assert !unc.contains(document) : unc;
            }
            if (!success) {
              // add document back to the queue
              boolean addedBack = queueCommit(project, document, "Re-added back");
              assert addedBack;
            }
          }
        };
    return finishRunnable;
  }
  @Override
  public void run() {
    threadFinished = false;
    while (!isDisposed) {
      try {
        boolean success = false;
        Document document = null;
        Project project = null;
        ProgressIndicator indicator = null;
        try {
          CommitTask task;
          synchronized (documentsToCommit) {
            if (!myEnabled || documentsToCommit.isEmpty()) {
              documentsToCommit.wait();
              continue;
            }
            task = documentsToCommit.pullFirst();
            document = task.document;
            indicator = task.indicator;
            project = task.project;

            log("Pulled", document, false, indicator);

            CommitStage commitStage = getCommitStage(document);
            Document[] uncommitted = null;
            if (commitStage != CommitStage.QUEUED_TO_COMMIT
                || project.isDisposed()
                || !ArrayUtil.contains(
                    document,
                    uncommitted =
                        PsiDocumentManager.getInstance(project).getUncommittedDocuments())) {
              List<Document> documents = uncommitted == null ? null : Arrays.asList(uncommitted);
              log("Abandon and proceeding to next", document, false, commitStage, documents);
              continue;
            }
            if (indicator.isRunning()) {
              useIndicator(indicator);
              document.putUserData(COMMIT_PROGRESS, indicator);
            } else {
              success = true; // document has been marked as removed, e.g. by synchronous commit
            }
          }

          Runnable finishRunnable = null;
          if (!success && !indicator.isCanceled()) {
            try {
              finishRunnable = commit(document, project, null, indicator, false, task.reason);
              success = finishRunnable != null;
              log("DCT.commit returned", document, false, finishRunnable, indicator);
            } finally {
              document.putUserData(COMMIT_PROGRESS, null);
            }
          }

          synchronized (documentsToCommit) {
            if (indicator.isCanceled()) {
              success = false;
            }
            if (success) {
              assert !ApplicationManager.getApplication().isDispatchThread();
              UIUtil.invokeLaterIfNeeded(finishRunnable);
              log(
                  "Invoked later finishRunnable",
                  document,
                  false,
                  success,
                  finishRunnable,
                  indicator);
            }
          }
        } catch (ProcessCanceledException e) {
          cancel(e); // leave queue unchanged
          log("PCE", document, false, e);
          success = false;
        } catch (InterruptedException e) {
          // app must be closing
          int i = 0;
          log("IE", document, false, e);
          cancel(e);
        } catch (Throwable e) {
          LOG.error(e);
          cancel(e);
        }
        synchronized (documentsToCommit) {
          if (!success && indicator.isRunning()) { // running means sync commit has not intervened
            // reset status for queue back successfully
            changeCommitStage(
                document, CommitStage.WAITING_FOR_PSI_APPLY, CommitStage.QUEUED_TO_COMMIT, false);
            changeCommitStage(document, CommitStage.COMMITTED, CommitStage.QUEUED_TO_COMMIT, false);
            doQueue(document, project, CommitStage.QUEUED_TO_COMMIT, "re-added on failure");
          }
        }
      } catch (Throwable e) {
        e.printStackTrace();
        // LOG.error(e);
      }
    }
    threadFinished = true;
    // ping the thread waiting for close
    wakeUpQueue();
    log("Good bye", null, false);
  }
 @Override
 public boolean isRunning() {
   return myIndicator.isRunning();
 }