Wizard: do not require to default settings to be present in yaml
This commit is contained in:
+2
@@ -191,6 +191,8 @@ class Context private constructor(
|
|||||||
|
|
||||||
val <V : Any, T : SettingType<V>> SettingReference<V, T>.setting: Setting<V, T>
|
val <V : Any, T : SettingType<V>> SettingReference<V, T>.setting: Setting<V, T>
|
||||||
get() = with(this) { getSetting() }
|
get() = with(this) { getSetting() }
|
||||||
|
|
||||||
|
inline operator fun <T> invoke(reader: ReadingContext.() -> T): T = reader()
|
||||||
}
|
}
|
||||||
|
|
||||||
open inner class WritingContext : ReadingContext() {
|
open inner class WritingContext : ReadingContext() {
|
||||||
|
|||||||
+1
@@ -114,3 +114,4 @@ inline val <V : Any, reified T : SettingType<V>> PluginSettingPropertyReference<
|
|||||||
get() = PluginSettingReference(this, T::class)
|
get() = PluginSettingReference(this, T::class)
|
||||||
|
|
||||||
typealias PluginSettingPropertyReference<V, T> = KProperty1<out Plugin, PluginSetting<V, T>>
|
typealias PluginSettingPropertyReference<V, T> = KProperty1<out Plugin, PluginSetting<V, T>>
|
||||||
|
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.tools.projectWizard.core.entity.settings
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||||
|
|
||||||
|
fun ParsingContext.parseSettingsMap(
|
||||||
|
path: String,
|
||||||
|
values: Map<String, Any?>,
|
||||||
|
settingReferences: List<Pair<SettingReference<*, *>, Setting<*, *>>>
|
||||||
|
): TaskResult<List<Pair<SettingReference<*, *>, Any>>> = settingReferences.mapComputeM { (settingReference, setting) ->
|
||||||
|
val settingValue = values[setting.path]
|
||||||
|
when {
|
||||||
|
settingValue != null -> {
|
||||||
|
setting.type.parse(this, settingValue, setting.path).map { listOf(settingReference to it) }
|
||||||
|
}
|
||||||
|
setting.isRequired -> {
|
||||||
|
fail(ParseError("No value was found for a key `$path.${setting.path}`"))
|
||||||
|
}
|
||||||
|
else -> success(emptyList())
|
||||||
|
}
|
||||||
|
}.sequence().map { it.flatten() }
|
||||||
+8
-5
@@ -261,11 +261,14 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
|||||||
} or mapParser { map, path ->
|
} or mapParser { map, path ->
|
||||||
val (id) = map.parseValue<String>(path, "name")
|
val (id) = map.parseValue<String>(path, "name")
|
||||||
val (configurator) = BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
val (configurator) = BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
||||||
val (settingsWithValues) = configurator.settings.mapComputeM { setting ->
|
val (settingsWithValues) = parseSettingsMap(
|
||||||
val (settingValue) = map[setting.path].toResult { ParseError("No value was found for a key `$path.${setting.path}`") }
|
path,
|
||||||
val reference = withSettingsOf(moduleIdentificator, configurator) { setting.reference }
|
map,
|
||||||
setting.type.parse(this, settingValue, setting.path).map { reference to it }
|
configurator.settings.map { setting ->
|
||||||
}.sequence()
|
val reference = withSettingsOf(moduleIdentificator, configurator) { setting.reference }
|
||||||
|
reference to setting
|
||||||
|
}
|
||||||
|
)
|
||||||
updateState { it.withSettings(settingsWithValues) }
|
updateState { it.withSettings(settingsWithValues) }
|
||||||
configurator
|
configurator
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -233,14 +233,17 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor {
|
|||||||
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>>
|
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun parser(sourcesetIdentificator: Identificator): Parser<Template> = mapParser { map, path ->
|
fun parser(templateId: Identificator): Parser<Template> = mapParser { map, path ->
|
||||||
val (id) = map.parseValue<String>(path, "id")
|
val (id) = map.parseValue<String>(path, "id")
|
||||||
val (template) = state.idToTemplate[id].toResult { TemplateNotFoundError(id) }
|
val (template) = state.idToTemplate[id].toResult { TemplateNotFoundError(id) }
|
||||||
val (settingsWithValues) = template.settings.mapComputeM { setting ->
|
val (settingsWithValues) = parseSettingsMap(
|
||||||
val (settingValue) = map[setting.path].toResult { ParseError("No value was found for a key `$path.${setting.path}`") }
|
path,
|
||||||
val reference = withSettingsOf(sourcesetIdentificator, template) { setting.reference }
|
map,
|
||||||
setting.type.parse(this, settingValue, setting.path).map { reference to it }
|
template.settings.map { setting ->
|
||||||
}.sequence()
|
val reference = withSettingsOf(templateId, template) { setting.reference }
|
||||||
|
reference to setting
|
||||||
|
}
|
||||||
|
)
|
||||||
updateState { it.withSettings(settingsWithValues) }
|
updateState { it.withSettings(settingsWithValues) }
|
||||||
template
|
template
|
||||||
} or valueParserM { value, path ->
|
} or valueParserM { value, path ->
|
||||||
|
|||||||
Reference in New Issue
Block a user