diff --git a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.java b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.java index b043d9fcaf35..221ee9942929 100644 --- a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.java +++ b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.java @@ -67,12 +67,12 @@ public class ChooseComponentsToExportDialog extends DialogWrapper { myShowFilePath = showFilePath; Map componentToContainingListElement = new LinkedHashMap<>(); for (List list : fileToComponents.values()) { - for (ExportableItem component : list) { - if (!addToExistingListElement(component, componentToContainingListElement, fileToComponents)) { + for (ExportableItem item : list) { + if (!addToExistingListElement(item, componentToContainingListElement, fileToComponents)) { ComponentElementProperties componentElementProperties = new ComponentElementProperties(); - componentElementProperties.addComponent(component); + componentElementProperties.items.add(item); - componentToContainingListElement.put(component, componentElementProperties); + componentToContainingListElement.put(item, componentElementProperties); } } } @@ -81,7 +81,7 @@ public class ChooseComponentsToExportDialog extends DialogWrapper { for (ComponentElementProperties componentElementProperty : new LinkedHashSet<>(componentToContainingListElement.values())) { myChooser.addElement(componentElementProperty, true, componentElementProperty); } - myChooser.sort((o1, o2) -> o1.toString().compareTo(o2.toString())); + myChooser.sort(Comparator.comparing(ComponentElementProperties::toString)); final ActionListener browseAction = new ActionListener() { @Override @@ -136,27 +136,27 @@ public class ChooseComponentsToExportDialog extends DialogWrapper { super.doOKAction(); } - private static boolean addToExistingListElement(@NotNull ExportableItem component, - @NotNull Map componentToContainingListElement, - @NotNull Map> fileToComponents) { - Path file = null; - for (Path exportFile : component.getFiles()) { - List list = fileToComponents.get(exportFile); - if (!ContainerUtil.isEmpty(list)) { - for (ExportableItem tiedComponent : list) { - if (tiedComponent == component) { - continue; - } + private static boolean addToExistingListElement(@NotNull ExportableItem item, + @NotNull Map itemToContainingListElement, + @NotNull Map> fileToItem) { + List list = fileToItem.get(item.getFile()); + if (ContainerUtil.isEmpty(list)) { + return false; + } - final ComponentElementProperties elementProperties = componentToContainingListElement.get(tiedComponent); - if (elementProperties != null && exportFile != file) { - LOG.assertTrue(file == null, "Component " + component + " serialize itself into " + file + " and " + exportFile); - // found - elementProperties.addComponent(component); - componentToContainingListElement.put(component, elementProperties); - file = exportFile; - } - } + Path file = null; + for (ExportableItem tiedItem : list) { + if (tiedItem == item) { + continue; + } + + final ComponentElementProperties elementProperties = itemToContainingListElement.get(tiedItem); + if (elementProperties != null && item.getFile() != file) { + LOG.assertTrue(file == null, "Component " + item + " serialize itself into " + file + " and " + item.getFile()); + // found + elementProperties.items.add(item); + itemToContainingListElement.put(item, elementProperties); + file = item.getFile(); } } return file != null; @@ -229,17 +229,13 @@ public class ChooseComponentsToExportDialog extends DialogWrapper { Set getExportableComponents() { Set components = new THashSet<>(); for (ComponentElementProperties elementProperties : myChooser.getMarkedElements()) { - components.addAll(elementProperties.myComponents); + components.addAll(elementProperties.items); } return components; } private static class ComponentElementProperties implements ElementsChooser.ElementProperties { - private final Set myComponents = new HashSet<>(); - - private boolean addComponent(ExportableItem component) { - return myComponents.add(component); - } + private final Set items = new THashSet<>(); @Override @Nullable @@ -255,7 +251,7 @@ public class ChooseComponentsToExportDialog extends DialogWrapper { public String toString() { Set names = new LinkedHashSet<>(); - for (ExportableItem component : myComponents) { + for (ExportableItem component : items) { names.add(component.getPresentableName()); } return StringUtil.join(ArrayUtil.toStringArray(names), ", "); diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt index 663c05d5ae9f..d535df5678a6 100644 --- a/platform/configuration-store-impl/src/ExportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt @@ -127,7 +127,7 @@ private class MyZipOutputStream(out: OutputStream) : ZipOutputStream(out) { } } -data class ExportableItem(val files: List, val presentableName: String, val roamingType: RoamingType = RoamingType.DEFAULT) +data class ExportableItem(val file: Path, val presentableName: String, val roamingType: RoamingType = RoamingType.DEFAULT) private fun exportInstalledPlugins(zipOut: MyZipOutputStream) { val plugins = ArrayList() @@ -156,15 +156,17 @@ fun getExportableComponentsMap(onlyExisting: Boolean, storageManager: StateStorageManager = ApplicationManager.getApplication().stateStore.stateStorageManager, onlyPaths: Set? = null): Map> { val result = LinkedHashMap>() + @Suppress("DEPRECATION") val processor = { component: ExportableComponent -> - val item = ExportableItem(component.exportFiles.map { it.toPath() }, component.presentableName, RoamingType.DEFAULT) - for (exportFile in item.files) { - result.putValue(exportFile, item) + for (file in component.exportFiles) { + val item = ExportableItem(file.toPath(), component.presentableName, RoamingType.DEFAULT) + result.putValue(item.file, item) } } @Suppress("DEPRECATION") ApplicationManager.getApplication().getComponents(ExportableApplicationComponent::class.java).forEach(processor) + @Suppress("DEPRECATION") ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent::class.java).forEach(processor) val configPath = storageManager.expandMacros(ROOT_CONFIG) @@ -191,6 +193,7 @@ fun getExportableComponentsMap(onlyExisting: Boolean, ServiceManagerImpl.processAllImplementationClasses(ApplicationManager.getApplication() as ApplicationImpl, PairProcessor, PluginDescriptor> { aClass, pluginDescriptor -> val stateAnnotation = StoreUtil.getStateSpec(aClass) + @Suppress("DEPRECATION") if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty() || ExportableComponent::class.java.isAssignableFrom(aClass)) { return@PairProcessor true } @@ -227,10 +230,10 @@ fun getExportableComponentsMap(onlyExisting: Boolean, val presentableName = if (computePresentableNames) getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor) else "" if (isFileIncluded) { - result.putValue(file, ExportableItem(listOf(file), presentableName, storage.roamingType)) + result.putValue(file, ExportableItem(file, presentableName, storage.roamingType)) } if (additionalExportFile != null) { - result.putValue(additionalExportFile, ExportableItem(listOf(additionalExportFile), presentableName, RoamingType.DEFAULT)) + result.putValue(additionalExportFile, ExportableItem(additionalExportFile, "$presentableName (schemes)", RoamingType.DEFAULT)) } } true @@ -241,7 +244,7 @@ fun getExportableComponentsMap(onlyExisting: Boolean, 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(file, it.presentableName ?: "", it.roamingType)) } } } diff --git a/platform/configuration-store-impl/src/ImportSettingsAction.kt b/platform/configuration-store-impl/src/ImportSettingsAction.kt index 0be56e2257b7..a6e5f323a3d5 100644 --- a/platform/configuration-store-impl/src/ImportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ImportSettingsAction.kt @@ -110,10 +110,8 @@ private class ImportSettingsAction : AnAction(), DumbAware { private fun getRelativeNamesToExtract(chosenComponents: Set): Set { val result = THashSet() val root = Paths.get(PathManager.getConfigPath()) - for ((files) in chosenComponents) { - for (exportFile in files) { - result.add(root.relativize(exportFile).systemIndependentPath) - } + for (item in chosenComponents) { + result.add(root.relativize(item.file).systemIndependentPath) } result.add(PluginManager.INSTALLED_TXT) diff --git a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt index 5c822c285ae7..57ec3f6e3519 100644 --- a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt @@ -134,10 +134,10 @@ internal class ApplicationStoreTest { } test(ExportableItem(Paths.get(optionsPath, "filetypes.xml"), "File types", RoamingType.DEFAULT)) - test(ExportableItem(Paths.get(rootConfigPath, "filetypes"), "File types", RoamingType.DEFAULT)) + test(ExportableItem(Paths.get(rootConfigPath, "filetypes"), "File types (schemes)", RoamingType.DEFAULT)) test(ExportableItem(Paths.get(optionsPath, "customization.xml"), "Menus and toolbars customization", RoamingType.DEFAULT)) test(ExportableItem(Paths.get(optionsPath, "templates.xml"), "Live templates", RoamingType.DEFAULT)) - test(ExportableItem(Paths.get(rootConfigPath, "templates"), "Live templates", RoamingType.DEFAULT)) + test(ExportableItem(Paths.get(rootConfigPath, "templates"), "Live templates (schemes)", RoamingType.DEFAULT)) } @Test fun `import settings`() { @@ -175,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(listOf(ExportableItem(componentFile, ""))), additionalFile.to(listOf(ExportableItem(additionalFile, "")))) + assertThat(getExportableComponentsMap(false, false, storageManager, relativePaths)).containsOnly(componentFile.to(listOf(ExportableItem(componentFile, ""))), additionalFile.to(listOf(ExportableItem(additionalFile, " (schemes)")))) } finally { picoContainer.unregisterComponent(componentKey) diff --git a/plugins/settings-repository/src/copyAppSettingsToRepository.kt b/plugins/settings-repository/src/copyAppSettingsToRepository.kt index 5b72e0bf273f..68d9d31d9d42 100644 --- a/plugins/settings-repository/src/copyAppSettingsToRepository.kt +++ b/plugins/settings-repository/src/copyAppSettingsToRepository.kt @@ -31,8 +31,8 @@ import java.nio.file.Path fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager.getApplication()!!.stateStore.stateStorageManager as StateStorageManagerImpl) { val streamProvider = StreamProviderWrapper.getOriginalProvider(storageManager.streamProvider)!! as IcsManager.IcsStreamProvider - val fileToComponents = getExportableComponentsMap(true, false, storageManager) - fileToComponents.keys.forEachGuaranteed { file -> + val fileToItems = getExportableComponentsMap(true, false, storageManager) + fileToItems.keys.forEachGuaranteed { file -> var fileSpec: String try { val absolutePath = file.toAbsolutePath().systemIndependentPath @@ -49,7 +49,7 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager return@forEachGuaranteed } - val roamingType = getRoamingType(fileToComponents.get(file)!!) + val roamingType = fileToItems.get(file)?.firstOrNull()?.roamingType ?: RoamingType.DEFAULT if (file.isFile()) { val fileBytes = file.readBytes() streamProvider.doSave(fileSpec, fileBytes, fileBytes.size, roamingType) @@ -73,22 +73,4 @@ private fun saveDirectory(parent: Path, parentFileSpec: String, roamingType: Roa } } } -} - -private fun getRoamingType(components: Collection): RoamingType { - for (component in components) { - if (component is ExportableItem) { - return component.roamingType - } -// else if (component is PersistentStateComponent<*>) { -// val stateAnnotation = component.javaClass.getAnnotation(State::class.java) -// if (stateAnnotation != null) { -// val storages = stateAnnotation.storages -// if (!storages.isEmpty()) { -// return storages[0].roamingType -// } -// } -// } - } - return RoamingType.DEFAULT } \ No newline at end of file diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 3d3c489b84d4..94a9db8b40b3 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -523,7 +523,6 @@ -