IDEA-162371 Duplicate "Editor Colors" entry in export settings
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 3 Nov 2016 16:00:40 +0000 (17:00 +0100)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 3 Nov 2016 16:03:14 +0000 (17:03 +0100)
platform/configuration-store-impl/src/ChooseComponentsToExportDialog.java
platform/configuration-store-impl/src/ExportSettingsAction.kt
platform/configuration-store-impl/src/ImportSettingsAction.kt
platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt
plugins/settings-repository/src/copyAppSettingsToRepository.kt
resources/src/META-INF/IdeaPlugin.xml

index b043d9fcaf356913768e5ac63975b78e74280375..221ee9942929f6e681d06d30eb0ded2590dec6a0 100644 (file)
@@ -67,12 +67,12 @@ public class ChooseComponentsToExportDialog extends DialogWrapper {
     myShowFilePath = showFilePath;
     Map<ExportableItem, ComponentElementProperties> componentToContainingListElement = new LinkedHashMap<>();
     for (List<ExportableItem> 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<ExportableItem, ComponentElementProperties> componentToContainingListElement,
-                                                  @NotNull Map<Path, List<ExportableItem>> fileToComponents) {
+  private static boolean addToExistingListElement(@NotNull ExportableItem item,
+                                                  @NotNull Map<ExportableItem, ComponentElementProperties> itemToContainingListElement,
+                                                  @NotNull Map<Path, List<ExportableItem>> fileToItem) {
+    List<ExportableItem> list = fileToItem.get(item.getFile());
+    if (ContainerUtil.isEmpty(list)) {
+      return false;
+    }
+
     Path file = null;
-    for (Path exportFile : component.getFiles()) {
-      List<ExportableItem> list = fileToComponents.get(exportFile);
-      if (!ContainerUtil.isEmpty(list)) {
-        for (ExportableItem tiedComponent : list) {
-          if (tiedComponent == component) {
-            continue;
-          }
+    for (ExportableItem tiedItem : list) {
+      if (tiedItem == item) {
+        continue;
+      }
 
-          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;
-          }
-        }
+      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<ExportableItem> getExportableComponents() {
     Set<ExportableItem> 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<ExportableItem> myComponents = new HashSet<>();
-
-    private boolean addComponent(ExportableItem component) {
-      return myComponents.add(component);
-    }
+    private final Set<ExportableItem> items = new THashSet<>();
 
     @Override
     @Nullable
@@ -255,7 +251,7 @@ public class ChooseComponentsToExportDialog extends DialogWrapper {
 
     public String toString() {
       Set<String> names = new LinkedHashSet<>();
-      for (ExportableItem component : myComponents) {
+      for (ExportableItem component : items) {
         names.add(component.getPresentableName());
       }
       return StringUtil.join(ArrayUtil.toStringArray(names), ", ");
index 663c05d5ae9f51758dc067910bd11a5ee9a45774..d535df5678a62985176b2f23a873baebfb33e4f7 100644 (file)
@@ -127,7 +127,7 @@ private class MyZipOutputStream(out: OutputStream) : ZipOutputStream(out) {
   }
 }
 
-data class ExportableItem(val files: List<Path>, 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<String>()
@@ -156,15 +156,17 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
                                storageManager: StateStorageManager = ApplicationManager.getApplication().stateStore.stateStorageManager,
                                onlyPaths: Set<String>? = null): Map<Path, List<ExportableItem>> {
   val result = LinkedHashMap<Path, MutableList<ExportableItem>>()
+  @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<Class<*>, 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))
       }
     }
   }
index 0be56e2257b7f3c1297bbbd87e369e0b979f882c..a6e5f323a3d5ae3ffdd6c27bc441f6da26bca250 100644 (file)
@@ -110,10 +110,8 @@ private class ImportSettingsAction : AnAction(), DumbAware {
   private fun getRelativeNamesToExtract(chosenComponents: Set<ExportableItem>): Set<String> {
     val result = THashSet<String>()
     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)
index 5c822c285ae7c6a734922d6a88292bb3bd60efb8..57ec3f6e3519b46437f4e7a50f59c65c4c2286bc 100644 (file)
@@ -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)
index 5b72e0bf273fd28fdd10e61dc9f3180cb81c9648..68d9d31d9d42c073daf9b0ad5597602a775bdaf5 100644 (file)
@@ -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<ExportableItem>): 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
index 3d3c489b84d48369518bcaa3673ac3a7bbbf059b..94a9db8b40b31e6c7a33b35048f11fa88df568d5 100644 (file)
 
     <applicationService serviceInterface="com.intellij.codeInsight.folding.JavaCodeFoldingSettings"
                         serviceImplementation="com.intellij.codeInsight.folding.impl.JavaCodeFoldingSettingsImpl"/>
-    <exportable serviceInterface="com.intellij.codeInsight.folding.JavaCodeFoldingSettings"/>
 
     <projectService serviceInterface="com.intellij.psi.impl.source.tree.injected.JavaConcatenationInjectorManager"
                     serviceImplementation="com.intellij.psi.impl.source.tree.injected.JavaConcatenationInjectorManager"/>