mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
Disable WorkspaceEntitiesLifecycleActivity in unit tests by default
(cherry picked from commit 73934f5796d84186576ecc8b755f033dd24a7f9b) GitOrigin-RevId: 03ca9b870763aead7cfea780c1a081db8ac2966f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0ab15c65e6
commit
cb73ccd751
@@ -87,7 +87,9 @@ import com.intellij.util.io.PersistentMapImpl;
|
|||||||
import com.intellij.util.ref.GCUtil;
|
import com.intellij.util.ref.GCUtil;
|
||||||
import com.intellij.util.ref.GCWatcher;
|
import com.intellij.util.ref.GCWatcher;
|
||||||
import com.intellij.util.ui.UIUtil;
|
import com.intellij.util.ui.UIUtil;
|
||||||
|
import com.intellij.workspaceModel.ide.impl.WorkspaceEntityLifecycleSupporterUtils;
|
||||||
import com.siyeh.ig.JavaOverridingMethodUtil;
|
import com.siyeh.ig.JavaOverridingMethodUtil;
|
||||||
|
import kotlin.Unit;
|
||||||
import org.intellij.lang.annotations.Language;
|
import org.intellij.lang.annotations.Language;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -547,7 +549,7 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
myFixture.addFileToProject("foo/Foo" + i + ".java", "package foo; class Foo" + i + " {}").getVirtualFile();
|
myFixture.addFileToProject("foo/Foo" + i + ".java", "package foo; class Foo" + i + " {}").getVirtualFile();
|
||||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo" + i, scope));
|
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo" + i, scope));
|
||||||
String newName = "Bar" + i + ".java";
|
String newName = "Bar" + i + ".java";
|
||||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?,IOException>) () -> {
|
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
||||||
file.rename(this, newName);
|
file.rename(this, newName);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -602,7 +604,7 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
staticMethod(null);
|
staticMethod(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
final VirtualFile vFile = myFixture.configureByText(JavaFileType.INSTANCE, text0).getVirtualFile();
|
final VirtualFile vFile = myFixture.configureByText(JavaFileType.INSTANCE, text0).getVirtualFile();
|
||||||
long stamp = FileBasedIndex.getInstance().getIndexModificationStamp(JavaNullMethodArgumentIndex.INDEX_ID, getProject());
|
long stamp = FileBasedIndex.getInstance().getIndexModificationStamp(JavaNullMethodArgumentIndex.INDEX_ID, getProject());
|
||||||
JavaNullMethodArgumentIndex.MethodCallData data = new JavaNullMethodArgumentIndex.MethodCallData("staticMethod", 0);
|
JavaNullMethodArgumentIndex.MethodCallData data = new JavaNullMethodArgumentIndex.MethodCallData("staticMethod", 0);
|
||||||
@@ -617,7 +619,7 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
staticMethod(null);
|
staticMethod(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
WriteAction.run(() -> VfsUtil.saveText(vFile, text));
|
WriteAction.run(() -> VfsUtil.saveText(vFile, text));
|
||||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||||
|
|
||||||
@@ -1438,7 +1440,8 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test_indexes_should_be_wiped_after_scratch_removal() throws StorageException, IOException {
|
public void test_indexes_should_be_wiped_after_scratch_removal() {
|
||||||
|
WorkspaceEntityLifecycleSupporterUtils.INSTANCE.withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(getProject(), () -> {
|
||||||
final VirtualFile file =
|
final VirtualFile file =
|
||||||
ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||||
int fileId = ((VirtualFileWithId)file).getId();
|
int fileId = ((VirtualFileWithId)file).getId();
|
||||||
@@ -1448,6 +1451,7 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
ID<Integer, Void> trigramId = TrigramIndex.INDEX_ID;
|
ID<Integer, Void> trigramId = TrigramIndex.INDEX_ID;
|
||||||
|
|
||||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||||
|
try {
|
||||||
assertNotEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
assertNotEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||||
|
|
||||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
||||||
@@ -1457,8 +1461,15 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||||
assertEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
assertEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||||
}
|
}
|
||||||
|
catch (StorageException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void test_requestReindex() {
|
public void test_requestReindex() {
|
||||||
|
WorkspaceEntityLifecycleSupporterUtils.INSTANCE.withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(getProject(), () -> {
|
||||||
VirtualFile file = ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
VirtualFile file = ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||||
deleteOnTearDown(file);
|
deleteOnTearDown(file);
|
||||||
|
|
||||||
@@ -1472,6 +1483,8 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
|||||||
|
|
||||||
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
||||||
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
||||||
|
return Unit.INSTANCE;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test_modified_excluded_file_not_present_in_index() throws StorageException, IOException {
|
public void test_modified_excluded_file_not_present_in_index() throws StorageException, IOException {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package com.intellij.workspaceModel.ide.impl
|
package com.intellij.workspaceModel.ide.impl
|
||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.extensions.ExtensionNotApplicableException
|
||||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||||
import com.intellij.openapi.extensions.PluginDescriptor
|
import com.intellij.openapi.extensions.PluginDescriptor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -13,13 +14,13 @@ import kotlinx.coroutines.coroutineScope
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
private class WorkspaceEntitiesLifecycleActivity : ProjectActivity {
|
private class WorkspaceEntitiesLifecycleActivity : ProjectActivity {
|
||||||
override suspend fun execute(project: Project) {
|
init {
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
//todo GoGutterMarkerTest failed without it - ideally, we should setup project in tests without this activity
|
throw ExtensionNotApplicableException.create()
|
||||||
WorkspaceEntityLifecycleSupporterUtils.ensureAllEntitiesInWorkspaceAreAsProvidersDefined(project)
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun execute(project: Project) {
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
WorkspaceEntityLifecycleSupporter.EP_NAME.addExtensionPointListener(this, object : ExtensionPointListener<WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>> {
|
WorkspaceEntityLifecycleSupporter.EP_NAME.addExtensionPointListener(this, object : ExtensionPointListener<WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>> {
|
||||||
override fun extensionAdded(extension: WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>, pluginDescriptor: PluginDescriptor) {
|
override fun extensionAdded(extension: WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>, pluginDescriptor: PluginDescriptor) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
package com.intellij.workspaceModel.ide.impl
|
package com.intellij.workspaceModel.ide.impl
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.backgroundWriteAction
|
import com.intellij.openapi.application.backgroundWriteAction
|
||||||
import com.intellij.openapi.components.serviceAsync
|
import com.intellij.openapi.components.serviceAsync
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
@@ -12,6 +13,7 @@ import com.intellij.platform.workspace.storage.MutableEntityStorage
|
|||||||
import com.intellij.platform.workspace.storage.WorkspaceEntity
|
import com.intellij.platform.workspace.storage.WorkspaceEntity
|
||||||
import com.intellij.platform.workspace.storage.toBuilder
|
import com.intellij.platform.workspace.storage.toBuilder
|
||||||
import org.jetbrains.annotations.ApiStatus
|
import org.jetbrains.annotations.ApiStatus
|
||||||
|
import org.jetbrains.annotations.TestOnly
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
object WorkspaceEntityLifecycleSupporterUtils {
|
object WorkspaceEntityLifecycleSupporterUtils {
|
||||||
@@ -35,6 +37,49 @@ object WorkspaceEntityLifecycleSupporterUtils {
|
|||||||
builderRef.get()?.let { backgroundWriteAction { writeBuilder(workspaceModel, it) } }
|
builderRef.get()?.let { backgroundWriteAction { writeBuilder(workspaceModel, it) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
fun withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project, block: () -> Unit) {
|
||||||
|
setUpAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project)
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tearDownAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
fun setUpAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project) {
|
||||||
|
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||||
|
val snapshot = workspaceModel.currentSnapshot
|
||||||
|
val builderRef = Ref<MutableEntityStorage>()
|
||||||
|
|
||||||
|
WorkspaceEntityLifecycleSupporter.EP_NAME.forEachExtensionSafe { provider ->
|
||||||
|
ensureInitialized(project = project, provider = provider, snapshot = snapshot, builderRef = builderRef)
|
||||||
|
}
|
||||||
|
builderRef.get()?.let { ApplicationManager.getApplication().runWriteAction { writeBuilder(workspaceModel, it) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
|
fun tearDownAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project) {
|
||||||
|
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||||
|
val snapshot = workspaceModel.currentSnapshot
|
||||||
|
val builderRef = Ref<MutableEntityStorage>()
|
||||||
|
WorkspaceEntityLifecycleSupporter.EP_NAME.forEachExtensionSafe { provider ->
|
||||||
|
val entitiesIterator = snapshot.entities(provider.getEntityClass()).iterator()
|
||||||
|
if (entitiesIterator.hasNext()) {
|
||||||
|
var builder = builderRef.get()
|
||||||
|
if (builder == null) {
|
||||||
|
builder = snapshot.toBuilder()
|
||||||
|
builderRef.set(builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
entitiesIterator.forEach { builder.removeEntity(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builderRef.get()?.let { ApplicationManager.getApplication().runWriteAction { writeBuilder(workspaceModel, it) } }
|
||||||
|
}
|
||||||
|
|
||||||
private fun writeBuilder(workspaceModel: WorkspaceModel, builder: MutableEntityStorage) {
|
private fun writeBuilder(workspaceModel: WorkspaceModel, builder: MutableEntityStorage) {
|
||||||
workspaceModel.updateProjectModel("ConstantEntitiesCheckActivity") {
|
workspaceModel.updateProjectModel("ConstantEntitiesCheckActivity") {
|
||||||
it.applyChangesFrom(builder)
|
it.applyChangesFrom(builder)
|
||||||
|
|||||||
Reference in New Issue
Block a user