mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Workspace Model] Tests reformat
GitOrigin-RevId: 5cca3aa7a719ce4460595b43d67cec10fbb38a5d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e9bdf5c88a
commit
1b9a105d48
+2
-2
@@ -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<EntityChange.Added<SourceRootEntity>>().single { it.entity is SourceRootEntity }
|
||||
|
||||
@Suppress("USELESS_IS_CHECK")
|
||||
val javaSourceRootChange = changes.filterIsInstance<EntityChange.Added<JavaSourceRootPropertiesEntity>>().single { it.entity is JavaSourceRootPropertiesEntity }
|
||||
Assert.assertEquals(File(temp.root, "src2").toVirtualFileUrl(virtualFileManager).url, sourceRootChange.entity.url.url)
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+20
-14
@@ -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<ModifiableRootModel> { ModuleRootManager.getInstance(module).modifiableModel }
|
||||
val modifiableModel = ApplicationManager.getApplication().runReadAction<ModifiableRootModel> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -98,7 +98,7 @@ class ModuleLibraryBridgeTest {
|
||||
ModuleRootModificationUtil.addModuleLibrary(module, antLibraryName, listOf(), emptyList())
|
||||
module
|
||||
}
|
||||
|
||||
|
||||
val moduleRootManager = WriteCommandAction.writeCommandAction(project).compute<ModuleRootManager, RuntimeException> {
|
||||
val moduleRootManager = ModuleRootManager.getInstance(module)
|
||||
moduleRootManager.modifiableModel.let { rootModel ->
|
||||
@@ -110,7 +110,7 @@ class ModuleLibraryBridgeTest {
|
||||
}
|
||||
moduleRootManager
|
||||
}
|
||||
|
||||
|
||||
WriteCommandAction.writeCommandAction(project).run<RuntimeException> {
|
||||
assertModuleLibraryDependency(moduleRootManager, mavenLibraryName)
|
||||
|
||||
@@ -210,7 +210,7 @@ class ModuleLibraryBridgeTest {
|
||||
ModuleRootModificationUtil.addModuleLibrary(module, antLibraryName, listOf(), emptyList())
|
||||
module
|
||||
}
|
||||
|
||||
|
||||
WriteCommandAction.writeCommandAction(project).run<RuntimeException> {
|
||||
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<RuntimeException> {
|
||||
val moduleRootManager = ModuleRootManager.getInstance(module)
|
||||
moduleRootManager.modifiableModel.let { rootModel ->
|
||||
|
||||
+4
-3
@@ -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
|
||||
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleComponent
|
||||
|
||||
@State(name = "XXX")
|
||||
class TestModuleComponent: ModuleComponent, PersistentStateComponent<TestModuleComponent> {
|
||||
class TestModuleComponent : ModuleComponent, PersistentStateComponent<TestModuleComponent> {
|
||||
var testString: String = ""
|
||||
|
||||
override fun getState(): TestModuleComponent = this
|
||||
|
||||
+5
-1
@@ -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)
|
||||
|
||||
+7
-5
@@ -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<WorkspaceModelCacheVersion>("com.intellij.workspaceModel.cache.version")
|
||||
|
||||
private val WORKSPACE_MODEL_CACHE_VERSION_EP = ExtensionPointName.create<WorkspaceModelCacheVersion>(
|
||||
"com.intellij.workspaceModel.cache.version")
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -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()
|
||||
|
||||
+1
-3
@@ -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<JpsProjectSerializers, EntityStorage> {
|
||||
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())
|
||||
|
||||
+20
-15
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -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)
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+8
-4
@@ -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<String>, projectLibrariesNames: List<String>, loadedProjects: List<Project>) {
|
||||
private fun checkLibrariesInStorages(globalLibrariesNames: List<String>,
|
||||
projectLibrariesNames: List<String>,
|
||||
loadedProjects: List<Project>) {
|
||||
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)
|
||||
}
|
||||
|
||||
+13
-9
@@ -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()
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -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<ArtifactOutputPackagingElementEntity>().single().artifact!!.resolve(storage))
|
||||
assertEquals(artifacts[0],
|
||||
archiveChildren.filterIsInstance<ArtifactOutputPackagingElementEntity>().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())
|
||||
|
||||
+24
-14
@@ -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<String>(), storage.projectLibraries.mapTo(HashSet()) {it.name})
|
||||
checkProjectAfterReload("directoryBased/removeAllLibraries",
|
||||
"fileBased/removeAllLibraries") { (storage, originalUnloadedEntitiesBuilder, _) ->
|
||||
assertEquals(emptySet<String>(), 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) }
|
||||
|
||||
+16
-11
@@ -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")
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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)
|
||||
|
||||
+29
-19
@@ -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) }
|
||||
}
|
||||
|
||||
+44
-21
@@ -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<String>, componentsToIgnore: List<String>) {
|
||||
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 <E : WorkspaceEntity> isSerializerWithoutEntities(serializer: JpsFileEntitiesSerializer<E>) =
|
||||
serializer is JpsFileEntityTypeSerializer<E> && 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<JpsFileEntitySource>().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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class AbstractEntitiesTest {
|
||||
|
||||
val anotherMiddleEntity = builder.addMiddleEntity("second")
|
||||
builder.modifyEntity(leftEntity) {
|
||||
|
||||
|
||||
}
|
||||
builder.modifyEntity(leftEntity) {
|
||||
this.children = listOf(anotherMiddleEntity)
|
||||
|
||||
-1
@@ -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 {
|
||||
|
||||
-1
@@ -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
|
||||
|
||||
+108
-108
@@ -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()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-5
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+5
-8
@@ -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<SuperSimpleEntity, SuperSimpleEntityData>(result), SuperSimpleEntity.Builder {
|
||||
constructor(): this(SuperSimpleEntityData())
|
||||
class Builder(result: SuperSimpleEntityData?) : ModifiableWorkspaceEntityBase<SuperSimpleEntity, SuperSimpleEntityData>(
|
||||
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<ConnectionId> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
+4
-4
@@ -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()
|
||||
|
||||
+8
-6
@@ -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<String>, newUrls: List<String>,
|
||||
operation: (SetVFUEntity.Builder, Set<VirtualFileUrl>) -> Unit) {
|
||||
operation: (SetVFUEntity.Builder, Set<VirtualFileUrl>) -> 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))
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
+6
-3
@@ -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
|
||||
|
||||
+20
-14
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -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")
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
@@ -9,6 +9,7 @@ import org.junit.Test
|
||||
|
||||
class VirtualFileUrlManagerTest {
|
||||
private lateinit var virtualFileManager: VirtualFileUrlManagerImpl
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
virtualFileManager = VirtualFileUrlManagerImpl()
|
||||
|
||||
+3
-3
@@ -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))
|
||||
|
||||
+8
-4
@@ -28,7 +28,8 @@ class BidirectionalMapPropertyTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class AddValues(val optimizedMap: BidirectionalMap<Int, Int>, val originalMap: OriginalBidirectionalMap<Int, Int>) : ImperativeCommand {
|
||||
private class AddValues(val optimizedMap: BidirectionalMap<Int, Int>,
|
||||
val originalMap: OriginalBidirectionalMap<Int, Int>) : 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<Int, Int>, val originalMap: OriginalBidirectionalMap<Int, Int>) : ImperativeCommand {
|
||||
private class GetValues(val optimizedMap: BidirectionalMap<Int, Int>,
|
||||
val originalMap: OriginalBidirectionalMap<Int, Int>) : 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<Int, Int>, val originalMap: OriginalBidirectionalMap<Int, Int>) : ImperativeCommand {
|
||||
private class RemoveKey(val optimizedMap: BidirectionalMap<Int, Int>,
|
||||
val originalMap: OriginalBidirectionalMap<Int, Int>) : 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<Int, Int>, val originalMap: OriginalBidirectionalMap<Int, Int>) : ImperativeCommand {
|
||||
private class RemoveValue(val optimizedMap: BidirectionalMap<Int, Int>,
|
||||
val originalMap: OriginalBidirectionalMap<Int, Int>) : ImperativeCommand {
|
||||
override fun performCommand(env: ImperativeCommand.Environment) {
|
||||
val value = selectElement(env, originalMap.values.toList()) ?: return
|
||||
|
||||
|
||||
+13
-10
@@ -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<WorkspaceEntity>) : ImperativeCommand {
|
||||
private class AddDetachedToStorage(private val storage: MutableEntityStorageImpl,
|
||||
private val entities: MutableList<WorkspaceEntity>) : 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<WorkspaceEntity>) : AddEntity(storage, entityDescription) {
|
||||
private val detachedEntities: MutableList<WorkspaceEntity>) : 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<E : WorkspaceEntity, M : WorkspaceEntity.Builder<E>>(private val entityClass: KClass<E>,
|
||||
protected val storage: MutableEntityStorageImpl) : ImperativeCommand {
|
||||
protected val storage: MutableEntityStorageImpl) : ImperativeCommand {
|
||||
abstract fun modifyEntity(env: ImperativeCommand.Environment): List<M.() -> Unit>
|
||||
|
||||
final override fun performCommand(env: ImperativeCommand.Environment) {
|
||||
@@ -309,7 +312,7 @@ private object OoChildManipulation : EntityManipulation {
|
||||
someProperty: String,
|
||||
env: ImperativeCommand.Environment): Pair<WorkspaceEntity?, String> {
|
||||
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<WorkspaceEntity?, String> {
|
||||
return storage addEntity XParentEntity(someProperty, source) to "parentProperty: $someProperty"
|
||||
return storage addEntity XParentEntity(someProperty, source) to "parentProperty: $someProperty"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -569,12 +572,12 @@ private fun <B : WorkspaceEntity, A : WorkspaceEntity.Builder<B>, T> modifyNulla
|
||||
}
|
||||
|
||||
private fun <B : WorkspaceEntity, A : WorkspaceEntity.Builder<B>> modifyStringProperty(property: KMutableProperty1<A, String>,
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
return modifyNotNullProperty(property, randomNames, env)
|
||||
}
|
||||
|
||||
private fun <B : WorkspaceEntity, A : WorkspaceEntity.Builder<B>> modifyBooleanProperty(property: KMutableProperty1<A, Boolean>,
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
return modifyNotNullProperty(property, Generator.booleans(), env)
|
||||
}
|
||||
|
||||
@@ -643,7 +646,7 @@ private fun <B : WorkspaceEntity, A : WorkspaceEntity.Builder<B>, T> removeInSeq
|
||||
}
|
||||
|
||||
private fun <B : WorkspaceEntity, A : WorkspaceEntity.Builder<B>, T> removeInList(property: KMutableProperty1<A, List<T>>,
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
env: ImperativeCommand.Environment): A.() -> Unit {
|
||||
return {
|
||||
val value = property.getter.call(this)
|
||||
if (value.any()) {
|
||||
|
||||
+8
-7
@@ -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<VirtualFileIndex>) : ImperativeCommand {
|
||||
private inner class ToImmutable(private val index: VirtualFileIndex.MutableVirtualFileIndex,
|
||||
private val immutables: MutableList<VirtualFileIndex>) : 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<out WorkspaceEntity> = env.generate<Class<out WorkspaceEntity>>(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))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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() {
|
||||
|
||||
+2
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user