IDEA-141891 Custom keymaps not getting cloned/merged

This commit is contained in:
Vladimir Krivosheev
2016-09-24 19:18:22 +02:00
parent 1096bc126a
commit 87c54aa98b
5 changed files with 36 additions and 34 deletions
@@ -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))
}
}
}
@@ -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 <B> 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)
+12 -18
View File
@@ -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) })
}
@@ -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"
@@ -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<IcsCredentialsStor
override fun canCommit() = repository.repositoryState.canCommit()
fun renameDirectory(pairs: Map<String, String?>): Boolean {
fun renameDirectory(pairs: Map<String, String?>, commitMessage: String): Boolean {
var addCommand: AddCommand? = null
val toDelete = SmartList<DeleteDirectory>()
for ((oldPath, newPath) in pairs) {
@@ -248,7 +248,13 @@ class GitRepositoryManager(private val credentialsStore: Lazy<IcsCredentialsStor
file.delete()
}
else {
Files.move(file, new.resolve(file.fileName))
try {
file.move(new.resolve(file.fileName))
}
catch (ignored: FileAlreadyExistsException) {
return@catchAndLog
}
if (addCommand == null) {
addCommand = AddCommand(repository)
}
@@ -273,7 +279,7 @@ class GitRepositoryManager(private val credentialsStore: Lazy<IcsCredentialsStor
addCommand!!.call()
}
repository.commit(with(IdeaCommitMessageFormatter()) { StringBuilder().appendCommitOwnerInfo(true) }.append("Get rid of \$ROOT_CONFIG$ and \$APP_CONFIG").toString())
repository.commit(with(IdeaCommitMessageFormatter()) { StringBuilder().appendCommitOwnerInfo(true) }.append(commitMessage).toString())
return true
}