From f7511fef7aa755af920786b0c6a4b29466aa8d9c Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 5 Apr 2016 13:37:27 +0200 Subject: [PATCH] load application and project inside a transaction --- .../com/intellij/idea/IdeaApplication.java | 29 +++----- .../project/impl/ProjectManagerImpl.java | 66 +++++-------------- 2 files changed, 25 insertions(+), 70 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index bff380a85809..54723f7d05ce 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -342,29 +342,16 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); - app.invokeLater(new Runnable() { - @Override - public void run() { - Project projectFromCommandLine = null; - if (myPerformProjectLoad) { - projectFromCommandLine = loadProjectFromExternalCommandLine(); - } + TransactionGuard.submitTransaction(app, () -> { + Project projectFromCommandLine = myPerformProjectLoad ? loadProjectFromExternalCommandLine() : null; + app.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).appStarting(projectFromCommandLine); - final MessageBus bus = ApplicationManager.getApplication().getMessageBus(); - bus.syncPublisher(AppLifecycleListener.TOPIC).appStarting(projectFromCommandLine); + //noinspection SSBasedInspection + SwingUtilities.invokeLater(PluginManager::reportPluginError); - //noinspection SSBasedInspection - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - PluginManager.reportPluginError(); - } - }); - - //safe for headless and unit test modes - UsageTrigger.trigger(app.getName() + "app.started"); - } - }, ModalityState.NON_MODAL); + //safe for headless and unit test modes + UsageTrigger.trigger(app.getName() + "app.started"); + }); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index 74d9b2050b60..dd9d4c7a35ba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -229,8 +229,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { succeed = true; } finally { - if (!succeed) { - scheduleDispose(project); + if (!succeed && !project.isDefault()) { + TransactionGuard.submitTransaction(project, () -> WriteAction.run(() -> Disposer.dispose(project))); } } } @@ -244,26 +244,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { } } - private static void scheduleDispose(@NotNull final ProjectImpl project) { - if (project.isDefault()) { - return; - } - - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - if (!project.isDisposed()) { - Disposer.dispose(project); - } - } - }); - } - }); - } - @Override @Nullable public Project loadProject(@NotNull String filePath) throws IOException { @@ -347,31 +327,24 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { return false; } - try (AccessToken ignored = TransactionGuard.getInstance().startSynchronousTransaction(TransactionKind.ANY_CHANGE)) { - DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> - DumbService.getInstance(project).queueTask(new DumbModeTask() { - @Override - public void performInDumbMode(@NotNull ProgressIndicator indicator) { - waitForFileWatcher(indicator); - } + DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> + DumbService.getInstance(project).queueTask(new DumbModeTask() { + @Override + public void performInDumbMode(@NotNull ProgressIndicator indicator) { + waitForFileWatcher(indicator); + } - @Override - public String toString() { - return "wait for file watcher"; - } - }) - ); - } + @Override + public String toString() { + return "wait for file watcher"; + } + }) + ); Runnable process = new Runnable() { @Override public void run() { - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - fireProjectOpened(project); - } - }); + TransactionGuard.getInstance().submitTransactionAndWait(() -> fireProjectOpened(project)); StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project); startupManager.runStartupActivities(); @@ -468,12 +441,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { return null; } - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - openProject(project); - } - }); + TransactionGuard.getInstance().submitTransactionAndWait(() -> openProject(project)); return project; } }); @@ -637,7 +605,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { if (checkCanClose && !canClose(project)) return false; final ShutDownTracker shutDownTracker = ShutDownTracker.getInstance(); shutDownTracker.registerStopperThread(Thread.currentThread()); - try (AccessToken ignored = TransactionGuard.getInstance().startSynchronousTransaction(TransactionKind.ANY_CHANGE)) { + try { if (save) { FileDocumentManager.getInstance().saveAllDocuments(); project.save();