From b35f11759fd75eb80958a665440661d38dc010ed Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 30 Jan 2020 07:49:21 +0100 Subject: [PATCH] ensure that project is disposed under read action in tests (if was closed, then it was disposed not in read action) GitOrigin-RevId: b7ec4d659f33c324f1f3fc7e64faf32d26372a0d --- .../project/impl/ProjectManagerImpl.java | 8 +++++-- .../serviceContainer/MyComponentAdapter.kt | 3 ++- .../ServiceComponentAdapter.kt | 11 +++++---- .../openapi/vcs/impl/VcsInitialization.java | 24 ++++++++++++------- 4 files changed, 31 insertions(+), 15 deletions(-) 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 47248b8559d6..f9c9dca11411 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 @@ -676,9 +676,13 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable { ProjectImpl projectImpl = (ProjectImpl)project; projectImpl.stopServicePreloading(); projectImpl.disposeEarlyDisposable(); - projectImpl.startDispose(); } - ApplicationManager.getApplication().runWriteAction(() -> Disposer.dispose(project)); + ApplicationManager.getApplication().runWriteAction(() -> { + if (project instanceof ProjectImpl) { + ((ProjectImpl)project).startDispose(); + } + Disposer.dispose(project); + }); } return true; } diff --git a/platform/service-container/src/com/intellij/serviceContainer/MyComponentAdapter.kt b/platform/service-container/src/com/intellij/serviceContainer/MyComponentAdapter.kt index 71de40b39a7c..643da878b4b1 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/MyComponentAdapter.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/MyComponentAdapter.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.serviceContainer import com.intellij.diagnostic.ActivityCategory @@ -40,6 +40,7 @@ internal class MyComponentAdapter(private val componentKey: Class<*>, } componentManager.initializeComponent(instance, null) + @Suppress("DEPRECATION") if (instance is BaseComponent) { @Suppress("DEPRECATION") instance.initComponent() diff --git a/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt b/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt index 1f326b8d38fd..38980baec236 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.serviceContainer import com.intellij.diagnostic.ActivityCategory @@ -37,13 +37,16 @@ internal class ServiceComponentAdapter(val descriptor: ServiceDescriptor, // heavy to prevent storages from flushing and blocking FS HeavyProcessLatch.INSTANCE.processStarted(implementationClassName).use { - if (ProgressManager.getGlobalProgressIndicator() == null) { + if (indicator == null) { return createAndInitialize(componentManager, implementationClass) } else { - return ProgressManager.getInstance().computeInNonCancelableSection { - createAndInitialize(componentManager, implementationClass) + // don't use here computeInNonCancelableSection - it is kotlin and no need of such awkward and stack-trace unfriendly methods + var instance: T? = null + ProgressManager.getInstance().executeNonCancelableSection { + instance = createAndInitialize(componentManager, implementationClass) } + return instance!! } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java index 5e2f1bc7cc6a..fac8644f459b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.impl; import com.intellij.diagnostic.ThreadDumper; @@ -8,7 +8,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; -import com.intellij.openapi.progress.impl.ProgressManagerImpl; +import com.intellij.openapi.progress.impl.CoreProgressManager; import com.intellij.openapi.progress.util.StandardProgressIndicatorBase; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.concurrent.Future; @@ -44,7 +43,7 @@ public final class VcsInitialization { } public void startInitialization() { - myFuture = ((ProgressManagerImpl)ProgressManager.getInstance()) + myFuture = ((CoreProgressManager)ProgressManager.getInstance()) .runProcessWithProgressAsynchronously(new Task.Backgroundable(myProject, "VCS Initialization") { @Override public void run(@NotNull ProgressIndicator indicator) { @@ -71,17 +70,26 @@ public final class VcsInitialization { try { final List> list; synchronized (myLock) { - list = myList; // list will not be modified starting from this point - if (myStatus != Status.IDLE) return; // somebody already set status to finished, the project must have been disposed + list = myList; + // somebody already set status to finished, the project must have been disposed + if (myStatus != Status.IDLE) { + return; + } + myStatus = Status.RUNNING; Future future = myFuture; - if (future != null && future.isCancelled() || indicator.isCanceled()) { + if ((future != null && future.isCancelled()) || indicator.isCanceled()) { return; } } - Collections.sort(list, Comparator.comparingInt(o -> o.getFirst().getOrder())); + + list.sort(Comparator.comparingInt(o -> o.getFirst().getOrder())); for (Pair pair : list) { + if (myProject.isDisposed()) { + return; + } + ProgressManager.checkCanceled(); pair.getSecond().run(); }