From dfb0692f2f794b73902a70d68c5a255ddc3eb671 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 6 Feb 2024 15:12:15 +0100 Subject: [PATCH] [platform] merging component storage utils GitOrigin-RevId: 40144952ae1cb624a55f4b7e4e3527f24f323028 --- .../javac/JavacConfigurationMacroFilter.java | 6 +- .../find/impl/FindInProjectSettingsBase.java | 17 ++- .../src/DirectoryBasedStorage.kt | 11 +- .../src/ProjectStoreBridge.kt | 4 +- .../src/SaveSessionProducerBase.kt | 6 +- .../src/StorageVirtualFileTracker.kt | 8 +- .../src/XmlElementStorage.kt | 14 +- .../src/schemeManager/SchemeManagerImpl.kt | 10 +- .../testSrc/DirectoryBasedStorageTest.kt | 6 +- .../template/impl/TemplateSettings.java | 6 +- .../CachingJpsFileContentReader.kt | 8 +- .../configurationStore/JbXmlOutputter.kt | 10 +- .../impl/stores/ComponentStorageUtil.java | 139 ++++++++++++++++++ .../impl/stores/DirectoryStorageUtil.java | 101 ------------- .../impl/stores/FileStorageCoreUtil.java | 107 -------------- .../local/StateStorageBackedByController.kt | 4 +- 16 files changed, 199 insertions(+), 258 deletions(-) create mode 100644 platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/ComponentStorageUtil.java delete mode 100644 platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DirectoryStorageUtil.java delete mode 100644 platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/FileStorageCoreUtil.java diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurationMacroFilter.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurationMacroFilter.java index 39ad7117eff3..798e5fd2bfd5 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurationMacroFilter.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/javac/JavacConfigurationMacroFilter.java @@ -1,8 +1,8 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.compiler.impl.javaCompiler.javac; import com.intellij.openapi.application.PathMacroFilter; -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil; +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil; import com.intellij.util.xmlb.Constants; import org.jdom.Attribute; import org.jdom.Element; @@ -15,7 +15,7 @@ final class JavacConfigurationMacroFilter extends PathMacroFilter { Element parent = attribute.getParent(); if (parent != null && Constants.OPTION.equals(parent.getName()) && "ADDITIONAL_OPTIONS_STRING".equals(parent.getAttributeValue(Constants.NAME))) { Element grandParent = parent.getParentElement(); - return grandParent != null && grandParent.getName().equals(FileStorageCoreUtil.COMPONENT) + return grandParent != null && grandParent.getName().equals(ComponentStorageUtil.COMPONENT) && "JavacSettings".equals(grandParent.getAttributeValue(Constants.NAME)); } } diff --git a/platform/analysis-impl/src/com/intellij/find/impl/FindInProjectSettingsBase.java b/platform/analysis-impl/src/com/intellij/find/impl/FindInProjectSettingsBase.java index d96254509a5b..f3dfef6850ef 100644 --- a/platform/analysis-impl/src/com/intellij/find/impl/FindInProjectSettingsBase.java +++ b/platform/analysis-impl/src/com/intellij/find/impl/FindInProjectSettingsBase.java @@ -1,10 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.find.impl; import com.intellij.openapi.application.PathMacroFilter; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil; +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil; import com.intellij.openapi.util.NlsSafe; +import com.intellij.openapi.util.text.Strings; import com.intellij.util.ArrayUtilRt; import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.XCollection; @@ -106,10 +107,20 @@ public class FindInProjectSettingsBase implements PersistentStateComponent) { // todo reload only changed file, compute diff @@ -44,7 +43,7 @@ open class DirectoryBasedStorage( // on load, `FileStorageCoreUtil` checks both component and name attributes // (critically important for the external store case, where we have only in-project artifacts, but not external) - val state = Element(FileStorageCoreUtil.COMPONENT).setAttribute(FileStorageCoreUtil.NAME, componentName) + val state = Element(ComponentStorageUtil.COMPONENT).setAttribute(ComponentStorageUtil.NAME, componentName) if (splitter is StateSplitterEx) { for (fileName in storageData.keys()) { val subState = storageData.getState(fileName, archive) ?: return null @@ -201,7 +200,7 @@ open class DirectoryBasedStorage( val file = dir.getOrCreateChild(fileName, this) // we don't write xml prolog due to historical reasons (and should not in any case) val macroManager = if (storage.pathMacroSubstitutor == null) null else (storage.pathMacroSubstitutor as TrackingPathMacroSubstitutorImpl).macroManager - val xmlDataWriter = XmlDataWriter(FileStorageCoreUtil.COMPONENT, listOf(element), mapOf(FileStorageCoreUtil.NAME to storage.componentName!!), macroManager, dir.path) + val xmlDataWriter = XmlDataWriter(ComponentStorageUtil.COMPONENT, listOf(element), mapOf(ComponentStorageUtil.NAME to storage.componentName!!), macroManager, dir.path) writeFile(null, this, file, xmlDataWriter, getOrDetectLineSeparator(file) ?: LineSeparator.getSystemLineSeparator(), false) } catch (e: IOException) { @@ -226,7 +225,7 @@ open class DirectoryBasedStorage( val copiedStorageData = copiedStorageData!! for (file in dir.children) { val fileName = file.name - if (fileName.endsWith(FileStorageCoreUtil.DEFAULT_EXT) && !copiedStorageData.containsKey(fileName)) { + if (fileName.endsWith(ComponentStorageUtil.DEFAULT_EXT) && !copiedStorageData.containsKey(fileName)) { if (file.isWritable) { file.delete(this) } diff --git a/platform/configuration-store-impl/src/ProjectStoreBridge.kt b/platform/configuration-store-impl/src/ProjectStoreBridge.kt index a3f543f9aa7c..1c37ce6c88f1 100644 --- a/platform/configuration-store-impl/src/ProjectStoreBridge.kt +++ b/platform/configuration-store-impl/src/ProjectStoreBridge.kt @@ -9,7 +9,7 @@ import com.intellij.ide.impl.isTrusted import com.intellij.openapi.components.* import com.intellij.openapi.components.impl.ModulePathMacroManager import com.intellij.openapi.components.impl.ProjectPathMacroManager -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.components.impl.stores.IProjectStore import com.intellij.openapi.module.ModuleManager @@ -195,7 +195,7 @@ internal class StorageJpsConfigurationReader(private val project: Project, val component = if (storage is DirectoryBasedStorage) { val elementContent = stateMap.getElement(PathUtilRt.getFileName(filePath)) if (elementContent != null) { - Element(FileStorageCoreUtil.COMPONENT).setAttribute(FileStorageCoreUtil.NAME, componentName).addContent(elementContent) + Element(ComponentStorageUtil.COMPONENT).setAttribute(ComponentStorageUtil.NAME, componentName).addContent(elementContent) } else { null diff --git a/platform/configuration-store-impl/src/SaveSessionProducerBase.kt b/platform/configuration-store-impl/src/SaveSessionProducerBase.kt index 3f26f435e3a9..eecd2aaab74c 100644 --- a/platform/configuration-store-impl/src/SaveSessionProducerBase.kt +++ b/platform/configuration-store-impl/src/SaveSessionProducerBase.kt @@ -1,7 +1,7 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.configurationStore -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.util.WriteExternalException import com.intellij.openapi.vfs.LargeFileWriteRequestor import com.intellij.openapi.vfs.SafeWriteRequestor @@ -38,7 +38,7 @@ internal fun serializeState(state: Any): Element? { return when (state) { is Element -> state is com.intellij.openapi.util.JDOMExternalizable -> { - val element = Element(FileStorageCoreUtil.COMPONENT) + val element = Element(ComponentStorageUtil.COMPONENT) state.writeExternal(element) element } diff --git a/platform/configuration-store-impl/src/StorageVirtualFileTracker.kt b/platform/configuration-store-impl/src/StorageVirtualFileTracker.kt index 2778487ade41..9022fb5075d1 100644 --- a/platform/configuration-store-impl/src/StorageVirtualFileTracker.kt +++ b/platform/configuration-store-impl/src/StorageVirtualFileTracker.kt @@ -1,11 +1,11 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. @file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet") package com.intellij.configurationStore import com.intellij.openapi.components.Service import com.intellij.openapi.components.StateStorage -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.components.stateStore import com.intellij.openapi.module.Module @@ -71,7 +71,7 @@ internal class StorageVirtualFileTracker { // So, we don't check if some of the registered storages located inside changed directory. // but if we have DirectoryBasedStorage, we check - if file located inside it - if (storage == null && hasDirectoryBasedStorages && path.endsWith(FileStorageCoreUtil.DEFAULT_EXT, ignoreCase = true)) { + if (storage == null && hasDirectoryBasedStorages && path.endsWith(ComponentStorageUtil.DEFAULT_EXT, ignoreCase = true)) { storage = filePathToStorage.get(VfsUtil.getParentDir(path)) } } @@ -129,4 +129,4 @@ internal class StorageVirtualFileTracker { StoreReloadManager.getInstance(project).storageFilesBatchProcessing(batchStorageEvents) } } -} \ No newline at end of file +} diff --git a/platform/configuration-store-impl/src/XmlElementStorage.kt b/platform/configuration-store-impl/src/XmlElementStorage.kt index bb1c1f9071a6..516a0033c2c0 100644 --- a/platform/configuration-store-impl/src/XmlElementStorage.kt +++ b/platform/configuration-store-impl/src/XmlElementStorage.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.components.PathMacroManager import com.intellij.openapi.components.PathMacroSubstitutor import com.intellij.openapi.components.RoamingType import com.intellij.openapi.components.StateStorage -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.diagnostic.debug import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.SystemInfo @@ -88,7 +88,7 @@ abstract class XmlElementStorage protected constructor(val fileSpec: String, private fun loadState(element: Element): StateMap { beforeElementLoaded(element) - return StateMap.fromMap(FileStorageCoreUtil.load(element, pathMacroSubstitutor)) + return StateMap.fromMap(ComponentStorageUtil.load(element, pathMacroSubstitutor)) } final override fun createSaveSessionProducer(): SaveSessionProducer? { @@ -305,13 +305,13 @@ private fun save(states: StateMap, newLiveStates: Map): Mutable // name attribute should be first val elementAttributes = element.attributes - var nameAttribute = element.getAttribute(FileStorageCoreUtil.NAME) + var nameAttribute = element.getAttribute(ComponentStorageUtil.NAME) if (nameAttribute != null && nameAttribute === elementAttributes[0] && componentName == nameAttribute.value) { // all is OK } else { if (nameAttribute == null) { - nameAttribute = Attribute(FileStorageCoreUtil.NAME, componentName) + nameAttribute = Attribute(ComponentStorageUtil.NAME, componentName) elementAttributes.add(0, nameAttribute) } else { @@ -334,12 +334,12 @@ private fun save(states: StateMap, newLiveStates: Map): Mutable internal fun Element.normalizeRootName(): Element { if (org.jdom.JDOMInterner.isInterned(this)) { - if (name == FileStorageCoreUtil.COMPONENT) { + if (name == ComponentStorageUtil.COMPONENT) { return this } else { val clone = clone() - clone.name = FileStorageCoreUtil.COMPONENT + clone.name = ComponentStorageUtil.COMPONENT return clone } } @@ -348,7 +348,7 @@ internal fun Element.normalizeRootName(): Element { LOG.warn("State element must not have a parent: ${JDOMUtil.writeElement(this)}") detach() } - name = FileStorageCoreUtil.COMPONENT + name = ComponentStorageUtil.COMPONENT return this } } diff --git a/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt b/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt index 2cfaf9bd9b7d..8dd23dedcb11 100644 --- a/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt +++ b/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt @@ -11,7 +11,7 @@ import com.intellij.ide.ui.laf.TempUIThemeLookAndFeelInfo import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.components.RoamingType import com.intellij.openapi.components.SettingsCategory -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.diagnostic.debug import com.intellij.openapi.diagnostic.getOrLogException import com.intellij.openapi.extensions.PluginDescriptor @@ -80,7 +80,7 @@ class SchemeManagerImpl( updateExtension = true } else { - schemeExtension = FileStorageCoreUtil.DEFAULT_EXT + schemeExtension = ComponentStorageUtil.DEFAULT_EXT updateExtension = false } @@ -123,7 +123,7 @@ class SchemeManagerImpl( val fileNameWithoutExtension = schemeNameToFileName(schemeKey) val externalInfo = ExternalInfo(fileNameWithoutExtension = fileNameWithoutExtension, - fileExtension = fileNameWithoutExtension + FileStorageCoreUtil.DEFAULT_EXT) + fileExtension = fileNameWithoutExtension + ComponentStorageUtil.DEFAULT_EXT) externalInfo.schemeKey = schemeKey @@ -246,7 +246,7 @@ class SchemeManagerImpl( internal fun getFileExtension(fileName: CharSequence, isAllowAny: Boolean): String { return when { fileName.endsWith(schemeExtension, ignoreCase = true) -> schemeExtension - fileName.endsWith(FileStorageCoreUtil.DEFAULT_EXT, ignoreCase = true) -> FileStorageCoreUtil.DEFAULT_EXT + fileName.endsWith(ComponentStorageUtil.DEFAULT_EXT, ignoreCase = true) -> ComponentStorageUtil.DEFAULT_EXT isAllowAny -> PathUtilRt.getFileExtension(fileName.toString())!! else -> throw IllegalStateException("Scheme file extension $fileName is unknown, must be filtered out") } @@ -348,7 +348,7 @@ class SchemeManagerImpl( internal fun getFileName(scheme: T) = schemeListManager.getExternalInfo(scheme)?.fileNameWithoutExtension fun canRead(name: CharSequence): Boolean { - return (updateExtension && name.endsWith(FileStorageCoreUtil.DEFAULT_EXT, true) || name.endsWith(schemeExtension, ignoreCase = true)) && + return (updateExtension && name.endsWith(ComponentStorageUtil.DEFAULT_EXT, true) || name.endsWith(schemeExtension, ignoreCase = true)) && (processor !is LazySchemeProcessor || processor.isSchemeFile(name)) } diff --git a/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt b/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt index 76c765849d16..ab5572ae8a9e 100644 --- a/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt +++ b/platform/configuration-store-impl/testSrc/DirectoryBasedStorageTest.kt @@ -1,9 +1,9 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.configurationStore import com.intellij.openapi.application.writeAction import com.intellij.openapi.components.MainConfigurationStateSplitter -import com.intellij.openapi.components.impl.stores.DirectoryStorageUtil +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil import com.intellij.openapi.util.JDOMUtil import com.intellij.testFramework.ProjectRule import com.intellij.testFramework.RuleChain @@ -30,7 +30,7 @@ class DirectoryBasedStorageTest { val dir = tempDirManager.newPath(refreshVfs = true) Files.createDirectories(dir) Files.write(dir.resolve("empty.xml"), ByteArray(0)) - DirectoryStorageUtil.loadFrom(dir, null) + ComponentStorageUtil.load(dir, null) } @Test diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index 0b77013d8534..11a3e40fc871 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInsight.template.impl; import com.intellij.DynamicBundle; @@ -11,7 +11,7 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.SettingsCategory; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; -import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil; +import com.intellij.openapi.components.impl.stores.ComponentStorageUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.PluginId; @@ -593,7 +593,7 @@ public final class TemplateSettings implements PersistentStateComponent