do not check if only format changed for non-roamable storage and default project
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 2 Sep 2015 11:49:19 +0000 (13:49 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 3 Sep 2015 10:32:42 +0000 (12:32 +0200)
platform/configuration-store-impl/src/ComponentStoreImpl.kt
platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt
platform/configuration-store-impl/src/ProjectStoreImpl.kt
platform/configuration-store-impl/src/XmlElementStorage.kt
platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt

index 5683648a6a4934235eb14a1b900bd7c8041ccde1..e3b7c04a259cf75e3b3396b5a6f0ad8367130173 100644 (file)
@@ -248,7 +248,7 @@ abstract class ComponentStoreImpl : IComponentStore {
       }
 
       val storage = storageManager.getStateStorage(storageSpec)
-      var stateGetter = if (isUseLoadedStateAsExisting(storageSpec) && (ApplicationManager.getApplication().isUnitTestMode() || Registry.`is`("use.loaded.state.as.existing", false))) {
+      var stateGetter = if (isUseLoadedStateAsExisting(storage) && (ApplicationManager.getApplication().isUnitTestMode() || Registry.`is`("use.loaded.state.as.existing", false))) {
         (storage as? StorageBaseEx<*>)?.createGetSession(component, name, stateClass)
       }
       else {
@@ -281,7 +281,7 @@ abstract class ComponentStoreImpl : IComponentStore {
     return name
   }
 
-  protected open fun isUseLoadedStateAsExisting(storageSpec: Storage): Boolean = true
+  protected open fun isUseLoadedStateAsExisting(storage: StateStorage): Boolean = (storage as? XmlElementStorage)?.roamingType != RoamingType.DISABLED
 
   protected open fun getPathMacroManagerForDefaults(): PathMacroManager? = null
 
index a79feef438df03bfa1f554ff87ad1c584a5089e6..f8de1735d43ef7b16ef846cc3304c2665490ab27 100644 (file)
@@ -77,6 +77,8 @@ class DefaultProjectStoreImpl(override val project: ProjectImpl, private val pat
     override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation) = storage
   }
 
+  override fun isUseLoadedStateAsExisting(storage: StateStorage) = false
+
   // don't want to optimize and use already loaded data - it will add unnecessary complexity and implementation-lock (currently we store loaded archived state in memory, but later implementation can be changed)
   fun getStateCopy() = storage.loadLocalData()
   
index f3a5128b3aa655ef3791b50eb054592f9c109796..5ca7c61f9f6ce1306285ad9a9e72678c245bd3fb 100644 (file)
@@ -288,8 +288,6 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM
   }
 
   override fun selectDefaultStorages(storages: Array<Storage>, operation: StateStorageOperation) = selectDefaultStorages(storages, operation, scheme)
-
-  override fun isUseLoadedStateAsExisting(storageSpec: Storage) = storageSpec.file != StoragePathMacros.WORKSPACE_FILE
 }
 
 fun selectDefaultStorages(storages: Array<Storage>, operation: StateStorageOperation, scheme: StorageScheme): Array<Storage> {
index 8d16a69a95855d7a0cc729a0466009537229763f..90f158aed3e68c463e173546fd217b9e682a6342 100644 (file)
@@ -32,7 +32,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
                                                        protected val pathMacroSubstitutor: TrackingPathMacroSubstitutor?,
                                                        roamingType: RoamingType? = RoamingType.DEFAULT,
                                                        provider: StreamProvider? = null) : StorageBaseEx<StateMap>() {
-  protected val roamingType: RoamingType = roamingType ?: RoamingType.DEFAULT
+  val roamingType: RoamingType = roamingType ?: RoamingType.DEFAULT
   private val provider: StreamProvider? = if (provider == null || roamingType == RoamingType.DISABLED || !provider.isApplicable(fileSpec, this.roamingType)) null else provider
 
   protected abstract fun loadLocalData(): Element?
index 2120a265f16249f2967a899d3f70757a7f98743f..ca28916b28f8d86df19afe3b0b3d39593d900e37 100644 (file)
@@ -144,12 +144,12 @@ class ApplicationStoreTest {
     assertThat(file).hasContent("<application>\n  <component name=\"A\" foo=\"1\" bar=\"2\" />\n</application>")
   }
 
-  @Test fun `do not apply to workspace storage - do not save if only format is changed`() {
-    @State(name = "A", storages = arrayOf(Storage(file = StoragePathMacros.WORKSPACE_FILE)))
+  @Test fun `do not check if only format changed for non-roamable storage`() {
+    @State(name = "A", storages = arrayOf(Storage(file = "b.xml", roamingType = RoamingType.DISABLED)))
     class AWorkspace : A()
 
     val oldContent = "<application><component name=\"A\" foo=\"old\" deprecated=\"old\"/></application>"
-    val file = writeConfig("workspace.xml", oldContent)
+    val file = writeConfig("b.xml", oldContent)
     val oldModificationTime = file.getLastModifiedTime()
     testAppConfig.refreshVfs()
 
@@ -206,10 +206,7 @@ class ApplicationStoreTest {
 
     override fun setPath(path: String) {
       storageManager.addMacro(StoragePathMacros.APP_CONFIG, path)
-      storageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, "$path/workspace.xml")
     }
-
-    override fun isUseLoadedStateAsExisting(storageSpec: Storage) = storageSpec.file != StoragePathMacros.WORKSPACE_FILE
   }
 
   abstract class Foo {