From 1b9a105d48bdfe8d07912058a858b5376466b8f7 Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Fri, 28 Apr 2023 10:24:58 +0300 Subject: [PATCH] [Workspace Model] Tests reformat GitOrigin-RevId: 5cca3aa7a719ce4460595b43d67cec10fbb38a5d --- .../ide/ImlReplaceBySourceTest.kt | 4 +- .../ide/ImlSerializationTest.kt | 2 +- .../ide/JpsProjectLoadingListenerTest.kt | 2 +- .../workspaceModel/ide/ModuleBridgesTest.kt | 34 +-- .../ide/ModuleLibraryBridgeTest.kt | 10 +- .../ide/ModuleTestPropertiesTest.kt | 7 +- .../ide/ProjectLibraryBridgeTest.kt | 10 +- .../workspaceModel/ide/ReplaceBySourceTest.kt | 7 +- .../workspaceModel/ide/TestModuleComponent.kt | 2 +- .../ide/VirtualFileUrlManagerTest.kt | 6 +- .../workspaceModel/ide/WorkspaceCacheTest.kt | 12 +- .../ide/WorkspaceModelAsyncTest.kt | 7 +- .../ide/WorkspaceModelMemoryDumper.kt | 4 +- .../ide/WorkspaceModelPerformanceTest.kt | 35 +-- .../DelayedProjectSynchronizerTest.kt | 21 +- .../JpsGlobalEntitiesLoaderTest.kt | 2 +- .../JpsGlobalEntitiesSyncTest.kt | 12 +- .../serialization/JpsIncorrectDataLoading.kt | 22 +- .../JpsProjectEntitiesLoaderTest.kt | 15 +- .../serialization/JpsProjectReloadingTest.kt | 38 +-- .../JpsProjectSaveAfterChangesTest.kt | 27 ++- .../JpsProjectSaveAllEntitiesTest.kt | 3 +- .../JpsSplitModuleAndContentRootTest.kt | 48 ++-- .../impl/jps/serialization/jpsTestUtils.kt | 65 ++++-- .../storage/tests/AbstractEntitiesTest.kt | 2 +- .../storage/tests/AddChildrenTest.kt | 1 - .../tests/CircularDependencyProhibitedTest.kt | 1 - .../storage/tests/EntitySourceIndexTest.kt | 216 +++++++++--------- .../EntityWithSymbolicIdInPStorageTest.kt | 2 +- .../storage/tests/ExtensionTest.kt | 6 +- .../tests/ExternalEntityMappingTest.kt | 2 +- .../tests/GeneratedCodeVersionsTest.kt | 13 +- .../tests/MoveEntitiesBetweenStoragesTest.kt | 8 +- .../tests/MutableEntityCollectionTest.kt | 14 +- .../storage/tests/ParentAndChildTest.kt | 6 +- .../storage/tests/ParentChildReferenceTest.kt | 9 +- .../storage/tests/ReplaceBySourceTest.kt | 34 +-- .../storage/tests/RiderEntitiesTest.kt | 4 +- .../storage/tests/SoftLinksTest.kt | 2 +- .../storage/tests/StorageIndexiesTest.kt | 2 +- .../tests/VirtualFileUrlManagerTest.kt | 1 + .../containers/NonNegativeIntIntBiMapTest.kt | 6 +- .../BidirectionalMapPropertyTest.kt | 12 +- .../propertyBased/EntityManipulations.kt | 23 +- .../propertyBased/VirtualFileIndexTest.kt | 15 +- .../storage/tests/storageTestUtils.kt | 2 +- .../workspaceModel/storage/tests/testUtils.kt | 5 +- 47 files changed, 442 insertions(+), 339 deletions(-) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlReplaceBySourceTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlReplaceBySourceTest.kt index aba14d8ce7ab..676159401f14 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlReplaceBySourceTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlReplaceBySourceTest.kt @@ -9,8 +9,6 @@ import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.testFramework.rules.TempDirectory import com.intellij.workspaceModel.ide.impl.jps.serialization.* -import com.intellij.workspaceModel.ide.impl.jps.serialization.TestErrorReporter -import com.intellij.workspaceModel.ide.impl.jps.serialization.asConfigLocation import com.intellij.workspaceModel.storage.EntityChange import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.bridgeEntities.JavaSourceRootPropertiesEntity @@ -30,6 +28,7 @@ class ImlReplaceBySourceTest { val projectModel = ProjectModelRule() private lateinit var virtualFileManager: VirtualFileUrlManager + @Before fun setUp() { virtualFileManager = VirtualFileUrlManager.getInstance(projectModel.project) @@ -107,6 +106,7 @@ class ImlReplaceBySourceTest { // Changes 1 & 2 handle source roots ordering [ModuleSerializersFactory.SourceRootOrderEntry] @Suppress("USELESS_IS_CHECK") val sourceRootChange = changes.filterIsInstance>().single { it.entity is SourceRootEntity } + @Suppress("USELESS_IS_CHECK") val javaSourceRootChange = changes.filterIsInstance>().single { it.entity is JavaSourceRootPropertiesEntity } Assert.assertEquals(File(temp.root, "src2").toVirtualFileUrl(virtualFileManager).url, sourceRootChange.entity.url.url) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlSerializationTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlSerializationTest.kt index 4ee9dcd79b2e..720c681ab30c 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlSerializationTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ImlSerializationTest.kt @@ -67,7 +67,7 @@ class ImlSerializationTest { serializationRoundTrip(builder) } - private fun checkSerializationSize(bytes: ByteArray, expectedSize: Int, precision:Int) { + private fun checkSerializationSize(bytes: ByteArray, expectedSize: Int, precision: Int) { // At the moment serialization size varies from time to time. I don't know the reason for that, but you should check this test if // the serialization size changes a lot. diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/JpsProjectLoadingListenerTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/JpsProjectLoadingListenerTest.kt index 2db9130c9f7b..c4e39163aad7 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/JpsProjectLoadingListenerTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/JpsProjectLoadingListenerTest.kt @@ -12,9 +12,9 @@ import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.DisposableRule import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.rules.ProjectModelRule -import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer import com.intellij.workspaceModel.ide.impl.JpsProjectLoadingManagerImpl import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheImpl +import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer import com.intellij.workspaceModel.ide.impl.jps.serialization.DelayedProjectSynchronizer import com.intellij.workspaceModel.ide.impl.jps.serialization.LoadedProjectData import com.intellij.workspaceModel.ide.impl.jps.serialization.copyAndLoadProject diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt index 5f8e1a5c10f4..8a583a4f739e 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleBridgesTest.kt @@ -68,7 +68,7 @@ class ModuleBridgesTest { @Rule @JvmField val projectModel = ProjectModelRule() - + private lateinit var project: Project private lateinit var virtualFileManager: VirtualFileUrlManager @@ -122,7 +122,8 @@ class ModuleBridgesTest { rootModel.commit() assertArrayEquals(arrayOf(temp.toVirtualFileUrl(virtualFileManager).url), m.rootManager.contentRootUrls) - } finally { + } + finally { modulesModifiableModel.dispose() } } @@ -287,17 +288,19 @@ class ModuleBridgesTest { val projectModel = WorkspaceModel.getInstance(project) project.messageBus.connect(disposableRule.disposable).subscribe(WorkspaceModelTopics.CHANGED, - object : WorkspaceModelChangeListener { - override fun beforeChanged(event: VersionedStorageChange) { - val moduleBridge = event.storageAfter.resolve(ModuleId("name"))!!.findModule(event.storageAfter) - assertNotNull(moduleBridge) - } + object : WorkspaceModelChangeListener { + override fun beforeChanged(event: VersionedStorageChange) { + val moduleBridge = event.storageAfter.resolve( + ModuleId("name"))!!.findModule(event.storageAfter) + assertNotNull(moduleBridge) + } - override fun changed(event: VersionedStorageChange) { - val moduleBridge = event.storageAfter.resolve(ModuleId("name"))!!.findModule(event.storageAfter) - assertNotNull(moduleBridge) - } - } + override fun changed(event: VersionedStorageChange) { + val moduleBridge = event.storageAfter.resolve( + ModuleId("name"))!!.findModule(event.storageAfter) + assertNotNull(moduleBridge) + } + } ) projectModel.updateProjectModel { @@ -425,7 +428,9 @@ class ModuleBridgesTest { val module = projectModel.createModule() - val modifiableModel = ApplicationManager.getApplication().runReadAction { ModuleRootManager.getInstance(module).modifiableModel } + val modifiableModel = ApplicationManager.getApplication().runReadAction { + ModuleRootManager.getInstance(module).modifiableModel + } val moduleExtension = modifiableModel.getModuleExtension(TestModuleExtension::class.java) moduleExtension.languageLevel = LanguageLevel.JDK_1_5 runWriteActionAndWait { modifiableModel.commit() } @@ -484,7 +489,8 @@ class ModuleBridgesTest { ) builder.modifyEntity(moduleEntity) { dependencies = listOf( - ModuleDependencyItem.Exportable.LibraryDependency(moduleLibraryEntity.symbolicId, false, ModuleDependencyItem.DependencyScope.COMPILE) + ModuleDependencyItem.Exportable.LibraryDependency(moduleLibraryEntity.symbolicId, false, + ModuleDependencyItem.DependencyScope.COMPILE) ).toMutableList() } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleLibraryBridgeTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleLibraryBridgeTest.kt index 20704b0b58ec..dfabdce6a401 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleLibraryBridgeTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleLibraryBridgeTest.kt @@ -98,7 +98,7 @@ class ModuleLibraryBridgeTest { ModuleRootModificationUtil.addModuleLibrary(module, antLibraryName, listOf(), emptyList()) module } - + val moduleRootManager = WriteCommandAction.writeCommandAction(project).compute { val moduleRootManager = ModuleRootManager.getInstance(module) moduleRootManager.modifiableModel.let { rootModel -> @@ -110,7 +110,7 @@ class ModuleLibraryBridgeTest { } moduleRootManager } - + WriteCommandAction.writeCommandAction(project).run { assertModuleLibraryDependency(moduleRootManager, mavenLibraryName) @@ -210,7 +210,7 @@ class ModuleLibraryBridgeTest { ModuleRootModificationUtil.addModuleLibrary(module, antLibraryName, listOf(), emptyList()) module } - + WriteCommandAction.writeCommandAction(project).run { val moduleRootManager = ModuleRootManager.getInstance(module) moduleRootManager.modifiableModel.let { rootModel -> @@ -240,7 +240,7 @@ class ModuleLibraryBridgeTest { rootModel.commit() } } - + val libraryDependencies = WorkspaceModel.getInstance(project).currentSnapshot .entities(ModuleEntity::class.java).first() .dependencies.drop(1) @@ -401,7 +401,7 @@ class ModuleLibraryBridgeTest { emptyList()) module } - + WriteCommandAction.writeCommandAction(project).run { val moduleRootManager = ModuleRootManager.getInstance(module) moduleRootManager.modifiableModel.let { rootModel -> diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleTestPropertiesTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleTestPropertiesTest.kt index 113c727cd221..0428eae81b45 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleTestPropertiesTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ModuleTestPropertiesTest.kt @@ -46,7 +46,7 @@ class ModuleTestPropertiesTest { val workspaceModel = WorkspaceModel.getInstance(projectModel.project) - UsefulTestCase.assertEmpty(workspaceModel.currentSnapshot.entities (TestModulePropertiesEntity::class.java).toList()) + UsefulTestCase.assertEmpty(workspaceModel.currentSnapshot.entities(TestModulePropertiesEntity::class.java).toList()) runWriteActionAndWait { workspaceModel.updateProjectModel { builder -> @@ -57,7 +57,7 @@ class ModuleTestPropertiesTest { } } - UsefulTestCase.assertNotEmpty(workspaceModel.currentSnapshot.entities (TestModulePropertiesEntity::class.java).toList()) + UsefulTestCase.assertNotEmpty(workspaceModel.currentSnapshot.entities(TestModulePropertiesEntity::class.java).toList()) assertSame(mainModule, testModuleProperties.productionModule) assertEquals(mainModule.name, testModuleProperties.productionModuleName) @@ -68,7 +68,8 @@ class ModuleTestPropertiesTest { val mainModuleName = "foo" val testModuleName = "foo.test" - val projectPath = File(PathManagerEx.getCommunityHomePath(), "platform/workspaceModel/jps/tests/testData/serialization/moduleTestProperties") + val projectPath = File(PathManagerEx.getCommunityHomePath(), + "platform/workspaceModel/jps/tests/testData/serialization/moduleTestProperties") val virtualFileUrlManager = VirtualFileUrlManager.getInstance(projectModel.project) val storage = copyAndLoadProject(projectPath, virtualFileUrlManager).storage diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ProjectLibraryBridgeTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ProjectLibraryBridgeTest.kt index 06af25c8e41e..54f576657d7a 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ProjectLibraryBridgeTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ProjectLibraryBridgeTest.kt @@ -213,7 +213,7 @@ class ProjectLibraryBridgeTest { libraryBridgeTree = it.libraries[0] assertTrue(libraryBridgeTwo === libraryBridgeTree) - libraryBridgeTree!!.modifiableModel.let { mLib-> + libraryBridgeTree!!.modifiableModel.let { mLib -> mLib.name = anotherLibraryName mLib } @@ -265,13 +265,13 @@ class ProjectLibraryBridgeTest { val library = createProjectLibrary("lib") assertEquals(2, events.size) assertEquals(0, excludedUrlEvents.size) - + val root = library.getFiles(OrderRootType.CLASSES).single() projectModel.modifyLibrary(library) { it.addExcludedRoot(root.url) } assertTrue(excludedUrlEvents.last() is EntityChange.Added) - + projectModel.modifyLibrary(library) { it.removeExcludedRoot(root.url) } @@ -298,7 +298,7 @@ class ProjectLibraryBridgeTest { assertTrue(newEntity.tableId is LibraryTableId.ProjectLibraryTableId) assertEquals(2, newEntity.roots.size) } - + private fun createProjectLibrary(libraryName: String, withRoots: Boolean = true): Library { val library = runWriteActionAndWait { LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(libraryName) @@ -309,6 +309,6 @@ class ProjectLibraryBridgeTest { it.addRoot(projectModel.baseProjectDir.newVirtualFile("$libraryName-sources.jar"), OrderRootType.SOURCES) } } - return library + return library } } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ReplaceBySourceTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ReplaceBySourceTest.kt index c450351f32b3..dac7042f40b8 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ReplaceBySourceTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/ReplaceBySourceTest.kt @@ -20,6 +20,7 @@ class ReplaceBySourceTest { val projectModel = ProjectModelRule() private lateinit var virtualFileManager: VirtualFileUrlManager + @Before fun setUp() { virtualFileManager = VirtualFileUrlManager.getInstance(projectModel.project) @@ -35,8 +36,10 @@ class ReplaceBySourceTest { val contentRootEntity = storage.entities(ContentRootEntity::class.java).first() if (i == 1) { contentRootEntity.sourceRoots.forEach { expectedResult.add(it.url.toString()) } - } else { - Assert.assertArrayEquals(expectedResult.toTypedArray(), contentRootEntity.sourceRoots.map { it.url.toString() }.toList().toTypedArray()) + } + else { + Assert.assertArrayEquals(expectedResult.toTypedArray(), + contentRootEntity.sourceRoots.map { it.url.toString() }.toList().toTypedArray()) } } } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/TestModuleComponent.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/TestModuleComponent.kt index 33e6c86769a3..968f951d0680 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/TestModuleComponent.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/TestModuleComponent.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleComponent @State(name = "XXX") -class TestModuleComponent: ModuleComponent, PersistentStateComponent { +class TestModuleComponent : ModuleComponent, PersistentStateComponent { var testString: String = "" override fun getState(): TestModuleComponent = this diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/VirtualFileUrlManagerTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/VirtualFileUrlManagerTest.kt index ad96e0c266d5..fc9a82c110d7 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/VirtualFileUrlManagerTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/VirtualFileUrlManagerTest.kt @@ -4,7 +4,10 @@ package com.intellij.workspaceModel.ide import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager -import org.junit.* +import org.junit.Assert +import org.junit.Before +import org.junit.ClassRule +import org.junit.Rule class VirtualFileUrlManagerTest { @Rule @@ -12,6 +15,7 @@ class VirtualFileUrlManagerTest { val projectModel = ProjectModelRule() private lateinit var virtualFileManager: VirtualFileUrlManager + @Before fun setUp() { virtualFileManager = VirtualFileUrlManager.getInstance(projectModel.project) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceCacheTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceCacheTest.kt index a8f12c59ba44..e6a99e3aac20 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceCacheTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceCacheTest.kt @@ -19,7 +19,6 @@ import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheImpl import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer import com.intellij.workspaceModel.ide.impl.jps.serialization.LoadedProjectData import com.intellij.workspaceModel.ide.impl.jps.serialization.copyAndLoadProject -import com.intellij.workspaceModel.storage.EntitySource import com.intellij.workspaceModel.storage.EntityStorageSerializer import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity import com.intellij.workspaceModel.storage.bridgeEntities.addModuleEntity @@ -84,12 +83,13 @@ class WorkspaceCacheTest { val project = loadProject(prepareProject().projectDir) val cache = WorkspaceModelCache.getInstance(project) as WorkspaceModelCacheImpl cache.saveCacheNow() - assertFalse("Cache for unloaded entities must not be created if no entities are unloaded", cache.getUnloadedEntitiesCacheFilePath().exists()) - + assertFalse("Cache for unloaded entities must not be created if no entities are unloaded", + cache.getUnloadedEntitiesCacheFilePath().exists()) + runBlocking { ModuleManager.getInstance(project).setUnloadedModules(listOf("newModule")) } - + cache.saveCacheNow() assertTrue(cache.getUnloadedEntitiesCacheFilePath().exists()) } @@ -194,6 +194,8 @@ class WorkspaceCacheTest { private fun cacheFileName(): String { return "test_caching_" + RandomStringUtils.randomAlphabetic(5) + ".data" } - private val WORKSPACE_MODEL_CACHE_VERSION_EP = ExtensionPointName.create("com.intellij.workspaceModel.cache.version") + + private val WORKSPACE_MODEL_CACHE_VERSION_EP = ExtensionPointName.create( + "com.intellij.workspaceModel.cache.version") } } \ No newline at end of file diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelAsyncTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelAsyncTest.kt index db49d5e517e0..ad351e38165c 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelAsyncTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelAsyncTest.kt @@ -15,7 +15,8 @@ import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity import com.intellij.workspaceModel.storage.bridgeEntities.addModuleEntity import junit.framework.Assert.assertEquals import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.take import org.junit.After import org.junit.ClassRule import org.junit.Rule @@ -93,7 +94,7 @@ class WorkspaceModelAsyncTest { val application = ApplicationManager.getApplication() assertEquals(false, application.isWriteAccessAllowed) - projectModel.project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, object: WorkspaceModelChangeListener { + projectModel.project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, object : WorkspaceModelChangeListener { override fun changed(event: VersionedStorageChange) { assertEquals(true, application.isWriteAccessAllowed) val entityChange = event.getAllChanges().single() @@ -115,7 +116,7 @@ class WorkspaceModelAsyncTest { val application = ApplicationManager.getApplication() assertEquals(false, application.isWriteAccessAllowed) - projectModel.project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, object: WorkspaceModelChangeListener { + projectModel.project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, object : WorkspaceModelChangeListener { override fun changed(event: VersionedStorageChange) { assertEquals(true, application.isWriteAccessAllowed) val entityChange = event.getAllChanges().single() diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelMemoryDumper.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelMemoryDumper.kt index 20e9d4e4101b..9a9a26f73aee 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelMemoryDumper.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelMemoryDumper.kt @@ -7,8 +7,6 @@ import com.intellij.testFramework.TestApplicationManager import com.intellij.util.MemoryDumpHelper import com.intellij.util.SystemProperties import com.intellij.workspaceModel.ide.impl.jps.serialization.* -import com.intellij.workspaceModel.ide.impl.jps.serialization.TestErrorReporter -import com.intellij.workspaceModel.ide.impl.jps.serialization.asConfigLocation import com.intellij.workspaceModel.storage.EntityStorage import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.impl.url.VirtualFileUrlManagerImpl @@ -34,7 +32,7 @@ private suspend fun loadProject(): Pair { val builder = MutableEntityStorage.create() val virtualFileManager = VirtualFileUrlManagerImpl() val projectDir = File(PathManager.getHomePath()).asConfigLocation(virtualFileManager) - val context = SerializationContextForTests(virtualFileManager, CachingJpsFileContentReader(projectDir)) + val context = SerializationContextForTests(virtualFileManager, CachingJpsFileContentReader(projectDir)) val serializers = JpsProjectEntitiesLoader.loadProject(projectDir, builder, builder, Paths.get("/tmp"), TestErrorReporter, context = context) return Pair(serializers, builder.toSnapshot()) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt index f26b632c25e7..4655f5c4a038 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/WorkspaceModelPerformanceTest.kt @@ -32,50 +32,55 @@ class WorkspaceModelPerformanceTest { @RegisterExtension @JvmField val ourProjectModel = ClassLevelProjectModelExtension() - + private lateinit var ourProjectRoot: VirtualFileUrl private var disposerDebugMode = true @BeforeAll @JvmStatic fun initProject() { - val fsRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///")!!.toVirtualFileUrl(VirtualFileUrlManager.getInstance(ourProjectModel.project)) + val fsRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///")!!.toVirtualFileUrl( + VirtualFileUrlManager.getInstance(ourProjectModel.project)) ourProjectRoot = fsRoot.append(WorkspaceModelPerformanceTest::class.java.simpleName) val builder = MutableEntityStorage.create() for (i in 1..100) { val libRoot = ourProjectRoot.append("lib$i") val classesRoot = LibraryRoot(libRoot.append("classes"), LibraryRootTypeId.COMPILED) val sourcesRoot = LibraryRoot(libRoot.append("sources"), LibraryRootTypeId.SOURCES) - builder.addEntity(LibraryEntity("lib$i", LibraryTableId.ProjectLibraryTableId, listOf(classesRoot, sourcesRoot), NonPersistentEntitySource)) + builder.addEntity( + LibraryEntity("lib$i", LibraryTableId.ProjectLibraryTableId, listOf(classesRoot, sourcesRoot), NonPersistentEntitySource)) } for (i in 1..100) { val contentRoot = ourProjectRoot.append("module$i") val srcRoot = contentRoot.append("src") val dependentModules = if (i > 10) 1..10 else IntRange.EMPTY - val dependentLibraries = (1 .. 10).toList() + (if (i > 10) listOf(i) else emptyList()) + val dependentLibraries = (1..10).toList() + (if (i > 10) listOf(i) else emptyList()) val dependencies = listOf( listOf(ModuleDependencyItem.ModuleSourceDependency, ModuleDependencyItem.InheritedSdkDependency), - dependentModules.map { - ModuleDependencyItem.Exportable.ModuleDependency(ModuleId("module$it"), false, ModuleDependencyItem.DependencyScope.COMPILE, false) + dependentModules.map { + ModuleDependencyItem.Exportable.ModuleDependency(ModuleId("module$it"), false, ModuleDependencyItem.DependencyScope.COMPILE, + false) }, - dependentLibraries.map { - ModuleDependencyItem.Exportable.LibraryDependency(LibraryId("lib$it", LibraryTableId.ProjectLibraryTableId), false, ModuleDependencyItem.DependencyScope.COMPILE) + dependentLibraries.map { + ModuleDependencyItem.Exportable.LibraryDependency(LibraryId("lib$it", LibraryTableId.ProjectLibraryTableId), false, + ModuleDependencyItem.DependencyScope.COMPILE) } ).flatten() builder addEntity ModuleEntity("module$i", dependencies, NonPersistentEntitySource) { contentRoots = listOf(ContentRootEntity(contentRoot, emptyList(), NonPersistentEntitySource) { - sourceRoots = listOf(SourceRootEntity(srcRoot, JpsModuleRootModelSerializer.JAVA_SOURCE_ROOT_TYPE_ID, NonPersistentEntitySource)) + sourceRoots = listOf( + SourceRootEntity(srcRoot, JpsModuleRootModelSerializer.JAVA_SOURCE_ROOT_TYPE_ID, NonPersistentEntitySource)) }) } } - + runWriteActionAndWait { WorkspaceModel.getInstance(ourProjectModel.project).updateProjectModel { it.addDiff(builder) } } - + ApplicationManagerEx.setInStressTest(true) disposerDebugMode = Disposer.isDebugMode() Disposer.setDebugMode(false) @@ -104,7 +109,7 @@ class WorkspaceModelPerformanceTest { } }.warmupIterations(15).assertTiming() } - + @Test fun `add remove project library`() { PlatformTestUtil.startPerformanceTest("Adding and removing a project library 30 times", 125) { @@ -118,7 +123,7 @@ class WorkspaceModelPerformanceTest { } }.warmupIterations(15).assertTiming() } - + @Test fun `add remove module library`() { val module = ourProjectModel.moduleManager.findModuleByName("module50")!! @@ -158,7 +163,7 @@ class WorkspaceModelPerformanceTest { assertTrue(count > 0) }.warmupIterations(5).assertTiming() } - + @Test fun `process order entries`() { PlatformTestUtil.startPerformanceTest("Iterate through order entries of all modules 1000 times", 60) { @@ -170,5 +175,5 @@ class WorkspaceModelPerformanceTest { } assertTrue(count > 0) }.warmupIterations(5).assertTiming() - } + } } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt index 7990dbb8e451..7d2e7aa91048 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/DelayedProjectSynchronizerTest.kt @@ -16,6 +16,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar import com.intellij.openapi.util.Disposer import com.intellij.platform.workspaceModel.jps.JpsImportedEntitySource import com.intellij.platform.workspaceModel.jps.JpsProjectFileEntitySource +import com.intellij.platform.workspaceModel.jps.serialization.impl.FileInDirectorySourceNames import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.DisposableRule import com.intellij.testFramework.OpenProjectTaskBuilder @@ -23,10 +24,12 @@ import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.testFramework.rules.TempDirectory import com.intellij.util.io.readText -import com.intellij.workspaceModel.ide.* -import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer -import com.intellij.platform.workspaceModel.jps.serialization.impl.FileInDirectorySourceNames +import com.intellij.workspaceModel.ide.UnloadedModulesNameHolder +import com.intellij.workspaceModel.ide.WorkspaceModel +import com.intellij.workspaceModel.ide.getInstance +import com.intellij.workspaceModel.ide.getJpsProjectConfigLocation import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheImpl +import com.intellij.workspaceModel.ide.impl.WorkspaceModelCacheSerializer import com.intellij.workspaceModel.ide.impl.WorkspaceModelImpl import com.intellij.workspaceModel.storage.EntityStorageSerializer import com.intellij.workspaceModel.storage.EntityStorageSnapshot @@ -93,7 +96,8 @@ class DelayedProjectSynchronizerTest { val storage = WorkspaceModel.getInstance(project).currentSnapshot val serializers = JpsProjectModelSynchronizer.getInstance(project).getSerializers() val unloadedEntitiesStorage = WorkspaceModel.getInstance(project).currentSnapshotOfUnloadedEntities - serializers.checkConsistency(getJpsProjectConfigLocation(project)!!, storage, unloadedEntitiesStorage, VirtualFileUrlManager.getInstance(project)) + serializers.checkConsistency(getJpsProjectConfigLocation(project)!!, storage, unloadedEntitiesStorage, + VirtualFileUrlManager.getInstance(project)) } @Test @@ -157,7 +161,8 @@ class DelayedProjectSynchronizerTest { val unloadedEntitiesBuilder = MutableEntityStorage.create() val orphanage = MutableEntityStorage.create() val configLocation = toConfigLocation(projectData.projectDir.toPath(), virtualFileManager) - val serializers = loadProject(configLocation, originalBuilder, orphanage, virtualFileManager, UnloadedModulesNameHolder.DUMMY, unloadedEntitiesBuilder, + val serializers = loadProject(configLocation, originalBuilder, orphanage, virtualFileManager, UnloadedModulesNameHolder.DUMMY, + unloadedEntitiesBuilder, fileInDirectorySourceNames) as JpsProjectSerializersImpl val loadedProjectData = LoadedProjectData(originalBuilder.toSnapshot(), orphanage.toSnapshot(), unloadedEntitiesBuilder.toSnapshot(), serializers, @@ -189,11 +194,13 @@ class DelayedProjectSynchronizerTest { val externalStorageConfigurationManager = ExternalStorageConfigurationManager.getInstance(projectModel.project) externalStorageConfigurationManager.isEnabled = true val originalBuilder = MutableEntityStorage.create() - loadProject(toConfigLocation(projectDir.toPath(), virtualFileManager), originalBuilder, originalBuilder, virtualFileManager, externalStorageConfigurationManager = externalStorageConfigurationManager) + loadProject(toConfigLocation(projectDir.toPath(), virtualFileManager), originalBuilder, originalBuilder, virtualFileManager, + externalStorageConfigurationManager = externalStorageConfigurationManager) val fileInDirectorySourceNames = FileInDirectorySourceNames.from(originalBuilder) val builderForAnotherProject = MutableEntityStorage.create() - loadProject(toConfigLocation(projectDir.toPath(), virtualFileManager), builderForAnotherProject, builderForAnotherProject, virtualFileManager, + loadProject(toConfigLocation(projectDir.toPath(), virtualFileManager), builderForAnotherProject, builderForAnotherProject, + virtualFileManager, externalStorageConfigurationManager = externalStorageConfigurationManager, fileInDirectorySourceNames = fileInDirectorySourceNames) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesLoaderTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesLoaderTest.kt index 51d43b40dc5a..2af9d5bee9e0 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesLoaderTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesLoaderTest.kt @@ -2,10 +2,10 @@ package com.intellij.workspaceModel.ide.impl.jps.serialization import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar +import com.intellij.platform.workspaceModel.jps.JpsGlobalFileEntitySource import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.DisposableRule import com.intellij.testFramework.UsefulTestCase -import com.intellij.platform.workspaceModel.jps.JpsGlobalFileEntitySource import com.intellij.workspaceModel.ide.impl.GlobalWorkspaceModel import com.intellij.workspaceModel.ide.impl.legacyBridge.library.GlobalLibraryTableBridgeImpl import com.intellij.workspaceModel.storage.bridgeEntities.LibraryEntity diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesSyncTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesSyncTest.kt index 913e65082e4d..cdd23ae41afd 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesSyncTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsGlobalEntitiesSyncTest.kt @@ -86,8 +86,10 @@ class JpsGlobalEntitiesSyncTest { builder.removeEntity(libraryEntity) globalLibrariesNames.remove(libraryNameToRemove) - val gradleLibraryEntity = LibraryEntity("com.gradle", LibraryTableId.GlobalLibraryTableId(LibraryTablesRegistrar.APPLICATION_LEVEL), - listOf(LibraryRoot(virtualFileManager.fromUrl("/a/b/one.txt"), LibraryRootTypeId.SOURCES)), + val gradleLibraryEntity = LibraryEntity("com.gradle", + LibraryTableId.GlobalLibraryTableId(LibraryTablesRegistrar.APPLICATION_LEVEL), + listOf( + LibraryRoot(virtualFileManager.fromUrl("/a/b/one.txt"), LibraryRootTypeId.SOURCES)), entitySource) builder.addEntity(gradleLibraryEntity) globalLibrariesNames.add(gradleLibraryEntity.name) @@ -101,7 +103,9 @@ class JpsGlobalEntitiesSyncTest { } } - private fun checkLibrariesInStorages(globalLibrariesNames: List, projectLibrariesNames: List, loadedProjects: List) { + private fun checkLibrariesInStorages(globalLibrariesNames: List, + projectLibrariesNames: List, + loadedProjects: List) { val libraryTable = LibraryTablesRegistrar.getInstance().libraryTable libraryTable as GlobalLibraryTableBridgeImpl val libraryBridges = libraryTable.libraries @@ -137,7 +141,7 @@ class JpsGlobalEntitiesSyncTest { private fun loadProject(): Project { val tmpFolder = temporaryFolder.newFolder() val projectDir = File(PathManagerEx.getCommunityHomePath(), - "platform/workspaceModel/jps/tests/testData/serialization/moduleTestProperties") + "platform/workspaceModel/jps/tests/testData/serialization/moduleTestProperties") FileUtil.copyDir(projectDir, tmpFolder) return PlatformTestUtil.loadAndOpenProject(tmpFolder.toPath(), disposableRule.disposable) } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsIncorrectDataLoading.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsIncorrectDataLoading.kt index 3c45710503a3..23a664150a3c 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsIncorrectDataLoading.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsIncorrectDataLoading.kt @@ -8,14 +8,12 @@ import com.intellij.workspaceModel.storage.EntityStorage import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity import com.intellij.workspaceModel.storage.bridgeEntities.sourceRoots -import com.intellij.workspaceModel.storage.url.VirtualFileUrl import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager -import junit.framework.TestCase import org.junit.Before import org.junit.Test import java.io.File -class JpsIncorrectDataLoading : HeavyPlatformTestCase() { +class JpsIncorrectDataLoading : HeavyPlatformTestCase() { private lateinit var errorCollector: CollectingErrorReporter @@ -27,7 +25,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { @Test fun `test load broken library order entry`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/libraryOrderEntry") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/libraryOrderEntry") val storage = loadProject(projectDir) val modules = storage.entities(ModuleEntity::class.java).toList() assertEquals(1, modules.size) @@ -36,7 +35,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { @Test fun `test load broken library order entry multiple`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/multipleLibraryOrderEntry") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/multipleLibraryOrderEntry") val storage = loadProject(projectDir) val modules = storage.entities(ModuleEntity::class.java).toList() assertEquals(1, modules.size) @@ -46,7 +46,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { @Test fun `test mess in source folder`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolder") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolder") val storage = loadProject(projectDir) val modules = storage.entities(ModuleEntity::class.java).toList() assertEquals(1, modules.size) @@ -55,7 +56,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { @Test fun `test mess in broken url`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolderBrokenUrl") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolderBrokenUrl") val storage = loadProject(projectDir) val modules = storage.entities(ModuleEntity::class.java).toList() assertEquals(1, modules.size) @@ -65,7 +67,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { @Test fun `test mess in source folder - is test source`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolderBrokenIsTestSource") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/brokenRoots/sourceFolderBrokenIsTestSource") val storage = loadProject(projectDir) val modules = storage.entities(ModuleEntity::class.java).toList() assertEquals(1, modules.size) @@ -76,7 +79,8 @@ class JpsIncorrectDataLoading : HeavyPlatformTestCase() { private fun loadProject(projectFile: File): EntityStorage { val storageBuilder = MutableEntityStorage.create() val virtualFileManager: VirtualFileUrlManager = VirtualFileUrlManager.getInstance(project) - loadProject(projectFile.asConfigLocation(virtualFileManager), storageBuilder, storageBuilder, virtualFileManager, errorReporter = errorCollector) + loadProject(projectFile.asConfigLocation(virtualFileManager), storageBuilder, storageBuilder, virtualFileManager, + errorReporter = errorCollector) return storageBuilder.toSnapshot() } } \ No newline at end of file diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectEntitiesLoaderTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectEntitiesLoaderTest.kt index ecb7871eb229..8ba6e5184227 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectEntitiesLoaderTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectEntitiesLoaderTest.kt @@ -92,8 +92,10 @@ class JpsProjectEntitiesLoaderTest : HeavyPlatformTestCase() { assertEquals(ModuleDependencyItem.ModuleSourceDependency, mainModule.dependencies[1]) assertEquals("log4j", (mainModule.dependencies[2] as ModuleDependencyItem.Exportable.LibraryDependency).library.name) assertFalse((mainModule.dependencies[2] as ModuleDependencyItem.Exportable.LibraryDependency).exported) - assertEquals(ModuleDependencyItem.DependencyScope.COMPILE, (mainModule.dependencies[2] as ModuleDependencyItem.Exportable.LibraryDependency).scope) - assertEquals(ModuleDependencyItem.DependencyScope.TEST, (mainModule.dependencies[3] as ModuleDependencyItem.Exportable.LibraryDependency).scope) + assertEquals(ModuleDependencyItem.DependencyScope.COMPILE, + (mainModule.dependencies[2] as ModuleDependencyItem.Exportable.LibraryDependency).scope) + assertEquals(ModuleDependencyItem.DependencyScope.TEST, + (mainModule.dependencies[3] as ModuleDependencyItem.Exportable.LibraryDependency).scope) assertTrue((mainModule.dependencies[4] as ModuleDependencyItem.Exportable.LibraryDependency).exported) assertEquals("util", (mainModule.dependencies[5] as ModuleDependencyItem.Exportable.ModuleDependency).module.name) @@ -179,12 +181,14 @@ class JpsProjectEntitiesLoaderTest : HeavyPlatformTestCase() { assertEquals("jar.jar", archiveRoot.fileName) val archiveChildren = archiveRoot.children.toList() assertEquals(3, archiveChildren.size) - assertEquals(artifacts[0], archiveChildren.filterIsInstance().single().artifact!!.resolve(storage)) + assertEquals(artifacts[0], + archiveChildren.filterIsInstance().single().artifact!!.resolve(storage)) } @Test fun `test custom packaging elements`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/customPackagingElements/javaeeSampleProject.ipr") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/customPackagingElements/javaeeSampleProject.ipr") val storage = loadProject(projectDir) val artifacts = storage.entities(ArtifactEntity::class.java).sortedBy { it.name }.toList() assertEquals(6, artifacts.size) @@ -197,7 +201,8 @@ class JpsProjectEntitiesLoaderTest : HeavyPlatformTestCase() { } fun `test custom source root`() { - val projectDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/customSourceRoot/customSourceRoot.ipr") + val projectDir = PathManagerEx.findFileUnderCommunityHome( + "platform/workspaceModel/jps/tests/testData/serialization/customSourceRoot/customSourceRoot.ipr") val storage = loadProject(projectDir) val module = assertOneElement(storage.entities(ModuleEntity::class.java).toList()) val sourceRoot = assertOneElement(module.sourceRoots.toList()) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectReloadingTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectReloadingTest.kt index 8b86dd392f16..ba55afb2bef5 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectReloadingTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectReloadingTest.kt @@ -57,7 +57,7 @@ class JpsProjectReloadingTest { @Test fun `add library`() { - checkProjectAfterReload( "directoryBased/addLibrary", "fileBased/addLibrary") { (storage, _, projectDirUrl) -> + checkProjectAfterReload("directoryBased/addLibrary", "fileBased/addLibrary") { (storage, _, projectDirUrl) -> val libraries = storage.projectLibraries.sortedBy { it.name }.toList() assertEquals(4, libraries.size) val junitLibrary = libraries[2] @@ -85,7 +85,8 @@ class JpsProjectReloadingTest { fun `add module`(unloaded: String) { val unloadedModuleNames = StringUtil.split(unloaded, ",").toSet() val unloadedHolder = UnloadedModulesNameHolderImpl(unloadedModuleNames) - checkProjectAfterReload("directoryBased/addModule", "fileBased/addModule", unloadedHolder) { (storage, unloadedEntitiesStorage, projectDirUrl) -> + checkProjectAfterReload("directoryBased/addModule", "fileBased/addModule", + unloadedHolder) { (storage, unloadedEntitiesStorage, projectDirUrl) -> val modules = storage.entities(ModuleEntity::class.java).sortedBy { it.name }.toList() assertEquals(4 - unloadedModuleNames.size, modules.size) val unloadedModules = unloadedEntitiesStorage.entities(ModuleEntity::class.java) @@ -102,16 +103,18 @@ class JpsProjectReloadingTest { fun `remove module`(unloaded: String) { val unloadedModuleNames = StringUtil.split(unloaded, ",").toSet() val unloadedHolder = UnloadedModulesNameHolderImpl(unloadedModuleNames) - checkProjectAfterReload("directoryBased/removeModule", "fileBased/removeModule", unloadedHolder) { (storage, unloadedEntitiesStorage, _) -> + checkProjectAfterReload("directoryBased/removeModule", "fileBased/removeModule", + unloadedHolder) { (storage, unloadedEntitiesStorage, _) -> assertEquals(unloadedModuleNames - "util", unloadedEntitiesStorage.entities(ModuleEntity::class.java).mapTo(HashSet()) { it.name }) val allEntities = storage.entities(ModuleEntity::class.java) + unloadedEntitiesStorage.entities(ModuleEntity::class.java) - assertEquals(setOf("main", "xxx"), allEntities.mapTo(HashSet()) {it.name}) + assertEquals(setOf("main", "xxx"), allEntities.mapTo(HashSet()) { it.name }) } } @Test fun `modify library`() { - checkProjectAfterReload("directoryBased/modifyLibrary", "fileBased/modifyLibrary") { (storage, originalUnloadedEntitiesBuilder, projectDirUrl) -> + checkProjectAfterReload("directoryBased/modifyLibrary", + "fileBased/modifyLibrary") { (storage, originalUnloadedEntitiesBuilder, projectDirUrl) -> val libraries = storage.projectLibraries.sortedBy { it.name }.toList() assertEquals(3, libraries.size) val junitLibrary = libraries[1] @@ -124,14 +127,15 @@ class JpsProjectReloadingTest { @Test fun `remove library`() { checkProjectAfterReload("directoryBased/removeLibrary", "fileBased/removeLibrary") { (storage, originalUnloadedEntitiesBuilder, _) -> - assertEquals(setOf("jarDir", "log4j"), storage.projectLibraries.mapTo(HashSet()) {it.name}) + assertEquals(setOf("jarDir", "log4j"), storage.projectLibraries.mapTo(HashSet()) { it.name }) } } @Test fun `remove all libraries`() { - checkProjectAfterReload("directoryBased/removeAllLibraries", "fileBased/removeAllLibraries") { (storage, originalUnloadedEntitiesBuilder, _) -> - assertEquals(emptySet(), storage.projectLibraries.mapTo(HashSet()) {it.name}) + checkProjectAfterReload("directoryBased/removeAllLibraries", + "fileBased/removeAllLibraries") { (storage, originalUnloadedEntitiesBuilder, _) -> + assertEquals(emptySet(), storage.projectLibraries.mapTo(HashSet()) { it.name }) } } @@ -151,16 +155,20 @@ class JpsProjectReloadingTest { val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager, unloadedModulesNameHolder) val change = updateAction(projectData) val result = - projectData.serializers.reloadFromChangedFiles(change, CachingJpsFileContentReader(projectData.configLocation), unloadedModulesNameHolder, TestErrorReporter) + projectData.serializers.reloadFromChangedFiles(change, CachingJpsFileContentReader(projectData.configLocation), + unloadedModulesNameHolder, TestErrorReporter) val originalBuilder = MutableEntityStorage.from(projectData.storage) - originalBuilder.replaceBySource({it in result.affectedSources}, result.builder) + originalBuilder.replaceBySource({ it in result.affectedSources }, result.builder) val originalUnloadedEntitiesBuilder = MutableEntityStorage.from(projectData.unloadedEntitiesStorage) - originalUnloadedEntitiesBuilder.replaceBySource({it in result.affectedSources}, result.unloadedEntityBuilder) - projectData.serializers.checkConsistency(projectData.configLocation, originalBuilder, originalUnloadedEntitiesBuilder, virtualFileManager) + originalUnloadedEntitiesBuilder.replaceBySource({ it in result.affectedSources }, result.unloadedEntityBuilder) + projectData.serializers.checkConsistency(projectData.configLocation, originalBuilder, originalUnloadedEntitiesBuilder, + virtualFileManager) return ReloadedProjectData(originalBuilder, originalUnloadedEntitiesBuilder, projectData.projectDirUrl) } - private fun reload(originalProjectDir: File, directoryName: String, unloadedModulesNameHolder: UnloadedModulesNameHolder): ReloadedProjectData { + private fun reload(originalProjectDir: File, + directoryName: String, + unloadedModulesNameHolder: UnloadedModulesNameHolder): ReloadedProjectData { return reload(originalProjectDir, unloadedModulesNameHolder) { projectData -> val changedDir = PathManagerEx.findFileUnderCommunityHome( "platform/workspaceModel/jps/tests/testData/serialization/reload/$directoryName") @@ -194,7 +202,9 @@ class JpsProjectReloadingTest { if (!relativeFileUrl.endsWith(".idea/libraries") && !relativeFileUrl.endsWith(".idea/artifacts")) return@forEach // Existing files + files that will be copied - val children = (JpsPathUtil.urlToFile(replaceBaseUrl(baseUrl, dir, file)).listFiles()?.map { JpsPathUtil.pathToUrl(it.absolutePath) } ?: emptyList()) + + val children = (JpsPathUtil.urlToFile(replaceBaseUrl(baseUrl, dir, file)).listFiles()?.map { + JpsPathUtil.pathToUrl(it.absolutePath) + } ?: emptyList()) + (file.listFiles()?.map { replaceBaseUrl(baseUrl, dir, it) } ?: emptyList()) if (children.all { it in res }) { if (replaceByParent) children.forEach { res.remove(it) } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAfterChangesTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAfterChangesTest.kt index e0d2fbf31a40..27552b78442b 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAfterChangesTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAfterChangesTest.kt @@ -26,6 +26,7 @@ class JpsProjectSaveAfterChangesTest { val projectModel: ProjectModelExtension = ProjectModelExtension() private lateinit var virtualFileManager: VirtualFileUrlManager + @BeforeEach fun setUp() { virtualFileManager = IdeVirtualFileUrlManagerImpl() @@ -35,8 +36,8 @@ class JpsProjectSaveAfterChangesTest { @ValueSource(strings = ["", "util", "util,main", "main"]) fun `modify module`(unloaded: String) { val unloadedHolder = unloadedHolder(unloaded) - checkSaveProjectAfterChange("common/modifyIml", "common/modifyIml", unloadedHolder) { - mainBuilder, _, unloadedEntitiesBuilder, configLocation -> + checkSaveProjectAfterChange("common/modifyIml", "common/modifyIml", + unloadedHolder) { mainBuilder, _, unloadedEntitiesBuilder, configLocation -> val builder = if (unloadedHolder.isUnloaded("util")) unloadedEntitiesBuilder else mainBuilder val utilModule = builder.entities(ModuleEntity::class.java).first { it.name == "util" } val sourceRoot = utilModule.sourceRoots.first() @@ -98,8 +99,8 @@ class JpsProjectSaveAfterChangesTest { @ValueSource(strings = ["", "newModule", "newModule,main", "main"]) fun `add module`(unloaded: String) { val unloadedHolder = unloadedHolder(unloaded); - checkSaveProjectAfterChange("directoryBased/addModule", "fileBased/addModule", unloadedHolder) { - mainBuilder, _, unloadedEntitiesBuilder, configLocation -> + checkSaveProjectAfterChange("directoryBased/addModule", "fileBased/addModule", + unloadedHolder) { mainBuilder, _, unloadedEntitiesBuilder, configLocation -> val builder = if (unloadedHolder.isUnloaded("newModule")) unloadedEntitiesBuilder else mainBuilder val source = JpsProjectFileEntitySource.FileInDirectory(configLocation.baseDirectoryUrl, configLocation) val dependencies = listOf(ModuleDependencyItem.InheritedSdkDependency, ModuleDependencyItem.ModuleSourceDependency) @@ -120,8 +121,8 @@ class JpsProjectSaveAfterChangesTest { @ValueSource(strings = ["", "util", "util,main", "main"]) fun `remove module`(unloaded: String) { val unloadedHolder = unloadedHolder(unloaded) - checkSaveProjectAfterChange("directoryBased/removeModule", "fileBased/removeModule", unloadedHolder) { - mainBuilder, _, unloadedEntitiesBuilder, _ -> + checkSaveProjectAfterChange("directoryBased/removeModule", "fileBased/removeModule", + unloadedHolder) { mainBuilder, _, unloadedEntitiesBuilder, _ -> val builder = if (unloadedHolder.isUnloaded("util")) unloadedEntitiesBuilder else mainBuilder val utilModule = builder.entities(ModuleEntity::class.java).first { it.name == "util" } //todo now we need to remove module libraries by hand, maybe we should somehow modify the model instead @@ -137,8 +138,9 @@ class JpsProjectSaveAfterChangesTest { fun `modify library`() { checkSaveProjectAfterChange("directoryBased/modifyLibrary", "fileBased/modifyLibrary") { builder, _, _, configLocation -> val junitLibrary = builder.entities(LibraryEntity::class.java).first { it.name == "junit" } - val root = LibraryRoot(virtualFileManager.fromUrl("jar://${JpsPathUtil.urlToPath(configLocation.baseDirectoryUrlString)}/lib/junit2.jar!/"), - LibraryRootTypeId.COMPILED) + val root = LibraryRoot( + virtualFileManager.fromUrl("jar://${JpsPathUtil.urlToPath(configLocation.baseDirectoryUrlString)}/lib/junit2.jar!/"), + LibraryRootTypeId.COMPILED) builder.modifyEntity(junitLibrary) { roots = mutableListOf(root) } @@ -175,18 +177,21 @@ class JpsProjectSaveAfterChangesTest { private fun unloadedHolder(unloaded: String): UnloadedModulesNameHolder { val unloadedModuleNames = StringUtil.split(unloaded, ",").toSet() - return object: UnloadedModulesNameHolder { + return object : UnloadedModulesNameHolder { override fun isUnloaded(name: String?) = name in unloadedModuleNames override fun hasUnloaded() = !unloadedModuleNames.isEmpty() } } + private fun checkSaveProjectAfterChange(directoryNameForDirectoryBased: String, directoryNameForFileBased: String, unloadedModuleNameHolder: UnloadedModulesNameHolder = UnloadedModulesNameHolder.DUMMY, change: (MutableEntityStorage, MutableEntityStorage, MutableEntityStorage, JpsProjectConfigLocation) -> Unit) { - checkSaveProjectAfterChange(sampleDirBasedProjectFile, directoryNameForDirectoryBased, change, unloadedModuleNameHolder, virtualFileManager, "serialization/reload") - checkSaveProjectAfterChange(sampleFileBasedProjectFile, directoryNameForFileBased, change, unloadedModuleNameHolder, virtualFileManager, "serialization/reload") + checkSaveProjectAfterChange(sampleDirBasedProjectFile, directoryNameForDirectoryBased, change, unloadedModuleNameHolder, + virtualFileManager, "serialization/reload") + checkSaveProjectAfterChange(sampleFileBasedProjectFile, directoryNameForFileBased, change, unloadedModuleNameHolder, virtualFileManager, + "serialization/reload") } } \ No newline at end of file diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAllEntitiesTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAllEntitiesTest.kt index bddb323dcc3a..63d0e1a3337b 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAllEntitiesTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsProjectSaveAllEntitiesTest.kt @@ -8,10 +8,10 @@ import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.workspaceModel.ide.getInstance import com.intellij.workspaceModel.storage.MutableEntityStorage -import com.intellij.workspaceModel.storage.bridgeEntities.addLibraryEntity import com.intellij.workspaceModel.storage.bridgeEntities.LibraryRoot import com.intellij.workspaceModel.storage.bridgeEntities.LibraryRootTypeId import com.intellij.workspaceModel.storage.bridgeEntities.LibraryTableId +import com.intellij.workspaceModel.storage.bridgeEntities.addLibraryEntity import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager import org.junit.Before import org.junit.ClassRule @@ -25,6 +25,7 @@ class JpsProjectSaveAllEntitiesTest { val projectModel = ProjectModelRule() private lateinit var virtualFileManager: VirtualFileUrlManager + @Before fun setUp() { virtualFileManager = VirtualFileUrlManager.getInstance(projectModel.project) diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsSplitModuleAndContentRootTest.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsSplitModuleAndContentRootTest.kt index e9c841ee25f1..eca84de0ae56 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsSplitModuleAndContentRootTest.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/JpsSplitModuleAndContentRootTest.kt @@ -12,18 +12,15 @@ import com.intellij.platform.workspaceModel.jps.JpsProjectFileEntitySource import com.intellij.platform.workspaceModel.jps.OrphanageWorkerEntitySource import com.intellij.testFramework.ApplicationRule import com.intellij.testFramework.rules.ProjectModelRule -import com.intellij.workspaceModel.ide.* +import com.intellij.workspaceModel.ide.EntitiesOrphanage +import com.intellij.workspaceModel.ide.UnloadedModulesNameHolder import com.intellij.workspaceModel.ide.impl.IdeVirtualFileUrlManagerImpl import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.bridgeEntities.* import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue -import org.junit.Assume -import org.junit.Before -import org.junit.ClassRule -import org.junit.Rule -import org.junit.Test +import org.junit.* import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -53,7 +50,8 @@ class JpsSplitModuleAndContentRootTest { @Test fun `add local content root via orphanage`() { - checkSaveProjectAfterChange("after/addContentRootOrphanage", "after/addContentRootOrphanage", false) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("after/addContentRootOrphanage", "after/addContentRootOrphanage", + false) { builder, orphanage, configLocation -> assertTrue(builder.entities(ModuleEntity::class.java).toList().isEmpty()) assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().entitySource !is OrphanageWorkerEntitySource) } @@ -62,20 +60,24 @@ class JpsSplitModuleAndContentRootTest { @Test fun `add local source root via orphanage`() { Assume.assumeTrue(EntitiesOrphanage.isEnabled) - checkSaveProjectAfterChange("after/addSourceRootOrphanage", "after/addSourceRootOrphanage", false) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("after/addSourceRootOrphanage", "after/addSourceRootOrphanage", + false) { builder, orphanage, configLocation -> assertTrue(builder.entities(ModuleEntity::class.java).toList().isEmpty()) assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().entitySource is OrphanageWorkerEntitySource) - assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().sourceRoots.single().entitySource !is OrphanageWorkerEntitySource) + assertTrue(orphanage.entities( + ModuleEntity::class.java).single().contentRoots.single().sourceRoots.single().entitySource !is OrphanageWorkerEntitySource) } } @Test fun `add local content and source root via orphanage`() { Assume.assumeTrue(EntitiesOrphanage.isEnabled) - checkSaveProjectAfterChange("after/addSourceAndContentRootOrphanage", "after/addSourceAndContentRootOrphanage", false) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("after/addSourceAndContentRootOrphanage", "after/addSourceAndContentRootOrphanage", + false) { builder, orphanage, configLocation -> assertTrue(builder.entities(ModuleEntity::class.java).toList().isEmpty()) assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().entitySource !is OrphanageWorkerEntitySource) - assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().sourceRoots.single().entitySource !is OrphanageWorkerEntitySource) + assertTrue(orphanage.entities( + ModuleEntity::class.java).single().contentRoots.single().sourceRoots.single().entitySource !is OrphanageWorkerEntitySource) } } @@ -85,17 +87,20 @@ class JpsSplitModuleAndContentRootTest { checkSaveProjectAfterChange("after/addExcludeOrphanage", "after/addExcludeOrphanage", false) { builder, orphanage, configLocation -> assertTrue(builder.entities(ModuleEntity::class.java).toList().isEmpty()) assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().entitySource is OrphanageWorkerEntitySource) - assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().excludedUrls.single().entitySource !is OrphanageWorkerEntitySource) + assertTrue(orphanage.entities( + ModuleEntity::class.java).single().contentRoots.single().excludedUrls.single().entitySource !is OrphanageWorkerEntitySource) } } @Test fun `add local exclude and content root via orphanage`() { Assume.assumeTrue(EntitiesOrphanage.isEnabled) - checkSaveProjectAfterChange("after/addExcludeAndContentRootOrphanage", "after/addExcludeAndContentRootOrphanage", false) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("after/addExcludeAndContentRootOrphanage", "after/addExcludeAndContentRootOrphanage", + false) { builder, orphanage, configLocation -> assertTrue(builder.entities(ModuleEntity::class.java).toList().isEmpty()) assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().entitySource !is OrphanageWorkerEntitySource) - assertTrue(orphanage.entities(ModuleEntity::class.java).single().contentRoots.single().excludedUrls.single().entitySource !is OrphanageWorkerEntitySource) + assertTrue(orphanage.entities( + ModuleEntity::class.java).single().contentRoots.single().excludedUrls.single().entitySource !is OrphanageWorkerEntitySource) } } @@ -486,7 +491,8 @@ class JpsSplitModuleAndContentRootTest { @Test fun `load mixed exclude 2`() { - checkSaveProjectAfterChange("after/addExcludeWithDifferentOrder1", "after/addExcludeWithDifferentOrder1") { builder, _, configLocation -> + checkSaveProjectAfterChange("after/addExcludeWithDifferentOrder1", + "after/addExcludeWithDifferentOrder1") { builder, _, configLocation -> val moduleEntity = builder.entities(ModuleEntity::class.java).single() val contentRootEntity = moduleEntity.contentRoots.single() val exclude = contentRootEntity.excludedUrls @@ -496,7 +502,8 @@ class JpsSplitModuleAndContentRootTest { @Test fun `load mixed exclude 3`() { - checkSaveProjectAfterChange("after/addExcludeWithDifferentOrder2", "after/addExcludeWithDifferentOrder2") { builder, _, configLocation -> + checkSaveProjectAfterChange("after/addExcludeWithDifferentOrder2", + "after/addExcludeWithDifferentOrder2") { builder, _, configLocation -> val moduleEntity = builder.entities(ModuleEntity::class.java).single() val contentRootEntity = moduleEntity.contentRoots.single() val exclude = contentRootEntity.excludedUrls @@ -556,7 +563,8 @@ class JpsSplitModuleAndContentRootTest { @TestFor(classes = [JavaModuleSettingsEntity::class, ModuleImlFileEntitiesSerializer::class, JavaSettingsSerializer::class]) @Test fun `load module without java custom settings but with exclude`() { - checkSaveProjectAfterChange("after/imlWithoutJavaSettingsButWithExclude", "after/imlWithoutJavaSettingsButWithExclude") { builder, _, _ -> + checkSaveProjectAfterChange("after/imlWithoutJavaSettingsButWithExclude", + "after/imlWithoutJavaSettingsButWithExclude") { builder, _, _ -> val javaSettings = builder.entities(ModuleEntity::class.java).single().javaSettings assertNotNull(javaSettings) assertTrue(javaSettings.excludeOutput) @@ -582,14 +590,16 @@ class JpsSplitModuleAndContentRootTest { @Test fun `load incorrect saved additional root`() { - checkSaveProjectAfterChange("before/loadIncorrectSavedAdditionalRoots", "after/loadIncorrectSavedAdditionalRoots", forceFilesRewrite = true) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("before/loadIncorrectSavedAdditionalRoots", "after/loadIncorrectSavedAdditionalRoots", + forceFilesRewrite = true) { builder, orphanage, configLocation -> // Nothing } } @Test fun `load and remove additional root`() { - checkSaveProjectAfterChange("before/loadAndRemoveAdditionalRoot", "after/loadAndRemoveAdditionalRootY", forceFilesRewrite = true) { builder, orphanage, configLocation -> + checkSaveProjectAfterChange("before/loadAndRemoveAdditionalRoot", "after/loadAndRemoveAdditionalRootY", + forceFilesRewrite = true) { builder, orphanage, configLocation -> val toRemove = builder.entities(ModuleEntity::class.java).single().contentRoots.filter { it.entitySource !is JpsImportedEntitySource } toRemove.forEach { builder.removeEntity(it) } } diff --git a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/jpsTestUtils.kt b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/jpsTestUtils.kt index 4b181e53f5c5..2eec5bcae0e1 100644 --- a/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/jpsTestUtils.kt +++ b/platform/workspaceModel/jps/tests/testSrc/com/intellij/workspaceModel/ide/impl/jps/serialization/jpsTestUtils.kt @@ -23,13 +23,15 @@ import com.intellij.platform.workspaceModel.jps.JpsFileEntitySource import com.intellij.platform.workspaceModel.jps.JpsGlobalFileEntitySource import com.intellij.platform.workspaceModel.jps.JpsProjectConfigLocation import com.intellij.platform.workspaceModel.jps.JpsProjectFileEntitySource +import com.intellij.platform.workspaceModel.jps.serialization.impl.FileInDirectorySourceNames import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.replaceService import com.intellij.util.LineSeparator import com.intellij.util.io.assertMatches import com.intellij.util.io.directoryContentOf -import com.intellij.workspaceModel.ide.* -import com.intellij.platform.workspaceModel.jps.serialization.impl.FileInDirectorySourceNames +import com.intellij.workspaceModel.ide.JpsGlobalModelSynchronizer +import com.intellij.workspaceModel.ide.UnloadedModulesNameHolder +import com.intellij.workspaceModel.ide.getGlobalInstance import com.intellij.workspaceModel.ide.impl.GlobalWorkspaceModel import com.intellij.workspaceModel.storage.* import com.intellij.workspaceModel.storage.impl.url.toVirtualFileUrl @@ -78,14 +80,16 @@ internal fun copyAndLoadProject(originalProjectFile: File, val configLocation = toConfigLocation(projectFile.toPath(), virtualFileManager) val unloadedEntitiesBuilder = MutableEntityStorage.create() val orphanage = MutableEntityStorage.create() - val serializers = loadProject(configLocation, originalBuilder, orphanage, virtualFileManager, externalStorageConfigurationManager = externalStorageConfigurationManager, + val serializers = loadProject(configLocation, originalBuilder, orphanage, virtualFileManager, + externalStorageConfigurationManager = externalStorageConfigurationManager, unloadedModuleNameHolder = unloadedModuleNameHolder, unloadedEntitiesBuilder = unloadedEntitiesBuilder) as JpsProjectSerializersImpl val loadedProjectData = LoadedProjectData(originalBuilder.toSnapshot(), orphanage.toSnapshot(), unloadedEntitiesBuilder.toSnapshot(), serializers, configLocation, originalProjectDir) if (checkConsistencyAfterLoading) { - serializers.checkConsistency(loadedProjectData.configLocation, loadedProjectData.storage, loadedProjectData.unloadedEntitiesStorage, virtualFileManager) + serializers.checkConsistency(loadedProjectData.configLocation, loadedProjectData.storage, loadedProjectData.unloadedEntitiesStorage, + virtualFileManager) } return loadedProjectData } @@ -108,7 +112,8 @@ internal fun loadProject(configLocation: JpsProjectConfigLocation, errorReporter: ErrorReporter = TestErrorReporter): JpsProjectSerializers { val cacheDirUrl = configLocation.baseDirectoryUrl.append("cache") val isExternalStorageEnabled = externalStorageConfigurationManager != null && externalStorageConfigurationManager.isEnabled - val context = SerializationContextForTests(virtualFileManager, CachingJpsFileContentReader(configLocation), isExternalStorageEnabled, fileInDirectorySourceNames) + val context = SerializationContextForTests(virtualFileManager, CachingJpsFileContentReader(configLocation), isExternalStorageEnabled, + fileInDirectorySourceNames) return runUnderModalProgressIfIsEdt { JpsProjectEntitiesLoader.loadProject(configLocation, originalBuilder, @@ -130,7 +135,9 @@ fun JpsProjectSerializersImpl.saveAllEntities(storage: EntityStorage, configLoca } internal fun assertDirectoryMatches(actualDir: File, expectedDir: File, filesToIgnore: Set, componentsToIgnore: List) { - val actualFiles = actualDir.walk().filter { it.isFile }.associateBy { FileUtil.toSystemIndependentName(FileUtil.getRelativePath(actualDir, it)!!) } + val actualFiles = actualDir.walk().filter { it.isFile }.associateBy { + FileUtil.toSystemIndependentName(FileUtil.getRelativePath(actualDir, it)!!) + } val expectedFiles = expectedDir.walk() .filter { it.isFile } .associateBy { FileUtil.toSystemIndependentName(FileUtil.getRelativePath(expectedDir, it)!!) } @@ -170,7 +177,8 @@ internal fun createProjectSerializers( val externalStoragePath = projectDir.toPath().resolve("cache") val isExternalStorageEnabled = externalStorageConfigurationManager != null && externalStorageConfigurationManager.isEnabled val context = SerializationContextForTests(virtualFileManager, reader, isExternalStorageEnabled) - val serializer = JpsProjectEntitiesLoader.createProjectSerializers(configLocation, externalStoragePath, context) as JpsProjectSerializersImpl + val serializer = JpsProjectEntitiesLoader.createProjectSerializers(configLocation, externalStoragePath, + context) as JpsProjectSerializersImpl return serializer to configLocation } @@ -185,7 +193,9 @@ fun JpsProjectSerializersImpl.checkConsistency(configLocation: JpsProjectConfigL directorySerializerFactoriesByUrl.forEach { (url, directorySerializer) -> assertEquals(url, directorySerializer.directoryUrl) val fileSerializers = serializerToDirectoryFactory.getKeysByValue(directorySerializer) ?: emptyList() - val directoryFileUrls = JpsPathUtil.urlToFile(url).listFiles { file: File -> file.isFile }?.map { JpsPathUtil.pathToUrl(it.systemIndependentPath) } ?: emptyList() + val directoryFileUrls = JpsPathUtil.urlToFile(url).listFiles { file: File -> file.isFile }?.map { + JpsPathUtil.pathToUrl(it.systemIndependentPath) + } ?: emptyList() assertEquals(directoryFileUrls.sorted(), fileSerializers.map { getNonNullActualFileUrl(it.internalEntitySource) }.sorted()) } @@ -193,7 +203,8 @@ fun JpsProjectSerializersImpl.checkConsistency(configLocation: JpsProjectConfigL assertEquals(url, fileSerializer.fileUrl) val fileSerializers = moduleSerializers.getKeysByValue(fileSerializer) ?: emptyList() val urlsFromFactory = fileSerializer.loadFileList(CachingJpsFileContentReader(configLocation), virtualFileManager) - assertEquals(urlsFromFactory.map { it.first.url }.sorted(), fileSerializers.map { getNonNullActualFileUrl(it.internalEntitySource) }.sorted()) + assertEquals(urlsFromFactory.map { it.first.url }.sorted(), + fileSerializers.map { getNonNullActualFileUrl(it.internalEntitySource) }.sorted()) } fileSerializersByUrl.keys.associateWith { fileSerializersByUrl.getValues(it) }.forEach { (url, serializers) -> @@ -212,21 +223,24 @@ fun JpsProjectSerializersImpl.checkConsistency(configLocation: JpsProjectConfigL fun isSerializerWithoutEntities(serializer: JpsFileEntitiesSerializer) = serializer is JpsFileEntityTypeSerializer && storage.entities(serializer.mainEntityClass).none { serializer.entityFilter(it) } - && unloadedEntitiesStorage.entities(serializer.mainEntityClass).none { serializer.entityFilter(it) } + && unloadedEntitiesStorage.entities(serializer.mainEntityClass).none { serializer.entityFilter(it) } val allSources = storage.entitiesBySource { true } + unloadedEntitiesStorage.entitiesBySource { true } val urlsFromSources = allSources.keys.filterIsInstance().mapTo(HashSet()) { getNonNullActualFileUrl(it) } assertEquals(urlsFromSources.sorted(), fileSerializersByUrl.keys.associateWith { fileSerializersByUrl.getValues(it) } - .filterNot { entry -> entry.value.all { isSerializerWithoutEntities(it)} }.map { it.key }.sorted()) + .filterNot { entry -> entry.value.all { isSerializerWithoutEntities(it) } }.map { it.key }.sorted()) - val fileIdFromEntities = allSources.keys.filterIsInstance(JpsProjectFileEntitySource.FileInDirectory::class.java).mapTo(HashSet()) { it.fileNameId } + val fileIdFromEntities = allSources.keys.filterIsInstance(JpsProjectFileEntitySource.FileInDirectory::class.java).mapTo( + HashSet()) { it.fileNameId } val unregisteredIds = fileIdFromEntities - fileIdToFileName.keys.toSet() assertTrue("Some fileNameId aren't registered: ${unregisteredIds}", unregisteredIds.isEmpty()) val staleIds = fileIdToFileName.keys.toSet() - fileIdFromEntities - assertTrue("There are stale mapping for some fileNameId: ${staleIds.joinToString { "$it -> ${fileIdToFileName.get(it)}" }}", staleIds.isEmpty()) + assertTrue("There are stale mapping for some fileNameId: ${staleIds.joinToString { "$it -> ${fileIdToFileName.get(it)}" }}", + staleIds.isEmpty()) } -internal fun File.asConfigLocation(virtualFileManager: VirtualFileUrlManager): JpsProjectConfigLocation = toConfigLocation(toPath(), virtualFileManager) +internal fun File.asConfigLocation(virtualFileManager: VirtualFileUrlManager): JpsProjectConfigLocation = toConfigLocation(toPath(), + virtualFileManager) internal fun toConfigLocation(file: Path, virtualFileManager: VirtualFileUrlManager): JpsProjectConfigLocation { if (FileUtil.extensionEquals(file.fileName.toString(), "ipr")) { @@ -352,11 +366,13 @@ internal fun checkSaveProjectAfterChange(originalProjectFile: File, checkConsistencyAfterLoading: Boolean = true, externalStorageConfigurationManager: ExternalStorageConfigurationManager? = null, forceAllFilesRewrite: Boolean = false) { - val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager, unloadedModuleNameHolder, checkConsistencyAfterLoading, externalStorageConfigurationManager) + val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager, unloadedModuleNameHolder, checkConsistencyAfterLoading, + externalStorageConfigurationManager) val builder = MutableEntityStorage.from(projectData.storage) val unloadedEntitiesBuilder = MutableEntityStorage.from(projectData.unloadedEntitiesStorage) change(builder, projectData.orphanage.toBuilder(), unloadedEntitiesBuilder, projectData.configLocation) - val changesList = builder.collectChanges(projectData.storage).values + unloadedEntitiesBuilder.collectChanges(projectData.unloadedEntitiesStorage).values + val changesList = builder.collectChanges(projectData.storage).values + unloadedEntitiesBuilder.collectChanges( + projectData.unloadedEntitiesStorage).values val changedSources = changesList.flatMapTo(HashSet()) { changes -> changes.flatMap { change -> when (change) { @@ -375,7 +391,8 @@ internal fun checkSaveProjectAfterChange(originalProjectFile: File, .associate { it.fileUrl.url to it.modulePath.path } writer.writeFiles(modulePathMapping) if (checkConsistencyAfterLoading) { - projectData.serializers.checkConsistency(projectData.configLocation, builder.toSnapshot(), unloadedEntitiesBuilder.toSnapshot(), virtualFileManager) + projectData.serializers.checkConsistency(projectData.configLocation, builder.toSnapshot(), unloadedEntitiesBuilder.toSnapshot(), + virtualFileManager) } val expectedDir = FileUtil.createTempDirectory("jpsProjectTest", "expected") @@ -392,7 +409,11 @@ internal fun checkSaveProjectAfterChange(originalProjectFile: File, assertDirectoryMatches(projectData.projectDir, expectedDir, emptySet(), emptyList()) } -internal fun copyAndLoadGlobalEntities(originalFile: String? = null, expectedFile: String? = null, testDir: File, parentDisposable: Disposable, action: (JpsGlobalFileEntitySource) -> Unit) { +internal fun copyAndLoadGlobalEntities(originalFile: String? = null, + expectedFile: String? = null, + testDir: File, + parentDisposable: Disposable, + action: (JpsGlobalFileEntitySource) -> Unit) { val optionsFolder = testDir.resolve("options") PathManager.setExplicitConfigPath(testDir.absolutePath) ApplicationManager.getApplication().stateStore.setPath(testDir.toPath()) @@ -423,8 +444,10 @@ internal fun copyAndLoadGlobalEntities(originalFile: String? = null, expectedFil // Save current state and check it's expected if (expectedFile != null) { application.invokeAndWait { saveDocumentsAndProjectsAndApp(true) } - val globalEntitiesFolder = File(PathManagerEx.getCommunityHomePath(), "platform/workspaceModel/jps/tests/testData/serialization/globalLibraries/$expectedFile") - optionsFolder.assertMatches(directoryContentOf(globalEntitiesFolder.toPath()), filePathFilter = { it.contains("applicationLibraries.xml") }) + val globalEntitiesFolder = File(PathManagerEx.getCommunityHomePath(), + "platform/workspaceModel/jps/tests/testData/serialization/globalLibraries/$expectedFile") + optionsFolder.assertMatches(directoryContentOf(globalEntitiesFolder.toPath()), + filePathFilter = { it.contains("applicationLibraries.xml") }) } } @@ -432,7 +455,7 @@ internal fun copyAndLoadGlobalEntities(originalFile: String? = null, expectedFil PathManager.setExplicitConfigPath(null) } -internal fun unloadedHolder(unloaded: String) : UnloadedModulesNameHolder { +internal fun unloadedHolder(unloaded: String): UnloadedModulesNameHolder { val unloadedModuleNames = StringUtil.split(unloaded, ",").toSet() return UnloadedModulesNameHolderImpl(unloadedModuleNames) } diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AbstractEntitiesTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AbstractEntitiesTest.kt index 119a2c9f9231..4ba2ed9d1799 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AbstractEntitiesTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AbstractEntitiesTest.kt @@ -36,7 +36,7 @@ class AbstractEntitiesTest { val anotherMiddleEntity = builder.addMiddleEntity("second") builder.modifyEntity(leftEntity) { - + } builder.modifyEntity(leftEntity) { this.children = listOf(anotherMiddleEntity) diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AddChildrenTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AddChildrenTest.kt index 72e405d5d30c..88d630508733 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AddChildrenTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/AddChildrenTest.kt @@ -5,7 +5,6 @@ package com.intellij.platform.workspaceModel.storage.tests import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.MutableEntityStorage import junit.framework.TestCase.* -import kotlinx.coroutines.NonCancellable.children import org.junit.Test class AddChildrenTest { diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/CircularDependencyProhibitedTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/CircularDependencyProhibitedTest.kt index b238ca6f6428..1b1ab1423a7d 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/CircularDependencyProhibitedTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/CircularDependencyProhibitedTest.kt @@ -6,7 +6,6 @@ import com.intellij.workspaceModel.storage.MutableEntityStorage import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows -import java.lang.IllegalStateException class CircularDependencyProhibitedTest { @Test diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntitySourceIndexTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntitySourceIndexTest.kt index 055604390c30..285c7ba515d5 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntitySourceIndexTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntitySourceIndexTest.kt @@ -10,127 +10,127 @@ import org.junit.Assert.assertNull import org.junit.Test class EntitySourceIndexTest { -@Test -fun `base index test`() { - val oldSource = SampleEntitySource("oldSource") - val newSource = SampleEntitySource("newSource") - val builder = createEmptyBuilder() - val entity = builder addEntity SourceEntity("hello", oldSource) - assertEquals((entity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + @Test + fun `base index test`() { + val oldSource = SampleEntitySource("oldSource") + val newSource = SampleEntitySource("newSource") + val builder = createEmptyBuilder() + val entity = builder addEntity SourceEntity("hello", oldSource) + assertEquals((entity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - builder.modifyEntity(entity) { - this.entitySource = newSource + builder.modifyEntity(entity) { + this.entitySource = newSource + } + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) + assertEquals(entity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) + + builder.removeEntity(entity) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) } - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) - assertEquals(entity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) - builder.removeEntity(entity) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) -} + @Test + fun `base index with diff test`() { + val oldSource = SampleEntitySource("oldSource") + val newSource = SampleEntitySource("newSource") + val builder = createEmptyBuilder() + val firstEntity = builder addEntity SourceEntity("one", oldSource) + assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) -@Test -fun `base index with diff test`() { - val oldSource = SampleEntitySource("oldSource") - val newSource = SampleEntitySource("newSource") - val builder = createEmptyBuilder() - val firstEntity = builder addEntity SourceEntity("one", oldSource) - assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + val diff = createBuilderFrom(builder.toSnapshot()) + assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(newSource)) - val diff = createBuilderFrom(builder.toSnapshot()) - assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(newSource)) + val secondEntity = diff addEntity SourceEntity("two", newSource) + assertEquals((secondEntity as SourceEntityImpl.Builder).id, diff.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) + assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) - val secondEntity = diff addEntity SourceEntity("two", newSource) - assertEquals((secondEntity as SourceEntityImpl.Builder).id, diff.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) - assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) - - builder.addDiff(diff) - assertEquals(secondEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) - assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) -} - -@Test -fun `remove from diff test`() { - val oldSource = SampleEntitySource("oldSource") - val builder = createEmptyBuilder() - val firstEntity = builder addEntity SourceEntity("one", oldSource) - assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - - val diff = createBuilderFrom(builder.toSnapshot()) - assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - - diff.removeEntity(firstEntity.from(diff)) - assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)) - - builder.addDiff(diff) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) -} - -@Test -fun `change source in diff test`() { - val oldSource = SampleEntitySource("oldSource") - val newSource = SampleEntitySource("newSource") - val builder = createEmptyBuilder() - val firstEntity = builder addEntity SourceEntity("one", oldSource) - assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - - val diff = createBuilderFrom(builder.toSnapshot()) - assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(newSource)) - - diff.modifyEntity(firstEntity.from(diff)) { - this.entitySource = newSource + builder.addDiff(diff) + assertEquals(secondEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) + assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) } - assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) - builder.addDiff(diff) - assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) - assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) -} + @Test + fun `remove from diff test`() { + val oldSource = SampleEntitySource("oldSource") + val builder = createEmptyBuilder() + val firstEntity = builder addEntity SourceEntity("one", oldSource) + assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) -@Test -fun `remove entity with child`() { - val entitySource = SampleEntitySource("oldSource") - val builder = createEmptyBuilder() - val firstEntity = builder addEntity SourceEntity("one", entitySource) - val entity = ChildSourceEntity("firstChild", entitySource) { - this.parentEntity = firstEntity + val diff = createBuilderFrom(builder.toSnapshot()) + assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + + diff.removeEntity(firstEntity.from(diff)) + assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)) + + builder.addDiff(diff) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) } - builder.addEntity(entity) - var entities = builder.indexes.entitySourceIndex.getIdsByEntry(entitySource) - assertEquals(2, entities?.size) + @Test + fun `change source in diff test`() { + val oldSource = SampleEntitySource("oldSource") + val newSource = SampleEntitySource("newSource") + val builder = createEmptyBuilder() + val firstEntity = builder addEntity SourceEntity("one", oldSource) + assertEquals((firstEntity as SourceEntityImpl.Builder).id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) - builder.removeEntity(firstEntity) + val diff = createBuilderFrom(builder.toSnapshot()) + assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + assertNull(diff.indexes.entitySourceIndex.getIdsByEntry(newSource)) - entities = builder.indexes.entitySourceIndex.getIdsByEntry(entitySource) - assertNull(entities) -} + diff.modifyEntity(firstEntity.from(diff)) { + this.entitySource = newSource + } + assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)?.single()) + assertEquals(firstEntity.id, diff.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(newSource)) -@Test(expected = AssertionError::class) -fun `test incorrect index`() { - val oldSource = SampleEntitySource("oldSource") - val builder = createEmptyBuilder() - builder addEntity SourceEntity("hello", oldSource) - - builder.indexes.entitySourceIndex.index(createEntityId(1, ClassToIntConverter.INSTANCE.getInt(SourceEntity::class.java)), oldSource) - - builder.assertConsistency() -} - -@Test -fun `add and change source`() { - val oldSource = SampleEntitySource("oldSource") - val builder = createEmptyBuilder() - val entity = builder addEntity SourceEntity("one", oldSource) - builder.modifyEntity(entity) { - this.entitySource = SampleEntitySource("newSource") + builder.addDiff(diff) + assertEquals(firstEntity.id, builder.indexes.entitySourceIndex.getIdsByEntry(newSource)?.single()) + assertNull(builder.indexes.entitySourceIndex.getIdsByEntry(oldSource)) + } + + @Test + fun `remove entity with child`() { + val entitySource = SampleEntitySource("oldSource") + val builder = createEmptyBuilder() + val firstEntity = builder addEntity SourceEntity("one", entitySource) + val entity = ChildSourceEntity("firstChild", entitySource) { + this.parentEntity = firstEntity + } + builder.addEntity(entity) + + var entities = builder.indexes.entitySourceIndex.getIdsByEntry(entitySource) + assertEquals(2, entities?.size) + + builder.removeEntity(firstEntity) + + entities = builder.indexes.entitySourceIndex.getIdsByEntry(entitySource) + assertNull(entities) + } + + @Test(expected = AssertionError::class) + fun `test incorrect index`() { + val oldSource = SampleEntitySource("oldSource") + val builder = createEmptyBuilder() + builder addEntity SourceEntity("hello", oldSource) + + builder.indexes.entitySourceIndex.index(createEntityId(1, ClassToIntConverter.INSTANCE.getInt(SourceEntity::class.java)), oldSource) + + builder.assertConsistency() + } + + @Test + fun `add and change source`() { + val oldSource = SampleEntitySource("oldSource") + val builder = createEmptyBuilder() + val entity = builder addEntity SourceEntity("one", oldSource) + builder.modifyEntity(entity) { + this.entitySource = SampleEntitySource("newSource") + } + builder.assertConsistency() } - builder.assertConsistency() -} } \ No newline at end of file diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntityWithSymbolicIdInPStorageTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntityWithSymbolicIdInPStorageTest.kt index fd3f6da4621f..b3f0e7b4e841 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntityWithSymbolicIdInPStorageTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/EntityWithSymbolicIdInPStorageTest.kt @@ -1,9 +1,9 @@ // 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.platform.workspaceModel.storage.tests +import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.testFramework.UsefulTestCase.assertEmpty import com.intellij.testFramework.UsefulTestCase.assertOneElement -import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.impl.MutableEntityStorageImpl import com.intellij.workspaceModel.storage.impl.assertConsistency import com.intellij.workspaceModel.storage.impl.exceptions.SymbolicIdAlreadyExistsException diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExtensionTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExtensionTest.kt index 9345aa39f95a..513a2983ce80 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExtensionTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExtensionTest.kt @@ -1,11 +1,7 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.workspaceModel.storage.tests -import com.intellij.platform.workspaceModel.storage.testEntities.entities.AttachedEntity -import com.intellij.platform.workspaceModel.storage.testEntities.entities.MainEntity -import com.intellij.platform.workspaceModel.storage.testEntities.entities.MySource -import com.intellij.platform.workspaceModel.storage.testEntities.entities.child -import com.intellij.platform.workspaceModel.storage.testEntities.entities.modifyEntity +import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import org.junit.jupiter.api.Test import kotlin.test.assertEquals import kotlin.test.assertTrue diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExternalEntityMappingTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExternalEntityMappingTest.kt index 6608001c2847..c1a6db9b7e87 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExternalEntityMappingTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ExternalEntityMappingTest.kt @@ -1,11 +1,11 @@ // 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.platform.workspaceModel.storage.tests -import com.intellij.testFramework.UsefulTestCase.assertEmpty import com.intellij.platform.workspaceModel.storage.testEntities.entities.SampleEntity import com.intellij.platform.workspaceModel.storage.testEntities.entities.SampleEntitySource import com.intellij.platform.workspaceModel.storage.testEntities.entities.SourceEntity import com.intellij.platform.workspaceModel.storage.testEntities.entities.modifyEntity +import com.intellij.testFramework.UsefulTestCase.assertEmpty import com.intellij.workspaceModel.storage.EntityStorage import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.impl.external.ExternalEntityMappingImpl diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/GeneratedCodeVersionsTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/GeneratedCodeVersionsTest.kt index add8f33d8f3b..f1c4b208b995 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/GeneratedCodeVersionsTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/GeneratedCodeVersionsTest.kt @@ -18,6 +18,7 @@ import kotlin.test.fail class GeneratedCodeVersionsTest { private var prev_api = 0 private var prev_impl = 0 + @Before fun setUp() { prev_api = CodeGeneratorVersions.API_VERSION @@ -99,16 +100,14 @@ interface SuperSimpleEntity : WorkspaceEntity { } - @GeneratedCodeApiVersion(1000001) @GeneratedCodeImplVersion(1000002) -open class SuperSimpleEntityImpl: SuperSimpleEntity, WorkspaceEntityBase() { +open class SuperSimpleEntityImpl : SuperSimpleEntity, WorkspaceEntityBase() { - - - class Builder(result: SuperSimpleEntityData?): ModifiableWorkspaceEntityBase(result), SuperSimpleEntity.Builder { - constructor(): this(SuperSimpleEntityData()) + class Builder(result: SuperSimpleEntityData?) : ModifiableWorkspaceEntityBase( + result), SuperSimpleEntity.Builder { + constructor() : this(SuperSimpleEntityData()) override fun applyToBuilder(builder: MutableEntityStorage) { if (this.diff != null) { @@ -185,8 +184,6 @@ open class SuperSimpleEntityImpl: SuperSimpleEntity, WorkspaceEntityBase() { } - - override fun connectionIdList(): List { TODO("Not yet implemented") } diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MoveEntitiesBetweenStoragesTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MoveEntitiesBetweenStoragesTest.kt index fa1a6ddfea9e..cf1e1d61368c 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MoveEntitiesBetweenStoragesTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MoveEntitiesBetweenStoragesTest.kt @@ -13,14 +13,14 @@ class MoveEntitiesBetweenStoragesTest { it addEntity SampleEntity(false, "to copy", ArrayList(), HashMap(), VirtualFileUrlManagerImpl().fromUrl("file:///tmp"), SampleEntitySource("test")) }.toSnapshot() - + val target = createEmptyBuilder().also { it.addEntity(snapshot.singleSampleEntity()) }.toSnapshot() val entity = target.singleSampleEntity() assertEquals("to copy", entity.stringProperty) } - + @Test fun `move entity with child`() { val snapshot = createEmptyBuilder().also { @@ -32,7 +32,7 @@ class MoveEntitiesBetweenStoragesTest { optionalParent = parent } }.toSnapshot() - + val target = createEmptyBuilder().also { it.addEntity(snapshot.entities(XParentEntity::class.java).single()) }.toSnapshot() @@ -54,7 +54,7 @@ class MoveEntitiesBetweenStoragesTest { parent2 = childEntity } }.toSnapshot() - + val target = createEmptyBuilder().also { it.addEntity(snapshot.entities(XParentEntity::class.java).single()) }.toSnapshot() diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MutableEntityCollectionTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MutableEntityCollectionTest.kt index 87df5fc0a775..35559af45a6c 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MutableEntityCollectionTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/MutableEntityCollectionTest.kt @@ -69,7 +69,7 @@ class MutableEntityCollectionTest { } makeOperationOnListAndCheck(builder, "/user/foo.txt", removeOperation = true) { entity, vfu -> - entity.fileProperty.removeIf{ it == vfu.single() } + entity.fileProperty.removeIf { it == vfu.single() } } makeOperationOnListAndCheck(builder, "/user/opt/app/a.txt", removeOperation = true) { entity, vfu -> @@ -77,7 +77,7 @@ class MutableEntityCollectionTest { } makeReplaceOnListOperationAndCheck(builder, listOf("/user/a.txt", "/user/f.txt"), listOf("/user/c.txt")) { entity, vfu -> - entity.fileProperty.retainAll(listOf(virtualFileManager.fromUrl ("/user/c.txt"))) + entity.fileProperty.retainAll(listOf(virtualFileManager.fromUrl("/user/c.txt"))) } makeReplaceOnListOperationAndCheck(builder, listOf("/user/c.txt"), listOf("/user/e.txt")) { entity, vfu -> @@ -152,7 +152,7 @@ class MutableEntityCollectionTest { //} makeReplaceOnSetOperationAndCheck(builder, listOf("/user/b.txt", "/user/opt/app/a.txt"), listOf("/user/c.txt")) { entity, vfu -> - entity.fileProperty.retainAll(listOf(virtualFileManager.fromUrl ("/user/c.txt"))) + entity.fileProperty.retainAll(listOf(virtualFileManager.fromUrl("/user/c.txt"))) } // TODO:: Not supported @@ -189,7 +189,8 @@ class MutableEntityCollectionTest { vfuForAction.forEach { if (removeOperation) { assertFalse(virtualFiles.contains(it)) - } else { + } + else { assertTrue(virtualFiles.contains(it)) } } @@ -224,7 +225,7 @@ class MutableEntityCollectionTest { } private fun makeReplaceOnSetOperationAndCheck(builder: MutableEntityStorageImpl, oldUrls: List, newUrls: List, - operation: (SetVFUEntity.Builder, Set) -> Unit) { + operation: (SetVFUEntity.Builder, Set) -> Unit) { val entity = builder.entities(SetVFUEntity::class.java).single() val vfuForAction = oldUrls.map { virtualFileManager.fromUrl(it) }.toSet() @@ -256,7 +257,8 @@ class MutableEntityCollectionTest { vfuForAction.forEach { if (removeOperation) { assertFalse(virtualFiles.contains(it)) - } else { + } + else { assertTrue(virtualFiles.contains(it)) } } diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentAndChildTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentAndChildTest.kt index e4cfea3023ec..6aa652f15f7d 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentAndChildTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentAndChildTest.kt @@ -46,7 +46,8 @@ class ParentAndChildTest { @Test fun `parent with child in builder`() { val entity = ParentEntity("ParentData", MySource) { - child = ChildEntity("ChildData", MySource) } + child = ChildEntity("ChildData", MySource) + } val builder = MutableEntityStorage.create() builder.addEntity(entity) @@ -100,7 +101,8 @@ class ParentAndChildTest { @Test fun `get parent from child`() { val entity = ParentEntity("ParentData", MySource) { - child = ChildEntity("ChildData", MySource) } + child = ChildEntity("ChildData", MySource) + } val builder = MutableEntityStorage.create() builder.addEntity(entity) diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentChildReferenceTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentChildReferenceTest.kt index b8383bcdc2b2..3fb670139816 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentChildReferenceTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ParentChildReferenceTest.kt @@ -10,10 +10,13 @@ import org.junit.jupiter.api.Test import kotlin.test.* class ParentChildReferenceTest { - + companion object { - private val CHILD_CONNECTION_ID: ConnectionId = ConnectionId.create(ParentEntity::class.java, ChildEntity::class.java, ConnectionId.ConnectionType.ONE_TO_ONE, false) - private val CHILDREN_CONNECTION_ID: ConnectionId = ConnectionId.create(ParentMultipleEntity::class.java, ChildMultipleEntity::class.java, ConnectionId.ConnectionType.ONE_TO_MANY, false) + private val CHILD_CONNECTION_ID: ConnectionId = ConnectionId.create(ParentEntity::class.java, ChildEntity::class.java, + ConnectionId.ConnectionType.ONE_TO_ONE, false) + private val CHILDREN_CONNECTION_ID: ConnectionId = ConnectionId.create(ParentMultipleEntity::class.java, + ChildMultipleEntity::class.java, + ConnectionId.ConnectionType.ONE_TO_MANY, false) } @Test diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ReplaceBySourceTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ReplaceBySourceTest.kt index 9c2b27e83770..51817ac4c3ed 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ReplaceBySourceTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/ReplaceBySourceTest.kt @@ -1,14 +1,14 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.workspaceModel.storage.tests +import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.testFramework.UsefulTestCase.assertEmpty import com.intellij.testFramework.UsefulTestCase.assertOneElement -import com.intellij.workspaceModel.storage.bridgeEntities.ContentRootEntity -import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity -import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.EntityChange import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.WorkspaceEntity +import com.intellij.workspaceModel.storage.bridgeEntities.ContentRootEntity +import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity import com.intellij.workspaceModel.storage.impl.* import com.intellij.workspaceModel.storage.impl.url.VirtualFileUrlManagerImpl import com.intellij.workspaceModel.storage.toBuilder @@ -637,7 +637,8 @@ class ReplaceBySourceTest { thisStateCheck { parentEntity assert ReplaceState.Relabel(anotherParent.base.id) - parentEntity.childOne!! assert ReplaceState.Relabel(anotherParent.childOne!!.base.id, setOf(ParentsRef.TargetRef(parentEntity.base.id))) + parentEntity.childOne!! assert ReplaceState.Relabel(anotherParent.childOne!!.base.id, + setOf(ParentsRef.TargetRef(parentEntity.base.id))) } replaceWithCheck { @@ -900,7 +901,8 @@ class ReplaceBySourceTest { thisStateCheck { thisRoot assert ReplaceState.NoChange(replaceRoot.base.id) - thisRoot.children.single() assert ReplaceState.Relabel(replaceRoot.children.single().base.id, setOf(ParentsRef.TargetRef(thisRoot.base.id))) + thisRoot.children.single() assert ReplaceState.Relabel(replaceRoot.children.single().base.id, + setOf(ParentsRef.TargetRef(thisRoot.base.id))) } replaceWithCheck { @@ -1051,14 +1053,14 @@ class ReplaceBySourceTest { builder add TreeMultiparentRootEntity("data", AnotherSource) { this.children = listOf( TreeMultiparentLeafEntity("data", MySource) { - this.children = listOf(TreeMultiparentLeafEntity ("internal", MySource)) + this.children = listOf(TreeMultiparentLeafEntity("internal", MySource)) } ) } replacement add TreeMultiparentRootEntity("data", AnotherSource) { this.children = listOf( TreeMultiparentLeafEntity("data", AnotherSource) { - this.children = listOf(TreeMultiparentLeafEntity ("internal", MySource)) + this.children = listOf(TreeMultiparentLeafEntity("internal", MySource)) } ) } @@ -1088,7 +1090,7 @@ class ReplaceBySourceTest { val replaceWithEntity = replacement add TreeMultiparentRootEntity("data", AnotherSource) { this.children = listOf( TreeMultiparentLeafEntity("data", AnotherSource) { - this.children = listOf(TreeMultiparentLeafEntity ("internal", MySource)) + this.children = listOf(TreeMultiparentLeafEntity("internal", MySource)) } ) } @@ -1109,13 +1111,15 @@ class ReplaceBySourceTest { thisStateCheck { leafsStructure assert ReplaceState.NoChange(replaceWithEntity.base.id) leafsStructure.children.single() assert ReplaceState.NoChange(replaceWithEntity.children.single().base.id) - internalChild assert ReplaceState.Relabel(replaceWithEntity.children.single().children.single().base.id, setOf(ParentsRef.TargetRef(leafsStructure.children.single().base.id))) + internalChild assert ReplaceState.Relabel(replaceWithEntity.children.single().children.single().base.id, + setOf(ParentsRef.TargetRef(leafsStructure.children.single().base.id))) } replaceWithCheck { replaceWithEntity assert ReplaceWithState.NoChange(leafsStructure.base.id) replaceWithEntity.children.single() assert ReplaceWithState.NoChange(leafsStructure.children.single().base.id) - replaceWithEntity.children.single().children.single() assert ReplaceWithState.Relabel(leafsStructure.children.single().children.single().base.id) + replaceWithEntity.children.single().children.single() assert ReplaceWithState.Relabel( + leafsStructure.children.single().children.single().base.id) } } @@ -1780,13 +1784,15 @@ class ReplaceBySourceTest { val anotherBuilder = builder.toSnapshot().toBuilder() - assertNull(builder.entities (ChainedEntity::class.java).single { it.entitySource == MySource }.parent) - assertNotEquals(AnotherSource, builder.entities (ChainedEntity::class.java).single { it.entitySource == AnotherSource }.parent!!.entitySource) + assertNull(builder.entities(ChainedEntity::class.java).single { it.entitySource == MySource }.parent) + assertNotEquals(AnotherSource, + builder.entities(ChainedEntity::class.java).single { it.entitySource == AnotherSource }.parent!!.entitySource) builder.replaceBySource({ true }, anotherBuilder) - assertNull(builder.entities (ChainedEntity::class.java).single { it.entitySource == MySource }.parent) - assertNotEquals(AnotherSource, builder.entities (ChainedEntity::class.java).single { it.entitySource == AnotherSource }.parent!!.entitySource) + assertNull(builder.entities(ChainedEntity::class.java).single { it.entitySource == MySource }.parent) + assertNotEquals(AnotherSource, + builder.entities(ChainedEntity::class.java).single { it.entitySource == AnotherSource }.parent!!.entitySource) } diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/RiderEntitiesTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/RiderEntitiesTest.kt index 79c84b1ed620..e8aebc380be8 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/RiderEntitiesTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/RiderEntitiesTest.kt @@ -88,7 +88,9 @@ class RiderEntitiesTest { val newBuilder = snapshot.toBuilder() val anotherBuilder = snapshot.toBuilder() - var existingProjectModelEntity = anotherBuilder.entities(ProjectModelTestEntity::class.java).single { it.descriptor.data.contains("left") } + var existingProjectModelEntity = anotherBuilder.entities(ProjectModelTestEntity::class.java).single { + it.descriptor.data.contains("left") + } assertNotNull(existingProjectModelEntity.contentRoot) anotherBuilder.modifyEntity(existingProjectModelEntity) { this.descriptor = DescriptorInstance("project model data left") diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/SoftLinksTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/SoftLinksTest.kt index 1ad58821b723..8c57a23ea98a 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/SoftLinksTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/SoftLinksTest.kt @@ -1,8 +1,8 @@ // 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.platform.workspaceModel.storage.tests -import com.intellij.testFramework.UsefulTestCase.assertOneElement import com.intellij.platform.workspaceModel.storage.testEntities.entities.* +import com.intellij.testFramework.UsefulTestCase.assertOneElement import com.intellij.workspaceModel.storage.MutableEntityStorage import com.intellij.workspaceModel.storage.impl.assertConsistency import junit.framework.Assert.assertEquals diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/StorageIndexiesTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/StorageIndexiesTest.kt index 8548b6a481a5..ec5d6bf417db 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/StorageIndexiesTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/StorageIndexiesTest.kt @@ -1,9 +1,9 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.workspaceModel.storage.tests.impl +import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.EntitySource import com.intellij.workspaceModel.storage.MutableEntityStorage -import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.impl.MutableEntityStorageImpl import com.intellij.workspaceModel.storage.impl.url.VirtualFileUrlManagerImpl import com.intellij.workspaceModel.storage.url.VirtualFileUrl diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/VirtualFileUrlManagerTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/VirtualFileUrlManagerTest.kt index 51c1113fe6d2..6d22c10d29f1 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/VirtualFileUrlManagerTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/VirtualFileUrlManagerTest.kt @@ -9,6 +9,7 @@ import org.junit.Test class VirtualFileUrlManagerTest { private lateinit var virtualFileManager: VirtualFileUrlManagerImpl + @Before fun setUp() { virtualFileManager = VirtualFileUrlManagerImpl() diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/containers/NonNegativeIntIntBiMapTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/containers/NonNegativeIntIntBiMapTest.kt index c66311497fe8..41e02dfa91b0 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/containers/NonNegativeIntIntBiMapTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/containers/NonNegativeIntIntBiMapTest.kt @@ -14,8 +14,8 @@ class NonNegativeIntIntBiMapTest { map.putAll(intArrayOf(1), 10) map.putAll(intArrayOf(1), 20) - assertArrayEquals(intArrayOf(1), map.getKeys (20).toArray()) - assertArrayEquals(intArrayOf(), map.getKeys (10).toArray()) + assertArrayEquals(intArrayOf(1), map.getKeys(20).toArray()) + assertArrayEquals(intArrayOf(), map.getKeys(10).toArray()) } @Test @@ -25,7 +25,7 @@ class NonNegativeIntIntBiMapTest { map.putAll(intArrayOf(1), 10) map.putAll(intArrayOf(2), 10) - assertArrayEquals(intArrayOf(1, 2), map.getKeys (10).toArray()) + assertArrayEquals(intArrayOf(1, 2), map.getKeys(10).toArray()) assertEquals(10, map.get(1)) assertEquals(10, map.get(2)) diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/BidirectionalMapPropertyTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/BidirectionalMapPropertyTest.kt index 6a85b7c1ad83..a046b1d4bb1c 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/BidirectionalMapPropertyTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/BidirectionalMapPropertyTest.kt @@ -28,7 +28,8 @@ class BidirectionalMapPropertyTest { } } - private class AddValues(val optimizedMap: BidirectionalMap, val originalMap: OriginalBidirectionalMap) : ImperativeCommand { + private class AddValues(val optimizedMap: BidirectionalMap, + val originalMap: OriginalBidirectionalMap) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { for (i in 1..env.generateValue(Generator.integers(2, 10), null)) { val key = env.generateValue(Generator.integers(-20, 20), null) @@ -43,14 +44,16 @@ class BidirectionalMapPropertyTest { } } - private class GetValues(val optimizedMap: BidirectionalMap, val originalMap: OriginalBidirectionalMap) : ImperativeCommand { + private class GetValues(val optimizedMap: BidirectionalMap, + val originalMap: OriginalBidirectionalMap) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { val key = selectElement(env, originalMap.keys.toList()) ?: return Assert.assertEquals(originalMap[key], optimizedMap[key]) } } - private class RemoveKey(val optimizedMap: BidirectionalMap, val originalMap: OriginalBidirectionalMap) : ImperativeCommand { + private class RemoveKey(val optimizedMap: BidirectionalMap, + val originalMap: OriginalBidirectionalMap) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { val key = selectElement(env, originalMap.keys.toList()) ?: return @@ -61,7 +64,8 @@ class BidirectionalMapPropertyTest { } } - private class RemoveValue(val optimizedMap: BidirectionalMap, val originalMap: OriginalBidirectionalMap) : ImperativeCommand { + private class RemoveValue(val optimizedMap: BidirectionalMap, + val originalMap: OriginalBidirectionalMap) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { val value = selectElement(env, originalMap.values.toList()) ?: return diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/EntityManipulations.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/EntityManipulations.kt index f1594194a1c3..8fbe19f78f91 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/EntityManipulations.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/EntityManipulations.kt @@ -1,9 +1,9 @@ // 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.platform.workspaceModel.storage.tests.propertyBased +import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.EntitySource import com.intellij.workspaceModel.storage.WorkspaceEntity -import com.intellij.platform.workspaceModel.storage.testEntities.entities.* import com.intellij.workspaceModel.storage.impl.* import com.intellij.workspaceModel.storage.impl.exceptions.SymbolicIdAlreadyExistsException import com.intellij.workspaceModel.storage.impl.url.VirtualFileUrlManagerImpl @@ -80,7 +80,8 @@ private class EntitiesBySource(private val storage: MutableEntityStorageImpl) : } } -private class AddDetachedToStorage(private val storage: MutableEntityStorageImpl, private val entities: MutableList) : ImperativeCommand { +private class AddDetachedToStorage(private val storage: MutableEntityStorageImpl, + private val entities: MutableList) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { if (entities.isEmpty()) return val entityIndex = env.generateValue(Generator.integers(0, entities.size - 1), null) @@ -88,7 +89,8 @@ private class AddDetachedToStorage(private val storage: MutableEntityStorageImpl if (someEntity is ModifiableWorkspaceEntityBase<*, *> && someEntity.diff == null) { storage.addEntity(someEntity) env.logMessage("Added ${someEntity.id.asString()} to storage") - } else { + } + else { env.logMessage("Cannot add an entity to storage") } } @@ -162,7 +164,8 @@ internal abstract class AddEntity(protected val storage: MutableEntityStorageImp internal abstract class CreateDetachedEntity(storage: MutableEntityStorageImpl, entityDescription: String, - private val detachedEntities: MutableList) : AddEntity(storage, entityDescription) { + private val detachedEntities: MutableList) : AddEntity(storage, + entityDescription) { override fun performCommand(env: ImperativeCommand.Environment) { val property = env.generateValue(randomNames, null) val source = env.generateValue(sources, null) @@ -181,7 +184,7 @@ internal abstract class CreateDetachedEntity(storage: MutableEntityStorageImpl, } internal abstract class ModifyEntity>(private val entityClass: KClass, - protected val storage: MutableEntityStorageImpl) : ImperativeCommand { + protected val storage: MutableEntityStorageImpl) : ImperativeCommand { abstract fun modifyEntity(env: ImperativeCommand.Environment): List Unit> final override fun performCommand(env: ImperativeCommand.Environment) { @@ -309,7 +312,7 @@ private object OoChildManipulation : EntityManipulation { someProperty: String, env: ImperativeCommand.Environment): Pair { val parentEntity = selectParent(storage, env) ?: return null to "Cannot select parent" - val newChild = storage addEntity OoChildEntity(someProperty, source) { + val newChild = storage addEntity OoChildEntity(someProperty, source) { this.parentEntity = parentEntity } return newChild to "Selected parent: $parentEntity" @@ -485,7 +488,7 @@ private object ParentEntityManipulation : EntityManipulation { override fun makeEntity(source: EntitySource, someProperty: String, env: ImperativeCommand.Environment): Pair { - return storage addEntity XParentEntity(someProperty, source) to "parentProperty: $someProperty" + return storage addEntity XParentEntity(someProperty, source) to "parentProperty: $someProperty" } } } @@ -569,12 +572,12 @@ private fun , T> modifyNulla } private fun > modifyStringProperty(property: KMutableProperty1, - env: ImperativeCommand.Environment): A.() -> Unit { + env: ImperativeCommand.Environment): A.() -> Unit { return modifyNotNullProperty(property, randomNames, env) } private fun > modifyBooleanProperty(property: KMutableProperty1, - env: ImperativeCommand.Environment): A.() -> Unit { + env: ImperativeCommand.Environment): A.() -> Unit { return modifyNotNullProperty(property, Generator.booleans(), env) } @@ -643,7 +646,7 @@ private fun , T> removeInSeq } private fun , T> removeInList(property: KMutableProperty1>, - env: ImperativeCommand.Environment): A.() -> Unit { + env: ImperativeCommand.Environment): A.() -> Unit { return { val value = property.getter.call(this) if (value.any()) { diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/VirtualFileIndexTest.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/VirtualFileIndexTest.kt index d2b020e5c150..b3ab86015026 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/VirtualFileIndexTest.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/propertyBased/VirtualFileIndexTest.kt @@ -23,7 +23,7 @@ class VirtualFileIndexTest { @Rule @JvmField var application = ApplicationRule() - + @Rule @JvmField var temporaryDirectoryRule = TemporaryDirectory() @@ -31,9 +31,9 @@ class VirtualFileIndexTest { @Rule @JvmField var disposableRule = DisposableRule() - + val manager = VirtualFileUrlManagerImpl() - + @Test fun `property test`() { PropertyChecker.checkScenarios { @@ -52,7 +52,7 @@ class VirtualFileIndexTest { } } } - + private inner class AddValue(private val index: VirtualFileIndex.MutableVirtualFileIndex) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { val (pointer, id, prop) = generateData(env) @@ -96,7 +96,8 @@ class VirtualFileIndexTest { } } - private inner class ToImmutable(private val index: VirtualFileIndex.MutableVirtualFileIndex, private val immutables: MutableList) : ImperativeCommand { + private inner class ToImmutable(private val index: VirtualFileIndex.MutableVirtualFileIndex, + private val immutables: MutableList) : ImperativeCommand { override fun performCommand(env: ImperativeCommand.Environment) { immutables.forEach { it.assertConsistency() @@ -134,7 +135,7 @@ class VirtualFileIndexTest { manager.fromPath(file.toString()) } - + internal val entityIdGenerator = Generator.from { env -> val clazz: Class = env.generate>(Generator.sampledFrom( ModuleEntity::class.java, @@ -144,7 +145,7 @@ class VirtualFileIndexTest { ArtifactEntity::class.java, )) val id = env.generate(Generator.integers(0, 100)) - + createEntityId(id, ClassToIntConverter.INSTANCE.getInt(clazz)) } diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/storageTestUtils.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/storageTestUtils.kt index 4ea57551d87b..502deee1ab2f 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/storageTestUtils.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/storageTestUtils.kt @@ -4,8 +4,8 @@ package com.intellij.platform.workspaceModel.storage.tests import com.intellij.workspaceModel.storage.EntityStorage import com.intellij.workspaceModel.storage.MutableEntityStorage -import com.intellij.workspaceModel.storage.impl.MutableEntityStorageImpl import com.intellij.workspaceModel.storage.impl.EntityStorageSnapshotImpl +import com.intellij.workspaceModel.storage.impl.MutableEntityStorageImpl import com.intellij.workspaceModel.storage.impl.assertConsistency fun EntityStorage.checkConsistency() { diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/testUtils.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/testUtils.kt index 3b37dc614022..38cc3b828b77 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/testUtils.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/platform/workspaceModel/storage/tests/testUtils.kt @@ -10,8 +10,6 @@ import com.intellij.workspaceModel.storage.impl.containers.BidirectionalLongMult import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager import junit.framework.TestCase.* import org.junit.Assert -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.function.Executable import java.nio.file.Files import java.util.function.BiPredicate import kotlin.reflect.full.memberProperties @@ -67,7 +65,8 @@ object SerializationRoundTripChecker { val expectedEntities = expectedEntityFamily.entities val actualEntities = actualEntityFamily.entities - assertOrderedEquals(expectedEntities, actualEntities) { a, b -> a == null && b == null || a != null && b != null && a.equalsIgnoringEntitySource(b) } + assertOrderedEquals(expectedEntities, + actualEntities) { a, b -> a == null && b == null || a != null && b != null && a.equalsIgnoringEntitySource(b) } } // Assert refs