cleanup: use ordinary invokeLater and avoid unnecessary synchronization

This commit is contained in:
Eugene Zhuravlev
2014-04-21 10:41:54 +04:00
parent 947d8ab9c5
commit 0285ece4e8
2 changed files with 52 additions and 55 deletions
@@ -71,43 +71,41 @@ public final class ExecutionHandler {
@Nullable final AntBuildMessageView buildMessageViewToReuse,
final DataContext dataContext,
List<BuildFileProperty> 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) {
@@ -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<BuildFileProperty> 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<Boolean> 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<ExecutionEvent> getEventsByClass(Class eventClass) {