mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 05:51:25 +07:00
[Workspace Model] Review cleanup
GitOrigin-RevId: 7cf9a22cf11ec34820ac1ee53767bac1a2afef30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
09b5c682da
commit
3f11a4f7b1
@@ -59,7 +59,7 @@ public interface ModifiableRootModel extends ModuleRootModel {
|
||||
* @param root root of a content
|
||||
* @return new content entry
|
||||
*/
|
||||
ContentEntry addContentEntry(@NotNull VirtualFile root, ProjectModelExternalSource externalSource);
|
||||
ContentEntry addContentEntry(@NotNull VirtualFile root, @NotNull ProjectModelExternalSource externalSource);
|
||||
|
||||
/**
|
||||
* Adds the specified file or directory as a content root.
|
||||
@@ -77,7 +77,7 @@ public interface ModifiableRootModel extends ModuleRootModel {
|
||||
* @param url root of a content
|
||||
* @return new content entry
|
||||
*/
|
||||
ContentEntry addContentEntry(@NotNull String url, ProjectModelExternalSource externalSource);
|
||||
ContentEntry addContentEntry(@NotNull String url, @NotNull ProjectModelExternalSource externalSource);
|
||||
|
||||
/**
|
||||
* Remove the specified content root.
|
||||
|
||||
@@ -184,7 +184,7 @@ class ModifiableRootModelBridgeImpl(
|
||||
return addContentEntry(root.url)
|
||||
}
|
||||
|
||||
override fun addContentEntry(root: VirtualFile, externalSource: ProjectModelExternalSource?): ContentEntry {
|
||||
override fun addContentEntry(root: VirtualFile, externalSource: ProjectModelExternalSource): ContentEntry {
|
||||
return addContentEntry(root.url, externalSource)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ class ModifiableRootModelBridgeImpl(
|
||||
return addEntityAndContentEntry(url, finalSource)
|
||||
}
|
||||
|
||||
override fun addContentEntry(url: String, externalSource: ProjectModelExternalSource?): ContentEntry {
|
||||
override fun addContentEntry(url: String, externalSource: ProjectModelExternalSource): ContentEntry {
|
||||
assertModelIsLive()
|
||||
|
||||
return addEntityAndContentEntry(url, moduleEntity.entitySource)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="junit" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="kotlin" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
<library name="spring" __external-system-id="GRADLE">
|
||||
<CLASSES />
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -1,26 +1,17 @@
|
||||
package com.intellij.workspaceModel.ide.impl.jps.serialization
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.ApplicationRule
|
||||
import com.intellij.testFramework.rules.ProjectModelRule
|
||||
import com.intellij.workspaceModel.ide.JpsFileEntitySource
|
||||
import com.intellij.workspaceModel.ide.JpsProjectConfigLocation
|
||||
import com.intellij.workspaceModel.ide.impl.IdeVirtualFileUrlManagerImpl
|
||||
import com.intellij.workspaceModel.ide.impl.JpsEntitySourceFactory
|
||||
import com.intellij.workspaceModel.storage.EntityChange
|
||||
import com.intellij.workspaceModel.storage.MutableEntityStorage
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.*
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.api.*
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.api.modifyEntity
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import org.junit.*
|
||||
|
||||
class JpsProjectSaveAfterChangesTest {
|
||||
@Rule
|
||||
@@ -154,41 +145,8 @@ class JpsProjectSaveAfterChangesTest {
|
||||
private fun checkSaveProjectAfterChange(directoryNameForDirectoryBased: String,
|
||||
directoryNameForFileBased: String,
|
||||
change: (MutableEntityStorage, JpsProjectConfigLocation) -> Unit) {
|
||||
checkSaveProjectAfterChange(sampleDirBasedProjectFile, directoryNameForDirectoryBased, change)
|
||||
checkSaveProjectAfterChange(sampleFileBasedProjectFile, directoryNameForFileBased, change)
|
||||
}
|
||||
|
||||
private fun checkSaveProjectAfterChange(originalProjectFile: File, changedFilesDirectoryName: String?,
|
||||
change: (MutableEntityStorage, JpsProjectConfigLocation) -> Unit) {
|
||||
val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager)
|
||||
val builder = MutableEntityStorage.from(projectData.storage)
|
||||
change(builder, projectData.configLocation)
|
||||
val changesMap = builder.collectChanges(projectData.storage)
|
||||
val changedSources = changesMap.values.flatMapTo(HashSet()) { changes -> changes.flatMap { change ->
|
||||
when (change) {
|
||||
is EntityChange.Added -> listOf(change.entity)
|
||||
is EntityChange.Removed -> listOf(change.entity)
|
||||
is EntityChange.Replaced -> listOf(change.oldEntity, change.newEntity)
|
||||
}
|
||||
}.map { it.entitySource }}
|
||||
val writer = JpsFileContentWriterImpl(projectData.configLocation)
|
||||
projectData.serializers.saveEntities(builder.toSnapshot(), changedSources, writer)
|
||||
writer.writeFiles()
|
||||
projectData.serializers.checkConsistency(projectData.configLocation, builder.toSnapshot(), virtualFileManager)
|
||||
|
||||
val expectedDir = FileUtil.createTempDirectory("jpsProjectTest", "expected")
|
||||
FileUtil.copyDir(projectData.originalProjectDir, expectedDir)
|
||||
if (changedFilesDirectoryName != null) {
|
||||
val changedDir = PathManagerEx.findFileUnderCommunityHome("platform/workspaceModel/jps/tests/testData/serialization/reload/$changedFilesDirectoryName")
|
||||
FileUtil.copyDir(changedDir, expectedDir)
|
||||
}
|
||||
expectedDir.walk().filter { it.isFile && it.readText().trim() == "<delete/>" }.forEach {
|
||||
FileUtil.delete(it)
|
||||
}
|
||||
|
||||
assertDirectoryMatches(projectData.projectDir, expectedDir,
|
||||
emptySet(),
|
||||
emptyList())
|
||||
checkSaveProjectAfterChange(sampleDirBasedProjectFile, directoryNameForDirectoryBased, change, virtualFileManager, "serialization/reload")
|
||||
checkSaveProjectAfterChange(sampleFileBasedProjectFile, directoryNameForFileBased, change, virtualFileManager, "serialization/reload")
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.intellij.workspaceModel.ide.impl.jps.serialization
|
||||
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
import com.intellij.openapi.project.ExternalStorageConfigurationManager
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.ApplicationRule
|
||||
import com.intellij.testFramework.rules.ProjectModelRule
|
||||
import com.intellij.workspaceModel.ide.JpsFileEntitySource
|
||||
import com.intellij.workspaceModel.ide.JpsImportedEntitySource
|
||||
import com.intellij.workspaceModel.ide.JpsProjectConfigLocation
|
||||
import com.intellij.workspaceModel.ide.impl.IdeVirtualFileUrlManagerImpl
|
||||
import com.intellij.workspaceModel.storage.EntityChange
|
||||
import com.intellij.workspaceModel.storage.MutableEntityStorage
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.addContentRootEntity
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.addSourceRootEntity
|
||||
@@ -22,7 +20,6 @@ import org.junit.Before
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class JpsSplitModuleAndContentRoot {
|
||||
@Rule
|
||||
@@ -133,59 +130,12 @@ class JpsSplitModuleAndContentRoot {
|
||||
|
||||
val initialDir = PathManagerEx.findFileUnderCommunityHome(
|
||||
"platform/workspaceModel/jps/tests/testData/serialization/splitModuleAndContentRoot/$dirBefore")
|
||||
checkSaveProjectAfterChange(initialDir, dirAfter, change)
|
||||
}
|
||||
|
||||
private fun checkSaveProjectAfterChange(originalProjectFile: File, changedFilesDirectoryName: String?,
|
||||
change: (MutableEntityStorage, JpsProjectConfigLocation) -> Unit) {
|
||||
val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager)
|
||||
val builder = MutableEntityStorage.from(projectData.storage)
|
||||
change(builder, projectData.configLocation)
|
||||
val changesMap = builder.collectChanges(projectData.storage)
|
||||
val changedSources = changesMap.values.flatMapTo(HashSet()) { changes ->
|
||||
changes.flatMap { change ->
|
||||
when (change) {
|
||||
is EntityChange.Added -> listOf(change.entity)
|
||||
is EntityChange.Removed -> listOf(change.entity)
|
||||
is EntityChange.Replaced -> listOf(change.oldEntity, change.newEntity)
|
||||
}
|
||||
}.map { it.entitySource }
|
||||
}
|
||||
val writer = JpsFileContentWriterImpl(projectData.configLocation)
|
||||
projectData.serializers.saveEntities(builder.toSnapshot(), changedSources, writer)
|
||||
writer.writeFiles()
|
||||
//projectData.serializers.checkConsistency(projectData.configLocation, builder.toSnapshot(), virtualFileManager)
|
||||
|
||||
val expectedDir = FileUtil.createTempDirectory("jpsProjectTest", "expected")
|
||||
FileUtil.copyDir(projectData.originalProjectDir, expectedDir)
|
||||
if (changedFilesDirectoryName != null) {
|
||||
val changedDir = PathManagerEx.findFileUnderCommunityHome(
|
||||
"platform/workspaceModel/jps/tests/testData/serialization/splitModuleAndContentRoot/$changedFilesDirectoryName")
|
||||
FileUtil.copyDir(changedDir, expectedDir)
|
||||
}
|
||||
expectedDir.walk().filter { it.isFile && it.readText().trim() == "<delete/>" }.forEach {
|
||||
FileUtil.delete(it)
|
||||
}
|
||||
|
||||
assertDirectoryMatches(projectData.projectDir, expectedDir,
|
||||
emptySet(),
|
||||
emptyList())
|
||||
}
|
||||
|
||||
internal fun copyAndLoadProject(originalProjectFile: File, virtualFileManager: VirtualFileUrlManager): LoadedProjectData {
|
||||
val (projectDir, originalProjectDir) = copyProjectFiles(originalProjectFile)
|
||||
val externalStorageConfigurationManager = ExternalStorageConfigurationManager.getInstance(projectModel.project)
|
||||
externalStorageConfigurationManager.isEnabled = true
|
||||
val originalBuilder = MutableEntityStorage.create()
|
||||
val projectFile = if (originalProjectFile.isFile) File(projectDir, originalProjectFile.name) else projectDir
|
||||
val configLocation = toConfigLocation(projectFile.toPath(), virtualFileManager)
|
||||
val serializers = loadProject(configLocation, originalBuilder, virtualFileManager, externalStorageConfigurationManager = externalStorageConfigurationManager) as JpsProjectSerializersImpl
|
||||
val loadedProjectData = LoadedProjectData(originalBuilder.toSnapshot(), serializers, configLocation, originalProjectDir)
|
||||
//serializers.checkConsistency(loadedProjectData.configLocation, loadedProjectData.storage, virtualFileManager)
|
||||
return loadedProjectData
|
||||
checkSaveProjectAfterChange(initialDir, dirAfter, change, virtualFileManager, "serialization/splitModuleAndContentRoot", false,
|
||||
externalStorageConfigurationManager)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
@ClassRule
|
||||
|
||||
@@ -47,14 +47,19 @@ internal data class LoadedProjectData(
|
||||
get() = File(VfsUtilCore.urlToPath(configLocation.baseDirectoryUrlString))
|
||||
}
|
||||
|
||||
internal fun copyAndLoadProject(originalProjectFile: File, virtualFileManager: VirtualFileUrlManager): LoadedProjectData {
|
||||
internal fun copyAndLoadProject(originalProjectFile: File,
|
||||
virtualFileManager: VirtualFileUrlManager,
|
||||
checkConsistencyAfterLoading: Boolean = true,
|
||||
externalStorageConfigurationManager: ExternalStorageConfigurationManager? = null): LoadedProjectData {
|
||||
val (projectDir, originalProjectDir) = copyProjectFiles(originalProjectFile)
|
||||
val originalBuilder = MutableEntityStorage.create()
|
||||
val projectFile = if (originalProjectFile.isFile) File(projectDir, originalProjectFile.name) else projectDir
|
||||
val configLocation = toConfigLocation(projectFile.toPath(), virtualFileManager)
|
||||
val serializers = loadProject(configLocation, originalBuilder, virtualFileManager) as JpsProjectSerializersImpl
|
||||
val serializers = loadProject(configLocation, originalBuilder, virtualFileManager, externalStorageConfigurationManager = externalStorageConfigurationManager) as JpsProjectSerializersImpl
|
||||
val loadedProjectData = LoadedProjectData(originalBuilder.toSnapshot(), serializers, configLocation, originalProjectDir)
|
||||
serializers.checkConsistency(loadedProjectData.configLocation, loadedProjectData.storage, virtualFileManager)
|
||||
if (checkConsistencyAfterLoading) {
|
||||
serializers.checkConsistency(loadedProjectData.configLocation, loadedProjectData.storage, virtualFileManager)
|
||||
}
|
||||
return loadedProjectData
|
||||
}
|
||||
|
||||
@@ -267,4 +272,45 @@ internal object TestErrorReporter : ErrorReporter {
|
||||
override fun reportError(message: String, file: VirtualFileUrl) {
|
||||
throw AssertionFailedError("Failed to load ${file.url}: $message")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun checkSaveProjectAfterChange(originalProjectFile: File,
|
||||
changedFilesDirectoryName: String?,
|
||||
change: (MutableEntityStorage, JpsProjectConfigLocation) -> Unit,
|
||||
virtualFileManager: VirtualFileUrlManager,
|
||||
testDir: String,
|
||||
checkConsistencyAfterLoading: Boolean = true,
|
||||
externalStorageConfigurationManager: ExternalStorageConfigurationManager? = null) {
|
||||
val projectData = copyAndLoadProject(originalProjectFile, virtualFileManager, checkConsistencyAfterLoading, externalStorageConfigurationManager)
|
||||
val builder = MutableEntityStorage.from(projectData.storage)
|
||||
change(builder, projectData.configLocation)
|
||||
val changesMap = builder.collectChanges(projectData.storage)
|
||||
val changedSources = changesMap.values.flatMapTo(HashSet()) { changes ->
|
||||
changes.flatMap { change ->
|
||||
when (change) {
|
||||
is EntityChange.Added -> listOf(change.entity)
|
||||
is EntityChange.Removed -> listOf(change.entity)
|
||||
is EntityChange.Replaced -> listOf(change.oldEntity, change.newEntity)
|
||||
}
|
||||
}.map { it.entitySource }
|
||||
}
|
||||
val writer = JpsFileContentWriterImpl(projectData.configLocation)
|
||||
projectData.serializers.saveEntities(builder.toSnapshot(), changedSources, writer)
|
||||
writer.writeFiles()
|
||||
if (checkConsistencyAfterLoading) {
|
||||
projectData.serializers.checkConsistency(projectData.configLocation, builder.toSnapshot(), virtualFileManager)
|
||||
}
|
||||
|
||||
val expectedDir = FileUtil.createTempDirectory("jpsProjectTest", "expected")
|
||||
FileUtil.copyDir(projectData.originalProjectDir, expectedDir)
|
||||
if (changedFilesDirectoryName != null) {
|
||||
val changedDir = PathManagerEx.findFileUnderCommunityHome(
|
||||
"platform/workspaceModel/jps/tests/testData/$testDir/$changedFilesDirectoryName")
|
||||
FileUtil.copyDir(changedDir, expectedDir)
|
||||
}
|
||||
expectedDir.walk().filter { it.isFile && it.readText().trim() == "<delete/>" }.forEach {
|
||||
FileUtil.delete(it)
|
||||
}
|
||||
|
||||
assertDirectoryMatches(projectData.projectDir, expectedDir, emptySet(), emptyList())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user