JpsProjectTaskRunner: reliably fire notifications when both runner finishes and all tracked async subtasks are completed (fixes IDEA-291331)

GitOrigin-RevId: dac22c52807d55c998a5bc0196250f633a902776
This commit is contained in:
Eugene Zhuravlev
2022-04-01 18:24:58 +02:00
committed by intellij-monorepo-bot
parent 28750296ba
commit ceb89c12c1
2 changed files with 15 additions and 9 deletions

View File

@@ -100,7 +100,7 @@ public final class CompileDriver {
startup(scope, false, false, withModalProgress, callback, null);
}
else {
SwingUtilities.invokeLater(() -> callback.finished(true, 0, 0, DummyCompileContext.create(myProject)));
callback.finished(true, 0, 0, DummyCompileContext.create(myProject));
}
}
@@ -445,7 +445,7 @@ public final class CompileDriver {
final ProgressIndicator indicator = compileContext.getProgressIndicator();
if (indicator.isCanceled() || myProject.isDisposed()) {
if (callback != null) {
SwingUtilities.invokeLater(() -> callback.finished(true, 0, 0, compileContext));
callback.finished(true, 0, 0, compileContext);
}
return;
}

View File

@@ -351,20 +351,26 @@ public final class JpsProjectTaskRunner extends ProjectTaskRunner {
@Override
synchronized public void close() {
myCollectingStopped = true;
if (!myCollectingStopped) {
myCollectingStopped = true;
notifyFinished();
}
}
synchronized private void notifyFinished() {
if (myTaskNotification != null) {
myTaskNotification.finished(new ProjectTaskResult(myAborted, myErrors, myWarnings));
private void notifyFinished() {
if (myCollectingStopped && myNotifications.isEmpty()) {
if (myTaskNotification != null) {
myTaskNotification.finished(new ProjectTaskResult(myAborted, myErrors, myWarnings));
}
myOnFinished.run();
}
myOnFinished.run();
}
synchronized private void appendJpsBuildResult(boolean aborted, int errors, int warnings,
@NotNull CompileContext compileContext,
@NotNull MyCompileStatusNotification notification) {
if (!myNotifications.remove(notification)) {
final boolean notificationRemoved = myNotifications.remove(notification);
if (!notificationRemoved) {
LOG.error("Multiple invocation of the same callback");
}
myErrors += errors;
@@ -373,7 +379,7 @@ public final class JpsProjectTaskRunner extends ProjectTaskRunner {
MyJpsBuildData jpsBuildData = (MyJpsBuildData)JPS_BUILD_DATA_KEY.get(myContext);
jpsBuildData.add(compileContext);
if (myCollectingStopped && myNotifications.isEmpty()) {
if (notificationRemoved) {
notifyFinished();
}
}