mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[ruby] run targets: allow to serialize target as a single instance without any lists
GitOrigin-RevId: 6bee0192fffa6b8c02d4709e26a535307d84c60b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a11d79d406
commit
faabe26b8d
@@ -3,6 +3,7 @@ package com.intellij.execution.target
|
||||
|
||||
import com.intellij.configurationStore.ComponentSerializationUtil
|
||||
import com.intellij.execution.target.ContributedConfigurationBase.Companion.getTypeImpl
|
||||
import com.intellij.execution.target.ContributedConfigurationsList.ContributedStateBase.Companion.deserializeState
|
||||
import com.intellij.openapi.components.BaseState
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
@@ -95,12 +96,7 @@ open class ContributedConfigurationsList<C, T>(private val extPoint: ExtensionPo
|
||||
}
|
||||
|
||||
protected open fun fromOneState(state: ContributedStateBase): C? {
|
||||
val type = extPoint.extensionList.firstOrNull { it.id == state.typeId }
|
||||
val defaultConfig = type?.createDefaultConfig()
|
||||
return defaultConfig?.also {
|
||||
it.displayName = state.name ?: ""
|
||||
ComponentSerializationUtil.loadComponentState(it.getSerializer(), state.innerState)
|
||||
}
|
||||
return extPoint.deserializeState(state)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -137,7 +133,17 @@ open class ContributedConfigurationsList<C, T>(private val extPoint: ExtensionPo
|
||||
|
||||
companion object {
|
||||
private fun ContributedConfigurationBase.getSerializer() = getTypeImpl().createSerializer(this)
|
||||
|
||||
fun <T, C> ExtensionPointName<T>.deserializeState(state: ContributedStateBase): C?
|
||||
where C : ContributedConfigurationBase, T : ContributedTypeBase<out C> {
|
||||
|
||||
val type = extensionList.firstOrNull { it.id == state.typeId }
|
||||
val defaultConfig = type?.createDefaultConfig()
|
||||
return defaultConfig?.also {
|
||||
it.displayName = state.name ?: ""
|
||||
ComponentSerializationUtil.loadComponentState(it.getSerializer(), state.innerState)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ package com.intellij.execution.target
|
||||
import com.intellij.configurationStore.ComponentSerializationUtil
|
||||
import com.intellij.configurationStore.jdomSerializer
|
||||
import com.intellij.execution.target.ContributedConfigurationsList.Companion.getSerializer
|
||||
import com.intellij.execution.target.TargetEnvironmentsManager.OneTargetState.Companion.toOneTargetState
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
@@ -57,26 +58,19 @@ fun loadTargetBasedSdkAdditionalData(element: Element): Pair<ContributedConfigur
|
||||
}
|
||||
|
||||
fun saveTargetConfiguration(element: Element, config: TargetEnvironmentConfiguration?) {
|
||||
val targetStateElement = Element(TARGET_ENVIRONMENT_CONFIGURATION)
|
||||
element.addContent(targetStateElement)
|
||||
TargetEnvironmentsManager.TargetsList().also { list ->
|
||||
config?.let { list.addConfig(it) }
|
||||
XmlSerializer.serializeInto(list.state, targetStateElement)
|
||||
val targetStateElement = Element(TARGET_ENVIRONMENT_CONFIGURATION).also {
|
||||
element.addContent(it)
|
||||
}
|
||||
|
||||
config?.toOneTargetState()?.let {
|
||||
jdomSerializer.serializeObjectInto(it, targetStateElement)
|
||||
}
|
||||
}
|
||||
|
||||
fun loadTargetConfiguration(element: Element): TargetEnvironmentConfiguration? {
|
||||
val targetConfigurationElement = element.getChild(TARGET_ENVIRONMENT_CONFIGURATION)
|
||||
if (targetConfigurationElement == null) {
|
||||
LOG.warn("Target configuration data is absent")
|
||||
return null
|
||||
}
|
||||
|
||||
val targetState = jdomSerializer.deserialize(targetConfigurationElement, ContributedConfigurationsList.ListState::class.java)
|
||||
|
||||
return TargetEnvironmentsManager.TargetsList().also {
|
||||
it.loadState(targetState)
|
||||
}.resolvedConfigs().firstOrNull()
|
||||
val targetConfigurationElement = element.getChild(TARGET_ENVIRONMENT_CONFIGURATION) ?: return null
|
||||
val targetState = jdomSerializer.deserialize(targetConfigurationElement, TargetEnvironmentsManager.OneTargetState::class.java)
|
||||
return targetState.toTargetConfiguration()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -76,13 +76,9 @@ class TargetEnvironmentsManager : PersistentStateComponent<TargetEnvironmentsMan
|
||||
) {
|
||||
override fun toBaseState(config: TargetEnvironmentConfiguration): OneTargetState = config.toOneTargetState()
|
||||
|
||||
override fun fromOneState(state: ContributedStateBase): TargetEnvironmentConfiguration? {
|
||||
val result = super.fromOneState(state)
|
||||
if (result != null && state is OneTargetState) {
|
||||
result.uuid = state.uuid ?: UUID.randomUUID().toString()
|
||||
result.runtimes.loadState(state.runtimes)
|
||||
}
|
||||
return result
|
||||
override fun fromOneState(state: ContributedStateBase) = when (state) {
|
||||
is OneTargetState -> state.toTargetConfiguration()
|
||||
else -> super.fromOneState(state) // unexpected, but I do not want to fail just in case
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +98,18 @@ class TargetEnvironmentsManager : PersistentStateComponent<TargetEnvironmentsMan
|
||||
@get: Property(surroundWithTag = false)
|
||||
var runtimes by list<ContributedConfigurationsList.ContributedStateBase>()
|
||||
|
||||
fun toTargetConfiguration(): TargetEnvironmentConfiguration? {
|
||||
return TargetEnvironmentType.EXTENSION_NAME.deserializeState(this)?.also { result ->
|
||||
result.uuid = uuid ?: UUID.randomUUID().toString()
|
||||
result.runtimes.loadState(runtimes)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun TargetEnvironmentConfiguration.toOneTargetState() = OneTargetState().also { result ->
|
||||
result.loadFromConfiguration(this)
|
||||
result.uuid = uuid
|
||||
result.runtimes = runtimes.state.configs
|
||||
fun TargetEnvironmentConfiguration.toOneTargetState() = OneTargetState().also { state ->
|
||||
state.loadFromConfiguration(this)
|
||||
state.uuid = uuid
|
||||
state.runtimes = runtimes.state.configs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user