diff --git a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java index fcff2ca565df..634f29e00c6b 100644 --- a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java +++ b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java @@ -16,6 +16,7 @@ package com.intellij.execution; +import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.util.Key; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -27,6 +28,9 @@ import org.jetbrains.annotations.NotNull; public abstract class BeforeRunTask implements Cloneable { @NotNull protected final Key myProviderId; + + // cannot be set to true by default, because RunManager.getHardcodedBeforeRunTasks creates before run task for each provider + // and some providers set enabled to true in the constructor to indicate, that before run task should be added to RC by default (on create) private boolean myIsEnabled; protected BeforeRunTask(@NotNull Key providerId) { @@ -47,7 +51,12 @@ public abstract class BeforeRunTask implements Cloneabl } public void writeExternal(@NotNull Element element) { - element.setAttribute("enabled", String.valueOf(myIsEnabled)); + if (this instanceof PersistentStateComponent) { + ((PersistentStateComponent)this).getState(); + } + else { + element.setAttribute("enabled", String.valueOf(myIsEnabled)); + } } public void readExternal(@NotNull Element element) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index e3a6ebb949d6..277a8538d133 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -16,9 +16,7 @@ package com.intellij.execution.impl import com.intellij.ProjectTopics -import com.intellij.configurationStore.OLD_NAME_CONVERTER -import com.intellij.configurationStore.SchemeManagerIprProvider -import com.intellij.configurationStore.save +import com.intellij.configurationStore.* import com.intellij.execution.* import com.intellij.execution.compound.CompoundRunConfiguration import com.intellij.execution.configurations.* @@ -58,6 +56,7 @@ import kotlin.concurrent.write private val SELECTED_ATTR = "selected" internal val METHOD = "method" private val OPTION = "option" +private val RECENT = "recent_temporary" // open for Upsource (UpsourceRunManager overrides to disable loadState (empty impl)) @State(name = "RunManager", defaultStateAsResource = true, storages = arrayOf(Storage(StoragePathMacros.WORKSPACE_FILE))) @@ -65,7 +64,6 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi companion object { @JvmField val CONFIGURATION = "configuration" - private val RECENT = "recent_temporary" @JvmField val NAME_ATTR = "name" @@ -607,7 +605,15 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi for (task in tasks) { val child = Element(OPTION) child.setAttribute(NAME_ATTR, task.providerId.toString()) - task.writeExternal(child) + if (task is PersistentStateComponent<*>) { + if (!task.isEnabled) { + child.setAttribute("enabled", "false") + } + task.serializeStateInto(child) + } + else { + task.writeExternal(child) + } methodElement.addContent(child) } return methodElement @@ -800,7 +806,14 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi val key = methodElement.getAttributeValue(NAME_ATTR) val provider = stringIdToBeforeRunProvider.getOrPut(key) { UnknownBeforeRunTaskProvider(key) } val beforeRunTask = (if (provider is RunConfigurationBeforeRunProvider) provider.createTask(settings.configuration, this) else provider.createTask(settings.configuration)) ?: continue - beforeRunTask.readExternal(methodElement) + if (beforeRunTask is PersistentStateComponent<*>) { + // for PersistentStateComponent we don't write default value for enabled, so, set it to true explicitly + beforeRunTask.isEnabled = true + beforeRunTask.deserializeAndLoadState(methodElement) + } + else { + beforeRunTask.readExternal(methodElement) + } if (result == null) { result = SmartList() } @@ -996,8 +1009,8 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi private fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List> { var result: MutableList>? = null for (provider in Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, project)) { - val task = provider.createTask(configuration) - if (task != null && task.isEnabled) { + val task = provider.createTask(configuration) ?: continue + if (task.isEnabled) { configuration.factory.configureBeforeRunTaskDefaults(provider.id, task) if (task.isEnabled) { if (result == null) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt index 353718bb4828..1e7ed9860a92 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt @@ -17,7 +17,7 @@ package com.intellij.execution.impl import com.intellij.configurationStore.SerializableScheme import com.intellij.configurationStore.deserializeAndLoadState -import com.intellij.configurationStore.serializeInto +import com.intellij.configurationStore.serializeStateInto import com.intellij.execution.* import com.intellij.execution.configurations.* import com.intellij.execution.runners.ProgramRunner @@ -282,7 +282,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m private fun serializeConfigurationInto(configuration: RunConfiguration, element: Element) { if (configuration is PersistentStateComponent<*>) { - configuration.state!!.serializeInto(element) + configuration.serializeStateInto(element) } else { configuration.writeExternal(element) diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt index 6651be07dec2..2cfc6b6e074e 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/xmlSerializer.kt @@ -119,15 +119,24 @@ fun PersistentStateComponent<*>.deserializeAndLoadState(element: Element) { (this as PersistentStateComponent).loadState(state) } +fun PersistentStateComponent<*>.serializeStateInto(element: Element) { + state?.let { serializeObjectInto(it, element) } +} + +@Deprecated("") fun T.serializeInto(target: Element) { - if (this is Element) { - val iterator = children.iterator() + serializeObjectInto(this, target) +} + +fun serializeObjectInto(o: Any, target: Element) { + if (o is Element) { + val iterator = o.children.iterator() for (child in iterator) { iterator.remove() target.addContent(child) } - val attributeIterator = attributes.iterator() + val attributeIterator = o.attributes.iterator() for (attribute in attributeIterator) { attributeIterator.remove() target.setAttribute(attribute) @@ -135,8 +144,8 @@ fun T.serializeInto(target: Element) { return } - val binding = serializer.getClassBinding(javaClass) - (binding as BeanBinding).serializeInto(this, target, null) + val binding = serializer.getClassBinding(o.javaClass) + (binding as BeanBinding).serializeInto(o, target, getDefaultSerializationFilter()) } private val serializer = object : XmlSerializerImpl.XmlSerializerBase() { diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java index 0710feaa8309..65c9bf372724 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java @@ -455,7 +455,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel for (ModuleExtension extension : myExtensions) { if (extension instanceof PersistentStateComponent) { //noinspection ConstantConditions - XmlSerializer.serializeInto(((PersistentStateComponent)extension).getState(), element); + XmlSerializer.serializeStateInto(((PersistentStateComponent)extension), element); } else { //noinspection deprecation diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt index 078e274f1605..df992a08cd3e 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt @@ -16,7 +16,7 @@ package com.maddyhome.idea.copyright import com.intellij.configurationStore.SerializableScheme -import com.intellij.configurationStore.serializeInto +import com.intellij.configurationStore.serializeObjectInto import com.intellij.openapi.components.BaseState import com.intellij.openapi.options.ExternalizableScheme import com.intellij.util.xmlb.annotations.OptionTag @@ -36,7 +36,7 @@ class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) : // ugly name to preserve compatibility // must be not private because otherwise binding is not created for private accessor @get:OptionTag("myName") - internal var profileName by string() + private var profileName by string() var notice by string(DEFAULT_COPYRIGHT_NOTICE) var keyword by string(EntityUtil.encode("Copyright")) @@ -61,7 +61,7 @@ class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) : override fun writeScheme(): Element { val element = Element("copyright") - serializeInto(element) + serializeObjectInto(this, element) return element } } diff --git a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java index 88f47fbfb8b2..bb6843b1e741 100644 --- a/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java +++ b/plugins/eclipse/src/org/jetbrains/idea/eclipse/conversion/IdeaSpecificSettings.java @@ -261,7 +261,7 @@ public class IdeaSpecificSettings extends AbstractIdeaSpecificSettings() + @get:Attribute() + var url by string() + @get:Attribute() var withDebugger by storedProperty(false) } -internal class LaunchBrowserBeforeRunTask : BeforeRunTask(LaunchBrowserBeforeRunTaskProvider.ID) { - val state = LaunchBrowserBeforeRunTaskState() +internal class LaunchBrowserBeforeRunTask : BeforeRunTask(LaunchBrowserBeforeRunTaskProvider.ID), PersistentStateComponent { + private var state = LaunchBrowserBeforeRunTaskState() + + override fun loadState(state: LaunchBrowserBeforeRunTaskState) { + state.resetModificationCount() + this.state = state + } + + override fun getState() = state } \ No newline at end of file