[configuration store] fix updating component state from stream provider if it was removed

In the previous version, if 'updatedFromStreamProvider' is firstly called when the element cannot be loaded (e.g., because its file is empty, such a situation reproduced in RemoteDevConfigShareTest, see CWM-8547), it stored 'null' in 'storageDataRef', and then 'updatedFromStreamProvider' is called again and now the element is loaded, it did nothing, so configuration of the component wasn't updated.

GitOrigin-RevId: 65636a3e984a9416c1a9e532328aac5f3cc9d0c2
This commit is contained in:
Nikolay Chashnikov
2023-11-28 12:33:42 +00:00
committed by intellij-monorepo-bot
parent a6272ebc54
commit 0b555e8b56
2 changed files with 30 additions and 1 deletions
@@ -208,7 +208,7 @@ abstract class XmlElementStorage protected constructor(val fileSpec: String,
// if data was loaded, mark as changed all loaded components
if (states != null) {
changedComponentNames.addAll(states.keys())
setStates(oldStorageData = states, newStorageData = null)
setStates(oldStorageData = states, newStorageData = StateMap.EMPTY)
}
}
else if (states != null) {
@@ -12,6 +12,7 @@ import com.intellij.serviceContainer.ComponentManagerImpl
import com.intellij.testFramework.*
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.testFramework.rules.InMemoryFsRule
import com.intellij.util.io.delete
import com.intellij.util.io.write
import com.intellij.util.xmlb.XmlSerializerUtil
import com.intellij.util.xmlb.annotations.Attribute
@@ -512,6 +513,34 @@ internal class ApplicationStoreTest {
assertTrue("New old.xml without os prefix not found", testAppConfig.resolve("old.xml").exists())
}
@Test
fun `reload components`() {
@State(name = "A", storages = [Storage(value = "a.xml")])
class Comp : FooComponent()
val component = Comp()
componentStore.initComponent(component, null, null)
writeConfig("a.xml", "")
componentStore.reloadComponents(changedFileSpecs = listOf("a.xml"), deletedFileSpecs = emptyList())
assertEquals("defaultValue", component.foo)
writeConfig("a.xml", createComponentFileContent("initial"))
componentStore.reloadComponents(changedFileSpecs = listOf("a.xml"), deletedFileSpecs = emptyList())
assertEquals("initial", component.foo)
writeConfig("a.xml", createComponentFileContent("changed"))
componentStore.reloadComponents(changedFileSpecs = listOf("a.xml"), deletedFileSpecs = emptyList())
assertEquals("changed", component.foo)
testAppConfig.resolve("a.xml").delete()
componentStore.reloadComponents(changedFileSpecs = emptyList(), deletedFileSpecs = listOf("a.xml"))
assertEquals("defaultValue", component.foo)
}
private fun createComponentFileContent(fooValue: String, componentName: String = "A") =
"""<application>${createComponentData(fooValue, componentName)}</application>"""
@State(name = "A", storages = [Storage(value = "per-os.xml", roamingType = RoamingType.PER_OS)])
private class PerOsComponent : FooComponent()