From 0285ece4e89ae8ffbdaf8da7a14b3c5e614ca7fb Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 21 Apr 2014 10:39:53 +0400 Subject: [PATCH] cleanup: use ordinary invokeLater and avoid unnecessary synchronization --- .../config/execution/ExecutionHandler.java | 62 +++++++++---------- .../ant/config/impl/AntConfigurationImpl.java | 45 +++++++------- 2 files changed, 52 insertions(+), 55 deletions(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java index d6974918378d..623b749af79e 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/execution/ExecutionHandler.java @@ -71,43 +71,41 @@ public final class ExecutionHandler { @Nullable final AntBuildMessageView buildMessageViewToReuse, final DataContext dataContext, List additionalProperties, @NotNull final AntBuildListener antBuildListener) { - FileDocumentManager.getInstance().saveAllDocuments(); - final AntCommandLineBuilder builder = new AntCommandLineBuilder(); final AntBuildMessageView messageView; final GeneralCommandLine commandLine; - synchronized (builder) { - Project project = buildFile.getProject(); + final Project project = buildFile.getProject(); + try { + FileDocumentManager.getInstance().saveAllDocuments(); + final AntCommandLineBuilder builder = new AntCommandLineBuilder(); - try { - builder.setBuildFile(buildFile.getAllOptions(), VfsUtil.virtualToIoFile(buildFile.getVirtualFile())); - builder.calculateProperties(dataContext, additionalProperties); - builder.addTargets(targets); + builder.setBuildFile(buildFile.getAllOptions(), VfsUtil.virtualToIoFile(buildFile.getVirtualFile())); + builder.calculateProperties(dataContext, additionalProperties); + builder.addTargets(targets); - builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset()); + builder.getCommandLine().setCharset(EncodingProjectManager.getInstance(buildFile.getProject()).getDefaultCharset()); - messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets); - commandLine = CommandLineBuilder.createFromJavaParameters(builder.getCommandLine()); - messageView.setBuildCommandLine(commandLine.getCommandLineString()); - } - catch (RunCanceledException e) { - e.showMessage(project, AntBundle.message("run.ant.erorr.dialog.title")); - antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); - return; - } - catch (CantRunException e) { - ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.erorr.dialog.title"), project); - antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); - return; - } - catch (Macro.ExecutionCancelledException e) { - antBuildListener.buildFinished(AntBuildListener.ABORTED, 0); - return; - } - catch (Throwable e) { - antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); - LOG.error(e); - return; - } + messageView = prepareMessageView(buildMessageViewToReuse, buildFile, targets); + commandLine = CommandLineBuilder.createFromJavaParameters(builder.getCommandLine()); + messageView.setBuildCommandLine(commandLine.getCommandLineString()); + } + catch (RunCanceledException e) { + e.showMessage(project, AntBundle.message("run.ant.erorr.dialog.title")); + antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); + return; + } + catch (CantRunException e) { + ExecutionErrorDialog.show(e, AntBundle.message("cant.run.ant.erorr.dialog.title"), project); + antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); + return; + } + catch (Macro.ExecutionCancelledException e) { + antBuildListener.buildFinished(AntBuildListener.ABORTED, 0); + return; + } + catch (Throwable e) { + antBuildListener.buildFinished(AntBuildListener.FAILED_TO_RUN, 0); + LOG.error(e); + return; } new Task.Backgroundable(buildFile.getProject(), AntBundle.message("ant.build.progress.dialog.title"), true) { diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java index dfa7a592796c..3bdcbeb150eb 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntConfigurationImpl.java @@ -32,7 +32,6 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; @@ -644,32 +643,32 @@ public class AntConfigurationImpl extends AntConfigurationBase implements Persis public static boolean executeTargetSynchronously(final DataContext dataContext, final AntBuildTarget target, final List additionalProperties) { final Semaphore targetDone = new Semaphore(); - final boolean[] result = new boolean[1]; - try { - ApplicationManager.getApplication().invokeAndWait(new Runnable() { - - public void run() { - Project project = CommonDataKeys.PROJECT.getData(dataContext); + targetDone.down(); + final Ref result = Ref.create(Boolean.FALSE); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || project.isDisposed()) { - result[0] = false; - return; + targetDone.up(); + } + else { + target.run(dataContext, additionalProperties, new AntBuildListener() { + public void buildFinished(int state, int errorCount) { + result.set((state == AntBuildListener.FINISHED_SUCCESSFULLY) && (errorCount == 0)); + targetDone.up(); + } + }); } - targetDone.down(); - target.run(dataContext, additionalProperties, new AntBuildListener() { - public void buildFinished(int state, int errorCount) { - result[0] = (state == AntBuildListener.FINISHED_SUCCESSFULLY) && (errorCount == 0); - targetDone.up(); - } - }); } - }, ModalityState.NON_MODAL); - } - catch (Exception e) { - LOG.error(e); - return false; - } + catch (Throwable e) { + targetDone.up(); + LOG.error(e); + } + } + }); targetDone.waitFor(); - return result[0]; + return result.get(); } private List getEventsByClass(Class eventClass) {