PlatformTestUtil.forceCloseProjectWithoutSaving doesn't require EDT

GitOrigin-RevId: fd7075d37b1ea8ba06ae2a3c8cb29080d87f8608
This commit is contained in:
Vladimir Krivosheev
2020-06-11 09:29:16 +03:00
committed by intellij-monorepo-bot
parent 40ed7059dd
commit 3cccd86b13
12 changed files with 38 additions and 41 deletions
@@ -1,5 +1,4 @@
// Copyright 2000-2018 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.scopes;
import com.intellij.ide.scopeView.NamedScopeFilter;
@@ -1,9 +1,9 @@
// 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.externalSystem.util
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.testFramework.runInEdtAndWait
fun Project.use(save: Boolean = false, action: (Project) -> Unit) {
val project = this@use
@@ -11,7 +11,7 @@ fun Project.use(save: Boolean = false, action: (Project) -> Unit) {
action(project)
}
finally {
invokeAndWaitIfNeeded {
runInEdtAndWait {
val projectManager = ProjectManagerEx.getInstanceEx()
if (save) {
projectManager.closeAndDispose(project)
@@ -53,7 +53,7 @@ internal fun Lifetime.createNestedDisposable(debugName: String = "lifetimeToDisp
}
@Suppress("ObjectLiteralToLambda")
fun Disposable.attach(disposable: () -> Unit) {
inline fun Disposable.attach(crossinline disposable: () -> Unit) {
Disposer.register(this, object : Disposable {
override fun dispose() {
disposable()
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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.command.impl;
import com.intellij.ide.IdeBundle;
@@ -10,9 +10,10 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
public class StartMarkAction extends BasicUndoableAction {
public final class StartMarkAction extends BasicUndoableAction {
public static final Key<StartMarkAction> START_MARK_ACTION_KEY = Key.create("current.inplace.refactorings.mark");
private String myCommandName;
private boolean myGlobal;
@@ -54,8 +55,10 @@ public class StartMarkAction extends BasicUndoableAction {
}
@TestOnly
public static void checkCleared(Project project) {
if (project == null) return;
public static void checkCleared(@Nullable Project project) {
if (project == null) {
return;
}
try {
StartMarkAction markAction = project.getUserData(START_MARK_ACTION_KEY);
assert markAction == null : markAction.myDocument;
@@ -91,8 +91,6 @@ private fun openProjectPerformTaskCloseProject(projectDir: Path, task: (Project)
}
}
finally {
runInEdtAndWait {
ProjectManagerEx.getInstanceEx().forceCloseProject(project)
}
PlatformTestUtil.forceCloseProjectWithoutSaving(project)
}
}
@@ -6,8 +6,6 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.module.impl.ProjectLoadingErrorsHeadlessNotifier;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.impl.ProjectManagerImpl;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
@@ -79,7 +77,7 @@ public class ModulesConfigurationTest extends HeavyPlatformTestCase {
if (isSave) {
StateStorageManagerKt.saveComponentManager(project, true);
}
((ProjectManagerImpl)ProjectManager.getInstance()).forceCloseProject(project);
PlatformTestUtil.forceCloseProjectWithoutSaving(project);
}
private void closeOnTearDown(Project project) {
@@ -76,8 +76,7 @@ class ProjectRule(val projectDescriptor: LightProjectDescriptor = LightProjectDe
val errors: MutableList<IllegalStateException> = SmartList()
val tasks: MutableList<ThrowableRunnable<Throwable>> = SmartList()
for (project in openProjects) {
errors.add(IllegalStateException(
"Test project is not disposed: $project;\n created in: ${getCreationPlace(project)}"))
errors.add(IllegalStateException("Test project is not disposed: $project;\n created in: ${getCreationPlace(project)}"))
tasks.add(ThrowableRunnable { projectManager.forceCloseProject(project) })
}
RunAll(tasks).run(errors)
@@ -407,6 +406,16 @@ class DisposableRule : ExternalResource() {
val disposable: Disposable
get() = _disposable.value
@Suppress("ObjectLiteralToLambda")
inline fun register(crossinline disposable: () -> Unit) {
Disposer.register(this.disposable, object : Disposable {
override fun dispose() {
disposable()
}
})
}
override fun after() {
if (_disposable.isInitialized()) {
Disposer.dispose(_disposable.value)
@@ -8,7 +8,6 @@ import com.intellij.openapi.module.ModifiableModuleModel
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.projectRoots.*
import com.intellij.openapi.rd.attach
import com.intellij.openapi.roots.ModuleRootModificationUtil
@@ -61,9 +60,7 @@ class ProjectModelRule(private val forceEnableWorkspaceModel: Boolean = false) :
}
override fun after() {
runInEdtAndWait {
ProjectManagerEx.getInstanceEx().forceCloseProject(project)
}
PlatformTestUtil.forceCloseProjectWithoutSaving(project)
}
}
private val ruleChain = RuleChain(baseProjectDir, projectResource, disposableRule)
@@ -13,7 +13,6 @@ import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.module.ModuleType
import com.intellij.openapi.module.ModuleTypeId
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.project.rootManager
import com.intellij.openapi.rd.attach
import com.intellij.openapi.roots.*
@@ -415,7 +414,7 @@ class ModuleBridgesTest {
WorkspaceModelInitialTestContent.withInitialContent(builder.toStorage()) {
val project = PlatformTestUtil.loadAndOpenProject(iprFile)
Disposer.register(disposableRule.disposable, Disposable {
invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) }
PlatformTestUtil.forceCloseProjectWithoutSaving(project)
})
val module = ModuleManager.getInstance(project).findModuleByName("test")
@@ -451,7 +450,7 @@ class ModuleBridgesTest {
WorkspaceModelInitialTestContent.withInitialContent(builder.toStorage()) {
val project = PlatformTestUtil.loadAndOpenProject(iprFile)
Disposer.register(disposableRule.disposable, Disposable {
invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) }
PlatformTestUtil.forceCloseProjectWithoutSaving(project)
})
val projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project)
@@ -667,6 +666,6 @@ internal fun createEmptyTestProject(temporaryDirectory: TemporaryDirectory, disp
val project = WorkspaceModelInitialTestContent.withInitialContent(WorkspaceEntityStorageBuilder.create()) {
PlatformTestUtil.loadAndOpenProject(projectDir.resolve("testProject.ipr"))
}
disposableRule.disposable.attach { invokeAndWaitIfNeeded { ProjectManagerEx.getInstanceEx().forceCloseProject(project) } }
disposableRule.disposable.attach { PlatformTestUtil.forceCloseProjectWithoutSaving(project) }
return project
}
@@ -2,32 +2,28 @@
package com.intellij.workspaceModel.ide
import com.intellij.openapi.application.impl.ApplicationInfoImpl
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.module.EmptyModuleType
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.module.impl.ModuleManagerComponent
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.rd.attach
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.registry.Registry
import com.intellij.testFramework.ApplicationRule
import com.intellij.testFramework.DisposableRule
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.TemporaryDirectory
import com.intellij.testFramework.rules.ProjectModelRule
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge
import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder
import com.intellij.workspaceModel.storage.bridgeEntities.ModuleDependencyItem
import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity
import com.intellij.workspaceModel.storage.WorkspaceEntityStorageBuilder
import com.intellij.workspaceModel.storage.bridgeEntities.addModuleEntity
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerComponentBridge
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Ignore
@@ -227,10 +223,8 @@ class WorkspaceModelPerformanceTest(private val modulesCount: Int) {
val project = logExecutionTimeInMillis<Project>("Project load") {
PlatformTestUtil.loadAndOpenProject(projectDir)
}
disposableRule.disposable.attach {
invokeAndWaitIfNeeded {
ProjectManagerEx.getInstanceEx().forceCloseProject(project)
}
disposableRule.register {
PlatformTestUtil.forceCloseProjectWithoutSaving(project)
}
return project
}
@@ -23,7 +23,6 @@ import com.intellij.openapi.externalSystem.service.project.settings.FacetConfigu
import com.intellij.openapi.externalSystem.service.project.settings.RunConfigurationImporter;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectManagerEx;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.util.Ref;
@@ -34,6 +33,7 @@ import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
import com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.testFramework.ExtensionTestUtil;
import com.intellij.testFramework.PlatformTestUtil;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings;
@@ -541,7 +541,7 @@ public class GradleSettingsImportingTest extends GradleSettingsImportingTestCase
assertFalse(sourceFolderManager.isDisposed());
}
finally {
application.invokeAndWait(() -> ProjectManagerEx.getInstanceEx().forceCloseProject(project));
PlatformTestUtil.forceCloseProjectWithoutSaving(project);
}
assertTrue(project.isDisposed());
assertTrue(sourceFolderManager.isDisposed());
@@ -1,6 +1,7 @@
// 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 org.jetbrains.index.stubs
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.module.Module
@@ -11,7 +12,6 @@ import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.TestApplicationManager
import com.intellij.util.ui.UIUtil
import java.io.File
import kotlin.system.exitProcess
@@ -54,7 +54,7 @@ abstract class ProjectSdkStubsGenerator {
stubsGenerator.buildStubsForRoots(roots)
}
finally {
UIUtil.invokeAndWaitIfNeeded(Runnable {
ApplicationManager.getApplication().invokeAndWait(Runnable {
ProjectManagerEx.getInstanceEx().forceCloseProject(project)
WriteAction.run<Throwable> {
SdkConfigurationUtil.removeSdk(sdk!!)