From 4ad1033483cf36cead8d52a2ed0ceb41337cc349 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 13 Feb 2013 14:50:00 +0100 Subject: [PATCH] allow isUpToDate() to be called from EDT; return false if another compilation session is in progress --- .../intellij/compiler/impl/CompileDriver.java | 17 +++-------------- .../compiler/progress/CompilerTask.java | 9 +++++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 51747d7dc732..3c88aa7b1a9c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -220,18 +220,8 @@ public class CompileDriver { if (!useOutOfProcessBuild()) { scope = addAdditionalRoots(scope, ALL_EXCEPT_SOURCE_PROCESSING); } - else { - final Application app = ApplicationManager.getApplication(); - if (!app.isUnitTestMode()) { - final boolean isDispatchThread = app.isDispatchThread(); - LOG.assertTrue(!isDispatchThread, "Calling isUpToDate() from Event Dispatch Thread may cause deadlocks"); - if (isDispatchThread) { - return false; - } - } - } - final CompilerTask task = new CompilerTask(myProject, "Classes up-to-date check", true, false); + final CompilerTask task = new CompilerTask(myProject, "Classes up-to-date check", true, false, false); final DependencyCache cache = useOutOfProcessBuild()? null : createDependencyCache(); final CompileContextImpl compileContext = new CompileContextImpl(myProject, task, scope, cache, true, false); @@ -640,7 +630,7 @@ public class CompileDriver { final String contentName = forceCompile ? CompilerBundle.message("compiler.content.name.compile") : CompilerBundle.message("compiler.content.name.make"); - final CompilerTask compileTask = new CompilerTask(myProject, contentName, ApplicationManager.getApplication().isUnitTestMode(), true); + final CompilerTask compileTask = new CompilerTask(myProject, contentName, ApplicationManager.getApplication().isUnitTestMode(), true, true); StatusBar.Info.set("", myProject, "Compiler"); if (useExtProcessBuild) { @@ -2282,8 +2272,7 @@ public class CompileDriver { } public void executeCompileTask(final CompileTask task, final CompileScope scope, final String contentName, final Runnable onTaskFinished) { - final CompilerTask progressManagerTask = - new CompilerTask(myProject, contentName, false, false); + final CompilerTask progressManagerTask = new CompilerTask(myProject, contentName, false, false, true); final CompileContextImpl compileContext = new CompileContextImpl(myProject, progressManagerTask, scope, null, false, false); FileDocumentManager.getInstance().saveAllDocuments(); diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index 527b627b0172..9c430d8a3ad9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -80,6 +80,7 @@ public class CompilerTask extends Task.Backgroundable { private final String myContentName; private final boolean myHeadlessMode; private final boolean myForceAsyncExecution; + private final boolean myWaitForPreviousSession; private int myErrorCount = 0; private int myWarningCount = 0; private boolean myMessagesAutoActivated = false; @@ -89,11 +90,12 @@ public class CompilerTask extends Task.Backgroundable { private final AtomicBoolean myMessageViewWasPrepared = new AtomicBoolean(false); private Runnable myRestartWork; - public CompilerTask(@NotNull Project project, String contentName, final boolean headlessMode, boolean forceAsync) { + public CompilerTask(@NotNull Project project, String contentName, final boolean headlessMode, boolean forceAsync, boolean waitForPreviousSession) { super(project, contentName); myContentName = contentName; myHeadlessMode = headlessMode; myForceAsyncExecution = forceAsync; + myWaitForPreviousSession = waitForPreviousSession; } public void setContentIdKey(Key> contentIdKey) { @@ -136,7 +138,10 @@ public class CompilerTask extends Task.Backgroundable { try { while (!acquired) { - acquired = semaphore.tryAcquire(500, TimeUnit.MILLISECONDS); + 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