From 87c54aa98bea58bd1be39e7e430a24b6e86aa8d6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 24 Sep 2016 19:18:22 +0200 Subject: [PATCH] IDEA-141891 Custom keymaps not getting cloned/merged --- .../src/ExportSettingsAction.kt | 13 ++++---- .../testSrc/ApplicationStoreTest.kt | 11 +++---- plugins/settings-repository/src/IcsManager.kt | 30 ++++++++----------- .../settings-repository/src/IcsUrlBuilder.kt | 2 +- .../src/git/GitRepositoryManager.kt | 14 ++++++--- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt index 25908e561072..663c05d5ae9f 100644 --- a/platform/configuration-store-impl/src/ExportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt @@ -225,11 +225,12 @@ fun getExportableComponentsMap(onlyExisting: Boolean, } } - val files = if (additionalExportFile == null) listOf(file) else if (isFileIncluded) listOf(file, additionalExportFile) else listOf(additionalExportFile) - val item = ExportableItem(files, if (computePresentableNames) getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor) else "", storage.roamingType) - result.putValue(file, item) + val presentableName = if (computePresentableNames) getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor) else "" + if (isFileIncluded) { + result.putValue(file, ExportableItem(listOf(file), presentableName, storage.roamingType)) + } if (additionalExportFile != null) { - result.putValue(additionalExportFile, item) + result.putValue(additionalExportFile, ExportableItem(listOf(additionalExportFile), presentableName, RoamingType.DEFAULT)) } } true @@ -237,10 +238,10 @@ fun getExportableComponentsMap(onlyExisting: Boolean, // must be in the end - because most of SchemeManager clients specify additionalExportFile in the State spec (SchemeManagerFactory.getInstance() as SchemeManagerFactoryBase).process { - if (it.roamingType != RoamingType.DISABLED && it.presentableName != null && it.fileSpec.getOrNull(0) != '$') { + if (it.roamingType != RoamingType.DISABLED && it.fileSpec.getOrNull(0) != '$') { val file = Paths.get(storageManager.expandMacros(ROOT_CONFIG), it.fileSpec) if (!result.containsKey(file) && !isSkipFile(file)) { - result.putValue(file, ExportableItem(listOf(file), it.presentableName, it.roamingType)) + result.putValue(file, ExportableItem(listOf(file), it.presentableName ?: "", it.roamingType)) } } } diff --git a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt index 58aa248da2af..ed47ca66e2de 100644 --- a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt @@ -129,13 +129,15 @@ internal class ApplicationStoreTest { fun test(item: ExportableItem) { val file = item.files.first() - assertThat(map[file]).containsExactly(item) + assertThat(map.get(file)).containsExactly(item) assertThat(file).doesNotExist() } - test(ExportableItem(listOf(Paths.get(optionsPath, "filetypes.xml"), Paths.get(rootConfigPath, "filetypes")), "File types", RoamingType.DEFAULT)) + test(ExportableItem(listOf(Paths.get(optionsPath, "filetypes.xml")), "File types", RoamingType.DEFAULT)) + test(ExportableItem(listOf(Paths.get(rootConfigPath, "filetypes")), "File types", RoamingType.DEFAULT)) test(ExportableItem(listOf(Paths.get(optionsPath, "customization.xml")), "Menus and toolbars customization", RoamingType.DEFAULT)) - test(ExportableItem(listOf(Paths.get(optionsPath, "templates.xml"), Paths.get(rootConfigPath, "templates")), "Live templates", RoamingType.DEFAULT)) + test(ExportableItem(listOf(Paths.get(optionsPath, "templates.xml")), "Live templates", RoamingType.DEFAULT)) + test(ExportableItem(listOf(Paths.get(rootConfigPath, "templates")), "Live templates", RoamingType.DEFAULT)) } @Test fun `import settings`() { @@ -166,7 +168,6 @@ internal class ApplicationStoreTest { val relativePaths = getPaths(ByteArrayInputStream(exportedData.internalBuffer, 0, exportedData.size())) assertThat(relativePaths).containsOnly("a.xml", "foo/", "foo/bar.icls", "IntelliJ IDEA Global Settings") - val list = listOf(ExportableItem(listOf(componentFile, additionalFile), "")) fun Path.to(that: B) = MapEntry.entry(this, that) @@ -174,7 +175,7 @@ internal class ApplicationStoreTest { val componentKey = A::class.java.name picoContainer.registerComponent(InstanceComponentAdapter(componentKey, component)) try { - assertThat(getExportableComponentsMap(false, false, storageManager, relativePaths)).containsOnly(componentFile.to(list), additionalFile.to(list)) + assertThat(getExportableComponentsMap(false, false, storageManager, relativePaths)).containsOnly(componentFile.to(listOf(ExportableItem(listOf(componentFile), ""))), additionalFile.to(listOf(ExportableItem(listOf(additionalFile), "")))) } finally { picoContainer.unregisterComponent(componentKey) diff --git a/plugins/settings-repository/src/IcsManager.kt b/plugins/settings-repository/src/IcsManager.kt index 90d78fa12981..03ddf6ec335a 100644 --- a/plugins/settings-repository/src/IcsManager.kt +++ b/plugins/settings-repository/src/IcsManager.kt @@ -24,6 +24,7 @@ import com.intellij.openapi.application.PathManager import com.intellij.openapi.components.RoamingType import com.intellij.openapi.components.stateStore import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.catchAndLog import com.intellij.openapi.progress.runBackgroundableTask import com.intellij.openapi.project.Project import com.intellij.openapi.project.impl.ProjectLifecycleListener @@ -216,39 +217,32 @@ class IcsApplicationLoadListener : ApplicationLoadListener { icsManager = IcsManager(pluginSystemDir) if (!pluginSystemDir.exists()) { - try { + LOG.catchAndLog { val oldPluginDir = Paths.get(PathManager.getSystemPath(), "settingsRepository") if (oldPluginDir.exists()) { oldPluginDir.move(pluginSystemDir) } } - catch (e: Throwable) { - LOG.error(e) - } } val repositoryManager = icsManager.repositoryManager if (repositoryManager.isRepositoryExists() && repositoryManager is GitRepositoryManager) { + val osFolderName = getOsFolderName() + val migrateSchemes = repositoryManager.renameDirectory(linkedMapOf( Pair("\$ROOT_CONFIG$", null), - Pair("_mac/\$ROOT_CONFIG$", "_mac"), - Pair("_windows/\$ROOT_CONFIG$", "_windows"), - Pair("_linux/\$ROOT_CONFIG$", "_linux"), - Pair("_freebsd/\$ROOT_CONFIG$", "_freebsd"), - Pair("_unix/\$ROOT_CONFIG$", "_unix"), - Pair("_unknown/\$ROOT_CONFIG$", "_unknown"), + Pair("$osFolderName/\$ROOT_CONFIG$", osFolderName), Pair("\$APP_CONFIG$", null), - Pair("_mac/\$APP_CONFIG$", "_mac"), - Pair("_windows/\$APP_CONFIG$", "_windows"), - Pair("_linux/\$APP_CONFIG$", "_linux"), - Pair("_freebsd/\$APP_CONFIG$", "_freebsd"), - Pair("_unix/\$APP_CONFIG$", "_unix"), - Pair("_unknown/\$APP_CONFIG$", "_unknown") - )) + Pair("$osFolderName/\$APP_CONFIG$", osFolderName) + ), "Get rid of \$ROOT_CONFIG$ and \$APP_CONFIG") + + val migrateKeyMaps = repositoryManager.renameDirectory(linkedMapOf( + Pair("$osFolderName/keymaps", "keymaps") + ), "Move keymaps to root") val removeOtherXml = repositoryManager.delete("other.xml") - if (migrateSchemes || removeOtherXml) { + if (migrateSchemes || migrateKeyMaps || removeOtherXml) { // schedule push to avoid merge conflicts application.invokeLater({ icsManager.autoSyncManager.autoSync(force = true) }) } diff --git a/plugins/settings-repository/src/IcsUrlBuilder.kt b/plugins/settings-repository/src/IcsUrlBuilder.kt index 268c126c5807..187c24172bfc 100644 --- a/plugins/settings-repository/src/IcsUrlBuilder.kt +++ b/plugins/settings-repository/src/IcsUrlBuilder.kt @@ -21,7 +21,7 @@ import com.intellij.openapi.util.SystemInfo internal const val PROJECTS_DIR_NAME: String = "_projects/" private val osPrefixes = arrayOf("_mac/", "_windows/", "_linux/", "_freebsd/", "_unix/") -private fun getOsFolderName() = when { +internal fun getOsFolderName() = when { SystemInfo.isMac -> "_mac" SystemInfo.isWindows -> "_windows" SystemInfo.isLinux -> "_linux" diff --git a/plugins/settings-repository/src/git/GitRepositoryManager.kt b/plugins/settings-repository/src/git/GitRepositoryManager.kt index 53eed3ae3742..38cfe1eae5ca 100644 --- a/plugins/settings-repository/src/git/GitRepositoryManager.kt +++ b/plugins/settings-repository/src/git/GitRepositoryManager.kt @@ -38,7 +38,7 @@ import org.eclipse.jgit.transport.* import org.jetbrains.settingsRepository.* import org.jetbrains.settingsRepository.RepositoryManager.Updater import java.io.IOException -import java.nio.file.Files +import java.nio.file.FileAlreadyExistsException import java.nio.file.Path import kotlin.concurrent.write @@ -230,7 +230,7 @@ class GitRepositoryManager(private val credentialsStore: Lazy): Boolean { + fun renameDirectory(pairs: Map, commitMessage: String): Boolean { var addCommand: AddCommand? = null val toDelete = SmartList() for ((oldPath, newPath) in pairs) { @@ -248,7 +248,13 @@ class GitRepositoryManager(private val credentialsStore: Lazy