From fbace6910303e18d77ea42a2383e3d2bf269c5ad Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 24 Nov 2015 11:07:43 +0100 Subject: [PATCH] it is ICS responsibility to remove ROOT_CONFIG from file path on copy local config --- .../src/ApplicationStoreImpl.kt | 26 +++++++------------ .../src/ProjectStateStorageManager.kt | 8 +----- .../src/StateStorageManagerImpl.kt | 8 +++--- .../src/copyAppSettingsToRepository.kt | 23 ++++++++-------- 4 files changed, 26 insertions(+), 39 deletions(-) diff --git a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt index 75b8440f2162..32ad477e0da8 100644 --- a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt +++ b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt @@ -74,11 +74,11 @@ class ApplicationStorageManager(private val application: Application, pathMacroM } override fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? { - if (component is NamedJDOMExternalizable) { - return "${component.externalFileName}${FileStorageCoreUtil.DEFAULT_EXT}" + return if (component is NamedJDOMExternalizable) { + "${component.externalFileName}${FileStorageCoreUtil.DEFAULT_EXT}" } else { - return DEFAULT_STORAGE_SPEC + DEFAULT_STORAGE_SPEC } } @@ -103,20 +103,12 @@ class ApplicationStorageManager(private val application: Application, pathMacroM } } - override fun normalizeFileSpec(fileSpec: String): String { - var path = super.normalizeFileSpec(fileSpec) - if (path.startsWithMacro(StoragePathMacros.APP_CONFIG)) { - return path.substring(StoragePathMacros.APP_CONFIG.length + 1) - } - return path - } + override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), StoragePathMacros.APP_CONFIG) - override fun expandMacros(path: String): String { - if (path[0] == '$') { - return super.expandMacros(path) - } - else { - return "${expandMacro(StoragePathMacros.APP_CONFIG)}/$path" - } + override fun expandMacros(path: String) = if (path[0] == '$') { + super.expandMacros(path) + } + else { + "${expandMacro(StoragePathMacros.APP_CONFIG)}/$path" } } \ No newline at end of file diff --git a/platform/configuration-store-impl/src/ProjectStateStorageManager.kt b/platform/configuration-store-impl/src/ProjectStateStorageManager.kt index 32546b750a9d..6a218b91a4fc 100644 --- a/platform/configuration-store-impl/src/ProjectStateStorageManager.kt +++ b/platform/configuration-store-impl/src/ProjectStateStorageManager.kt @@ -27,13 +27,7 @@ class ProjectStateStorageManager(macroSubstitutor: TrackingPathMacroSubstitutor, val VERSION_OPTION = "version" } - override fun normalizeFileSpec(fileSpec: String): String { - var path = super.normalizeFileSpec(fileSpec) - if (path.startsWithMacro(StoragePathMacros.PROJECT_CONFIG_DIR)) { - return path.substring(StoragePathMacros.PROJECT_CONFIG_DIR.length + 1) - } - return path - } + override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), StoragePathMacros.PROJECT_CONFIG_DIR) override fun expandMacros(path: String): String { if (path[0] == '$') { diff --git a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt index 71e7db21ba69..14061df1d61c 100644 --- a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt +++ b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt @@ -384,7 +384,7 @@ open class StateStorageManagerImpl(private val rootTagName: String, } } - override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? { + override final fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? { val oldStorageSpec = getOldStorageSpec(component, componentName, operation) ?: return null @Suppress("DEPRECATION") return getOrCreateStorage(oldStorageSpec, if (component is com.intellij.openapi.util.RoamingTypeDisabled) RoamingType.DISABLED else RoamingType.DEFAULT) @@ -393,7 +393,9 @@ open class StateStorageManagerImpl(private val rootTagName: String, protected open fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? = null } -fun String.startsWithMacro(macro: String): Boolean { +private fun String.startsWithMacro(macro: String): Boolean { val i = macro.length return length > i && this[i] == '/' && startsWith(macro) -} \ No newline at end of file +} + +fun removeMacroIfStartsWith(path: String, macro: String) = if (path.startsWithMacro(macro)) path.substring(macro.length + 1) else path \ No newline at end of file diff --git a/plugins/settings-repository/src/copyAppSettingsToRepository.kt b/plugins/settings-repository/src/copyAppSettingsToRepository.kt index 70764071438e..63f76bdbb25a 100644 --- a/plugins/settings-repository/src/copyAppSettingsToRepository.kt +++ b/plugins/settings-repository/src/copyAppSettingsToRepository.kt @@ -17,6 +17,7 @@ package org.jetbrains.settingsRepository import com.intellij.configurationStore.ROOT_CONFIG import com.intellij.configurationStore.StateStorageManagerImpl +import com.intellij.configurationStore.removeMacroIfStartsWith import com.intellij.ide.actions.ExportableItem import com.intellij.ide.actions.getExportableComponentsMap import com.intellij.openapi.application.ApplicationManager @@ -30,22 +31,21 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager val streamProvider = storageManager.streamProvider!! as IcsManager.IcsStreamProvider val fileToComponents = getExportableComponentsMap(true, false, storageManager) - for (file in fileToComponents.keySet()) { + for (file in fileToComponents.keys) { val absolutePath = FileUtilRt.toSystemIndependentName(file.absolutePath) - var fileSpec = storageManager.collapseMacros(absolutePath) - LOG.assertTrue(!fileSpec.contains(ROOT_CONFIG)) - if (fileSpec.equals(absolutePath)) { + var fileSpec = removeMacroIfStartsWith(storageManager.collapseMacros(absolutePath), ROOT_CONFIG) + if (fileSpec == absolutePath) { // we have not experienced such problem yet, but we are just aware val canonicalPath = FileUtilRt.toSystemIndependentName(file.canonicalPath) - if (!canonicalPath.equals(absolutePath)) { - fileSpec = storageManager.collapseMacros(canonicalPath) + if (canonicalPath != absolutePath) { + fileSpec = removeMacroIfStartsWith(storageManager.collapseMacros(canonicalPath), ROOT_CONFIG) } } val roamingType = getRoamingType(fileToComponents.get(file)!!) if (file.isFile) { val fileBytes = FileUtil.loadFileBytes(file) - streamProvider.doSave(fileSpec, fileBytes, fileBytes.size(), roamingType) + streamProvider.doSave(fileSpec, fileBytes, fileBytes.size, roamingType) } else { saveDirectory(file, fileSpec, roamingType, streamProvider) @@ -54,13 +54,12 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager } private fun saveDirectory(parent: File, parentFileSpec: String, roamingType: RoamingType, streamProvider: IcsManager.IcsStreamProvider) { - val files = parent.listFiles() - if (files != null) { - for (file in files) { - val childFileSpec = parentFileSpec + '/' + file.name + parent.listFiles()?.let { + for (file in it) { + val childFileSpec = "$parentFileSpec/${file.name}" if (file.isFile) { val fileBytes = FileUtil.loadFileBytes(file) - streamProvider.doSave(childFileSpec, fileBytes, fileBytes.size(), roamingType) + streamProvider.doSave(childFileSpec, fileBytes, fileBytes.size, roamingType) } else { saveDirectory(file, childFileSpec, roamingType, streamProvider)