ensure that project is disposed under read action in tests (if was closed, then it was disposed not in read action)

GitOrigin-RevId: b7ec4d659f33c324f1f3fc7e64faf32d26372a0d
This commit is contained in:
Vladimir Krivosheev
2020-01-30 07:49:21 +01:00
committed by intellij-monorepo-bot
parent 339e4811ed
commit b35f11759f
4 changed files with 31 additions and 15 deletions

View File

@@ -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;
}

View File

@@ -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()

View File

@@ -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<T, RuntimeException> {
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!!
}
}
}

View File

@@ -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<Pair<VcsInitObject, Runnable>> 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<VcsInitObject, Runnable> pair : list) {
if (myProject.isDisposed()) {
return;
}
ProgressManager.checkCanceled();
pair.getSecond().run();
}