mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ensure that VFS is not used for product specific workspace file
GitOrigin-RevId: 1119a20467c45f33ee774f97f3d22372e09b51d6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b5b8373903
commit
ac1f0a41de
@@ -52,8 +52,17 @@ class ApplicationStoreImpl(private val application: Application, pathMacroManage
|
||||
override fun toString() = "app"
|
||||
}
|
||||
|
||||
internal val appFileBasedStorageConfiguration = object: FileBasedStorageConfiguration {
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = false
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
class ApplicationStorageManager(application: Application?, pathMacroManager: PathMacroManager? = null)
|
||||
: StateStorageManagerImpl("application", pathMacroManager?.createTrackingSubstitutor(), application) {
|
||||
override fun getFileBasedStorageConfiguration(fileSpec: String) = appFileBasedStorageConfiguration
|
||||
|
||||
override fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? {
|
||||
return when (component) {
|
||||
@@ -72,9 +81,6 @@ class ApplicationStorageManager(application: Application?, pathMacroManager: Pat
|
||||
override val isUseXmlProlog: Boolean
|
||||
get() = false
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = false
|
||||
|
||||
override fun providerDataStateChanged(storage: FileBasedStorage, writer: DataWriter?, type: DataStateChanged) {
|
||||
// IDEA-144052 When "Settings repository" is enabled changes in 'Path Variables' aren't saved to default path.macros.xml file causing errors in build process
|
||||
if (storage.fileSpec == "path.macros.xml" || storage.fileSpec == "applicationLibraries.xml") {
|
||||
|
||||
@@ -231,7 +231,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
@CalledInAwt
|
||||
override fun saveComponent(component: PersistentStateComponent<*>) {
|
||||
val stateSpec = getStateSpec(component)
|
||||
LOG.info("saveComponent is called for ${stateSpec.name}")
|
||||
LOG.debug { "saveComponent is called for ${stateSpec.name}" }
|
||||
val saveManager = createSaveSessionProducerManager()
|
||||
commitComponent(saveManager, ComponentInfoImpl(component, stateSpec), null)
|
||||
val absolutePath = Paths.get(storageManager.expandMacros(findNonDeprecated(stateSpec.storages).path)).toAbsolutePath().toString()
|
||||
@@ -242,8 +242,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
val saveResult = saveManager.save()
|
||||
saveResult.throwIfErrored()
|
||||
|
||||
val isSomethingChanged = saveResult.isChanged
|
||||
if (!isSomethingChanged) {
|
||||
if (!saveResult.isChanged) {
|
||||
LOG.info("saveApplicationComponent is called for ${stateSpec.name} but nothing to save")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ open class FileBasedStorage(file: Path,
|
||||
var file = file
|
||||
private set
|
||||
|
||||
protected open val configuration: FileBasedStorageConfiguration = defaultFileBasedStorageConfiguration
|
||||
protected open val configuration: FileBasedStorageConfiguration
|
||||
get() = defaultFileBasedStorageConfiguration
|
||||
|
||||
init {
|
||||
val app = ApplicationManager.getApplication()
|
||||
@@ -57,7 +58,7 @@ open class FileBasedStorage(file: Path,
|
||||
|
||||
protected open val isUseXmlProlog = false
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
final override val isUseVfsForWrite: Boolean
|
||||
get() = configuration.isUseVfsForWrite
|
||||
|
||||
private val isUseUnixLineSeparator: Boolean
|
||||
|
||||
@@ -9,17 +9,13 @@ interface FileBasedStorageConfiguration {
|
||||
|
||||
val isUseVfsForWrite: Boolean
|
||||
|
||||
fun resolveVirtualFile(path: String): VirtualFile?
|
||||
fun resolveVirtualFile(path: String): VirtualFile? = LocalFileSystem.getInstance().findFileByPath(path)
|
||||
}
|
||||
|
||||
internal val defaultFileBasedStorageConfiguration: FileBasedStorageConfiguration = object: FileBasedStorageConfiguration {
|
||||
internal val defaultFileBasedStorageConfiguration: FileBasedStorageConfiguration = object : FileBasedStorageConfiguration {
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = false
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = true
|
||||
|
||||
override fun resolveVirtualFile(path: String): VirtualFile? {
|
||||
return LocalFileSystem.getInstance().findFileByPath(path)
|
||||
}
|
||||
}
|
||||
@@ -65,12 +65,11 @@ internal class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubs
|
||||
override val isExternalSystemStorageEnabled: Boolean
|
||||
get() = (componentManager as Module).project.isExternalStorageEnabled
|
||||
|
||||
override fun createFileBasedStorage(path: String, collapsedPath: String, roamingType: RoamingType, rootTagName: String?): StateStorage
|
||||
= ModuleFileStorage(this, Paths.get(path), collapsedPath, rootTagName, roamingType, getMacroSubstitutor(collapsedPath), if (roamingType == RoamingType.DISABLED) null else compoundStreamProvider)
|
||||
override fun createFileBasedStorage(path: String, collapsedPath: String, roamingType: RoamingType, rootTagName: String?): StateStorage {
|
||||
return ModuleFileStorage(this, Paths.get(path), collapsedPath, rootTagName, roamingType, getMacroSubstitutor(collapsedPath), if (roamingType == RoamingType.DISABLED) null else compoundStreamProvider)
|
||||
}
|
||||
|
||||
// use VFS to load module file because it is refreshed and loaded into VFS in any case
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = true
|
||||
override fun getFileBasedStorageConfiguration(fileSpec: String) = moduleFileBasedStorageConfiguration
|
||||
|
||||
private class ModuleFileStorage(storageManager: ModuleStateStorageManager,
|
||||
file: Path,
|
||||
@@ -85,4 +84,13 @@ internal class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val moduleFileBasedStorageConfiguration = object : FileBasedStorageConfiguration {
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = true
|
||||
|
||||
// use VFS to load module file because it is refreshed and loaded into VFS in any case
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
@@ -21,6 +21,28 @@ open class ProjectStateStorageManager(macroSubstitutor: PathMacroSubstitutor,
|
||||
const val ROOT_TAG_NAME = "project"
|
||||
}
|
||||
|
||||
private val fileBasedStorageConfiguration = object : FileBasedStorageConfiguration {
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = true
|
||||
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = project is VirtualFileResolver
|
||||
|
||||
override fun resolveVirtualFile(path: String): VirtualFile? {
|
||||
return when (project) {
|
||||
is VirtualFileResolver -> project.resolveVirtualFile(path)
|
||||
else -> super.resolveVirtualFile(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFileBasedStorageConfiguration(fileSpec: String): FileBasedStorageConfiguration {
|
||||
return when {
|
||||
isSpecialStorage(fileSpec) -> appFileBasedStorageConfiguration
|
||||
else -> fileBasedStorageConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), PROJECT_CONFIG_DIR)
|
||||
|
||||
override fun expandMacros(path: String): String {
|
||||
@@ -46,16 +68,6 @@ open class ProjectStateStorageManager(macroSubstitutor: PathMacroSubstitutor,
|
||||
|
||||
override val isExternalSystemStorageEnabled: Boolean
|
||||
get() = project.isExternalStorageEnabled
|
||||
|
||||
override val isUseVfsForRead: Boolean
|
||||
get() = project is VirtualFileResolver
|
||||
|
||||
override fun resolveVirtualFile(path: String): VirtualFile? {
|
||||
return when (project) {
|
||||
is VirtualFileResolver -> project.resolveVirtualFile(path)
|
||||
else -> super.resolveVirtualFile(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for upsource
|
||||
|
||||
@@ -36,8 +36,7 @@ private val MACRO_PATTERN = Pattern.compile("(\\$[^$]*\\$)")
|
||||
open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
final override val macroSubstitutor: PathMacroSubstitutor? = null,
|
||||
override val componentManager: ComponentManager? = null,
|
||||
private val virtualFileTracker: StorageVirtualFileTracker? = createDefaultVirtualTracker(componentManager)) : StateStorageManager,
|
||||
FileBasedStorageConfiguration by defaultFileBasedStorageConfiguration {
|
||||
private val virtualFileTracker: StorageVirtualFileTracker? = createDefaultVirtualTracker(componentManager)) : StateStorageManager {
|
||||
private val macros: MutableList<Macro> = ContainerUtil.createLockFreeCopyOnWriteList()
|
||||
private val storageLock = ReentrantReadWriteLock()
|
||||
private val storages = THashMap<String, StateStorage>()
|
||||
@@ -62,14 +61,16 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
|
||||
// access under storageLock
|
||||
@Suppress("LeakingThis")
|
||||
private var isUseVfsListener = if (componentManager == null || !isUseVfsForWrite) ThreeState.NO else ThreeState.UNSURE // unsure because depends on stream provider state
|
||||
private var isUseVfsListener = when {
|
||||
componentManager == null || componentManager is Application -> ThreeState.NO
|
||||
else -> ThreeState.UNSURE // unsure because depends on stream provider state
|
||||
}
|
||||
|
||||
open fun getFileBasedStorageConfiguration(fileSpec: String): FileBasedStorageConfiguration = defaultFileBasedStorageConfiguration
|
||||
|
||||
protected open val isUseXmlProlog: Boolean
|
||||
get() = true
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = true
|
||||
|
||||
companion object {
|
||||
private fun createDefaultVirtualTracker(componentManager: ComponentManager?): StorageVirtualFileTracker? {
|
||||
return when (componentManager) {
|
||||
@@ -307,11 +308,8 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
override val isUseXmlProlog: Boolean
|
||||
get() = rootElementName != null && storageManager.isUseXmlProlog && !isSpecialStorage(fileSpec)
|
||||
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = super.isUseVfsForWrite && !isSpecialStorage(fileSpec)
|
||||
|
||||
override val configuration: FileBasedStorageConfiguration
|
||||
get() = storageManager
|
||||
get() = storageManager.getFileBasedStorageConfiguration(fileSpec)
|
||||
|
||||
override fun beforeElementSaved(elements: MutableList<Element>, rootAttributes: MutableMap<String, String>) {
|
||||
if (rootElementName != null) {
|
||||
|
||||
@@ -169,9 +169,9 @@ internal class ComponentStoreModificationTrackerTest {
|
||||
|
||||
private class MyComponentStore(testAppConfigPath: Path) : ChildlessComponentStore() {
|
||||
private class MyStorageManager(private val rootDir: Path) : StateStorageManagerImpl("application") {
|
||||
override val isUseXmlProlog = false
|
||||
override fun getFileBasedStorageConfiguration(fileSpec: String) = appFileBasedStorageConfiguration
|
||||
|
||||
override val isUseVfsForWrite = false
|
||||
override val isUseXmlProlog = false
|
||||
|
||||
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), APP_CONFIG)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user