Search in sources :

Example 1 with CompilerManagerImpl

use of com.intellij.compiler.CompilerManagerImpl in project intellij-community by JetBrains.

the class CompilerTask method run.

@Override
public void run(@NotNull final ProgressIndicator indicator) {
    myIndicator = indicator;
    final ProjectManager projectManager = ProjectManager.getInstance();
    projectManager.addProjectManagerListener(myProject, myCloseListener = new CloseListener());
    final Semaphore semaphore = ((CompilerManagerImpl) CompilerManager.getInstance(myProject)).getCompilationSemaphore();
    boolean acquired = false;
    try {
        try {
            while (!acquired) {
                acquired = semaphore.tryAcquire(300, TimeUnit.MILLISECONDS);
                if (!acquired && !myWaitForPreviousSession) {
                    return;
                }
                if (indicator.isCanceled()) {
                    // 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();
            projectManager.removeProjectManagerListener(myProject, myCloseListener);
        } finally {
            if (acquired) {
                semaphore.release();
            }
        }
    }
}
Also used : CompilerManagerImpl(com.intellij.compiler.CompilerManagerImpl) Semaphore(java.util.concurrent.Semaphore) ProjectManager(com.intellij.openapi.project.ProjectManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

CompilerManagerImpl (com.intellij.compiler.CompilerManagerImpl)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 Semaphore (java.util.concurrent.Semaphore)1