Wizard: specify path for plugin entities in one place

This commit is contained in:
Ilya Kirillov
2020-07-22 16:10:39 +03:00
committed by Kirill Shmakov
parent c05c72387e
commit 3c3ba361e8
22 changed files with 248 additions and 317 deletions
@@ -10,7 +10,6 @@ import kotlin.properties.ReadOnlyProperty
interface SettingsOwner {
fun <V : Any, T : SettingType<V>> settingDelegate(
prefix: String,
create: (path: String) -> SettingBuilder<V, T>
): ReadOnlyProperty<Any, Setting<V, T>>
@@ -22,27 +21,24 @@ interface SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String = "",
init: DropDownSettingType.Builder<V>.() -> Unit = {}
): ReadOnlyProperty<Any, Setting<V, DropDownSettingType<V>>> = settingDelegate(prefix) { path ->
): ReadOnlyProperty<Any, Setting<V, DropDownSettingType<V>>> = settingDelegate { path ->
DropDownSettingType.Builder(path, title, neededAtPhase, parser).apply(init)
}
fun stringSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
init: StringSettingType.Builder.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
StringSettingType.Builder(path, title, neededAtPhase).apply(init)
}
fun booleanSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
init: BooleanSettingType.Builder.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
BooleanSettingType.Builder(path, title, neededAtPhase).apply(init)
}
@@ -50,18 +46,16 @@ interface SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String = "",
init: ValueSettingType.Builder<V>.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
ValueSettingType.Builder(path, title, neededAtPhase, parser).apply(init)
}
fun versionSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
init: VersionSettingType.Builder.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
VersionSettingType.Builder(path, title, neededAtPhase).apply(init)
}
@@ -69,18 +63,16 @@ interface SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String = "",
init: ListSettingType.Builder<V>.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
ListSettingType.Builder(path, title, neededAtPhase, parser).apply(init)
}
fun pathSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
init: PathSettingType.Builder.() -> Unit = {}
) = settingDelegate(prefix) { path ->
) = settingDelegate { path ->
PathSettingType.Builder(path, title, neededAtPhase).apply(init)
}
}
@@ -89,10 +81,8 @@ interface SettingsOwner {
inline fun <reified E> SettingsOwner.enumSettingImpl(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser(), prefix) {
) where E : Enum<E>, E : DisplayableSettingItem = dropDownSetting<E>(title, neededAtPhase, enumParser()) {
values = enumValues<E>().asList()
//
init()
}
@@ -26,146 +26,130 @@ abstract class Plugin(override val context: Context) : EntityBase(),
abstract val properties: List<Property<*>>
abstract val settings: List<PluginSetting<*, *>>
abstract val pipelineTasks: List<PipelineTask>
companion object : SettingsOwner {
fun pipelineTask(
prefix: String,
phase: GenerationPhase,
init: PipelineTask.Builder.() -> Unit
): ReadOnlyProperty<Any, PipelineTask> =
cached { name -> PipelineTask.Builder(withPrefix(prefix, name), phase).apply(init).build() }
fun <A, B : Any> task1(
prefix: String,
init: Task1.Builder<A, B>.() -> Unit
): ReadOnlyProperty<Any, Task1<A, B>> = cached { name -> Task1.Builder<A, B>(withPrefix(prefix, name)).apply(init).build() }
fun <T : Any> property(
prefix: String,
defaultValue: T,
init: Property.Builder<T>.() -> Unit = {}
): ReadOnlyProperty<Any, Property<T>> =
cached { name -> Property.Builder(withPrefix(prefix, name), defaultValue).apply(init).build() }
fun <T : Any> listProperty(prefix: String, vararg defaultValues: T, init: Property.Builder<List<T>>.() -> Unit = {}) =
property(prefix, defaultValues.toList(), init)
private fun withPrefix(name: String, prefix: String): String = if (prefix.isNotEmpty()) "$prefix.$name" else name
override fun <V : Any, T : SettingType<V>> settingDelegate(
prefix: String,
create: (path: String) -> SettingBuilder<V, T>
): ReadOnlyProperty<Any, PluginSetting<V, T>> = cached { name -> PluginSetting(create(withPrefix(name, prefix)).buildInternal()) }
// setting types
@Suppress("UNCHECKED_CAST")
override fun <V : DisplayableSettingItem> dropDownSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: DropDownSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<V, DropDownSettingType<V>>> =
super.dropDownSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<V, DropDownSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun stringSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: StringSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<String, StringSettingType>> =
super.stringSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<String, StringSettingType>>
@Suppress("UNCHECKED_CAST")
override fun booleanSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: BooleanSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Boolean, BooleanSettingType>> =
super.booleanSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<Boolean, BooleanSettingType>>
@Suppress("UNCHECKED_CAST")
override fun <V : Any> valueSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ValueSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<V, ValueSettingType<V>>> =
super.valueSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<V, ValueSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun versionSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: VersionSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Version, VersionSettingType>> =
super.versionSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<Version, VersionSettingType>>
@Suppress("UNCHECKED_CAST")
override fun <V : Any> listSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ListSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<List<V>, ListSettingType<V>>> =
super.listSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, PluginSetting<List<V>, ListSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun pathSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: PathSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>> =
super.pathSetting(title, neededAtPhase, prefix, init) as ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>>
@Suppress("UNCHECKED_CAST")
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
): ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, prefix, init) as ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>>
}
}
abstract class PluginSettingsOwner : SettingsOwner {
abstract val pluginPath: String
fun pipelineTask(
phase: GenerationPhase,
init: PipelineTask.Builder.() -> Unit
): ReadOnlyProperty<Any, PipelineTask> =
cached { name -> PipelineTask.Builder(withPluginPath(name), phase).apply(init).build() }
fun <A, B : Any> task1(
init: Task1.Builder<A, B>.() -> Unit
): ReadOnlyProperty<Any, Task1<A, B>> = cached { name -> Task1.Builder<A, B>(withPluginPath(name)).apply(init).build() }
fun <T : Any> property(
defaultValue: T,
init: Property.Builder<T>.() -> Unit = {}
): ReadOnlyProperty<Any, Property<T>> =
cached { name -> Property.Builder(withPluginPath(name), defaultValue).apply(init).build() }
fun <T : Any> listProperty(vararg defaultValues: T, init: Property.Builder<List<T>>.() -> Unit = {}) =
property(defaultValues.toList(), init)
private fun withPluginPath(name: String): String = "$pluginPath.$name"
override fun <V : Any, T : SettingType<V>> settingDelegate(
create: (path: String) -> SettingBuilder<V, T>
): ReadOnlyProperty<Any, PluginSetting<V, T>> = cached { name -> PluginSetting(create(withPluginPath(name)).buildInternal()) }
// setting types
@Suppress("UNCHECKED_CAST")
override fun <V : DisplayableSettingItem> dropDownSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
init: DropDownSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<V, DropDownSettingType<V>>> =
super.dropDownSetting(
title,
neededAtPhase,
parser,
init
) as ReadOnlyProperty<Any, PluginSetting<V, DropDownSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun stringSetting(
title: String,
neededAtPhase: GenerationPhase,
init: StringSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<String, StringSettingType>> =
super.stringSetting(
title,
neededAtPhase,
init
) as ReadOnlyProperty<Any, PluginSetting<String, StringSettingType>>
@Suppress("UNCHECKED_CAST")
override fun booleanSetting(
title: String,
neededAtPhase: GenerationPhase,
init: BooleanSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Boolean, BooleanSettingType>> =
super.booleanSetting(
title,
neededAtPhase,
init
) as ReadOnlyProperty<Any, PluginSetting<Boolean, BooleanSettingType>>
@Suppress("UNCHECKED_CAST")
override fun <V : Any> valueSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
init: ValueSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<V, ValueSettingType<V>>> =
super.valueSetting(
title,
neededAtPhase,
parser,
init
) as ReadOnlyProperty<Any, PluginSetting<V, ValueSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun versionSetting(
title: String,
neededAtPhase: GenerationPhase,
init: VersionSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Version, VersionSettingType>> =
super.versionSetting(
title,
neededAtPhase,
init
) as ReadOnlyProperty<Any, PluginSetting<Version, VersionSettingType>>
@Suppress("UNCHECKED_CAST")
override fun <V : Any> listSetting(
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
init: ListSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<List<V>, ListSettingType<V>>> =
super.listSetting(
title,
neededAtPhase,
parser,
init
) as ReadOnlyProperty<Any, PluginSetting<List<V>, ListSettingType<V>>>
@Suppress("UNCHECKED_CAST")
override fun pathSetting(
title: String,
neededAtPhase: GenerationPhase,
init: PathSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>> =
super.pathSetting(title, neededAtPhase, init) as ReadOnlyProperty<Any, PluginSetting<Path, PathSettingType>>
@Suppress("UNCHECKED_CAST")
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
): ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, PluginSetting<E, DropDownSettingType<E>>>
}
@@ -62,7 +62,6 @@ fun <V : Any, T : SettingType<V>> Reader.settingValue(module: Module, setting: M
abstract class ModuleConfiguratorSettings : SettingsOwner {
final override fun <V : Any, T : SettingType<V>> settingDelegate(
prefix: String,
create: (path: String) -> SettingBuilder<V, T>
): ReadOnlyProperty<Any?, ModuleConfiguratorSetting<V, T>> = cached { name ->
ModuleConfiguratorSetting(create(name).buildInternal())
@@ -73,14 +72,12 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: DropDownSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<V, DropDownSettingType<V>>> =
super.dropDownSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<V, DropDownSettingType<V>>>
@@ -88,13 +85,11 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
final override fun stringSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: StringSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<String, StringSettingType>> =
super.stringSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<String, StringSettingType>>
@@ -102,13 +97,11 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
final override fun booleanSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: BooleanSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<Boolean, BooleanSettingType>> =
super.booleanSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<Boolean, BooleanSettingType>>
@@ -117,14 +110,12 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ValueSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<V, ValueSettingType<V>>> =
super.valueSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<V, ValueSettingType<V>>>
@@ -132,13 +123,11 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
final override fun versionSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: VersionSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<Version, VersionSettingType>> =
super.versionSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<Version, VersionSettingType>>
@@ -147,14 +136,12 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ListSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<List<V>, ListSettingType<V>>> =
super.listSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<List<V>, ListSettingType<V>>>
@@ -162,13 +149,11 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
final override fun pathSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: PathSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<Path, PathSettingType>> =
super.pathSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<Path, PathSettingType>>
@@ -176,10 +161,9 @@ abstract class ModuleConfiguratorSettings : SettingsOwner {
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
): ReadOnlyProperty<Any, ModuleConfiguratorSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, prefix, init) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<E, DropDownSettingType<E>>>
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, ModuleConfiguratorSetting<E, DropDownSettingType<E>>>
}
interface ModuleConfiguratorWithSettings : ModuleConfigurator {
@@ -6,10 +6,7 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins
import org.jetbrains.kotlin.tools.projectWizard.KotlinNewProjectWizardBundle
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.Plugin
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.core.checker
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.core.entity.Property
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.PluginSetting
@@ -22,7 +19,7 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.withAllSubModules
class AndroidPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
override val settings: List<PluginSetting<*, *>> = listOf(
androidSdkPath
@@ -32,13 +29,12 @@ class AndroidPlugin(context: Context) : Plugin(context) {
)
override val properties: List<Property<*>> = listOf()
companion object {
private const val PATH = "android"
companion object : PluginSettingsOwner() {
override val pluginPath: String = "android"
val androidSdkPath by pathSetting(
KotlinNewProjectWizardBundle.message("plugin.android.setting.sdk"),
neededAtPhase = GenerationPhase.PROJECT_GENERATION,
PATH
) {
isSavable = true
isAvailable = isAndroidContainingProject
@@ -51,7 +47,7 @@ class AndroidPlugin(context: Context) : Plugin(context) {
.any { it.configurator is AndroidModuleConfigurator }
}
val addAndroidSdkToLocalProperties by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val addAndroidSdkToLocalProperties by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(GradlePlugin.createLocalPropertiesFile)
runAfter(KotlinPlugin.createModules)
isAvailable = isAndroidContainingProject
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins
import org.jetbrains.kotlin.tools.projectWizard.WizardRunConfiguration
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.Plugin
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.core.entity.Property
@@ -17,18 +18,18 @@ import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemPlugin
class RunConfigurationsPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
override val settings: List<PluginSetting<*, *>> = emptyList()
override val pipelineTasks: List<PipelineTask> = listOf(createRunConfigurationsTask)
override val properties: List<Property<*>> = listOf(configurations)
companion object {
private const val PATH = "runConfigurations"
companion object: PluginSettingsOwner() {
override val pluginPath = "runConfigurations"
val configurations by listProperty<WizardRunConfiguration>(PATH)
val configurations by listProperty<WizardRunConfiguration>()
val createRunConfigurationsTask by pipelineTask(PATH, GenerationPhase.PROJECT_IMPORT) {
val createRunConfigurationsTask by pipelineTask( GenerationPhase.PROJECT_IMPORT) {
runBefore(BuildSystemPlugin.importProject)
withAction {
@@ -8,7 +8,6 @@ import org.jetbrains.kotlin.tools.projectWizard.core.entity.Property
import org.jetbrains.kotlin.tools.projectWizard.core.entity.StringValidators
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.PluginSetting
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.PomIR
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
@@ -18,10 +17,10 @@ import java.nio.file.Files
import java.nio.file.Paths
class StructurePlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "structure"
companion object : PluginSettingsOwner() {
override val pluginPath = "structure"
private val ALLOWED_SPECIAL_CHARS_IN_GROUP_ID = Module.ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES + '.'
private val ALLOWED_SPECIAL_CHARS_IN_ARTIFACT_ID = Module.ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES
@@ -30,7 +29,6 @@ class StructurePlugin(context: Context) : Plugin(context) {
val projectPath by pathSetting(
KotlinNewProjectWizardBundle.message("plugin.structure.setting.location"),
GenerationPhase.FIRST_STEP,
PATH
) {
defaultValue = value(Paths.get("."))
@@ -46,7 +44,6 @@ class StructurePlugin(context: Context) : Plugin(context) {
val name by stringSetting(
KotlinNewProjectWizardBundle.message("plugin.structure.setting.name"),
GenerationPhase.FIRST_STEP,
PATH
) {
shouldNotBeBlank()
validate(StringValidators.shouldBeValidIdentifier(title, Module.ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES))
@@ -55,7 +52,6 @@ class StructurePlugin(context: Context) : Plugin(context) {
val groupId by stringSetting(
KotlinNewProjectWizardBundle.message("plugin.structure.setting.group.id"),
GenerationPhase.FIRST_STEP,
PATH
) {
isSavable = true
shouldNotBeBlank()
@@ -64,7 +60,6 @@ class StructurePlugin(context: Context) : Plugin(context) {
val artifactId by stringSetting(
KotlinNewProjectWizardBundle.message("plugin.structure.setting.artifact.id"),
GenerationPhase.FIRST_STEP,
PATH
) {
shouldNotBeBlank()
validate(StringValidators.shouldBeValidIdentifier(title, ALLOWED_SPECIAL_CHARS_IN_ARTIFACT_ID))
@@ -72,13 +67,12 @@ class StructurePlugin(context: Context) : Plugin(context) {
val version by stringSetting(
KotlinNewProjectWizardBundle.message("plugin.structure.setting.version"),
GenerationPhase.FIRST_STEP,
PATH
) {
shouldNotBeBlank()
validate(StringValidators.shouldBeValidIdentifier(title, ALLOWED_SPECIAL_CHARS_IN_VERSION))
defaultValue = value("1.0-SNAPSHOT")
}
val createProjectDir by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createProjectDir by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
withAction {
service<FileSystemWizardService>().createDirectory(StructurePlugin.projectPath.settingValue)
}
@@ -27,15 +27,14 @@ import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Repository
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.updateBuildFiles
abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem"
val type by enumSetting<BuildSystemType>(
KotlinNewProjectWizardBundle.message("plugin.buildsystem.setting.type"),
GenerationPhase.FIRST_STEP,
PATH
) {
isSavable = true
filter = { _, type ->
@@ -60,13 +59,13 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
}
}
val buildSystemData by property<List<BuildSystemData>>(PATH, emptyList())
val buildSystemData by property<List<BuildSystemData>>(emptyList())
val buildFiles by listProperty<BuildFileIR>(PATH)
val buildFiles by listProperty<BuildFileIR>()
val pluginRepositoreis by listProperty<Repository>(PATH)
val pluginRepositoreis by listProperty<Repository>()
val takeRepositoriesFromDependencies by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val takeRepositoriesFromDependencies by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(createModules)
runAfter(TemplatesPlugin.postApplyTemplatesToModules)
@@ -88,7 +87,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
}
}
val createModules by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(StructurePlugin.createProjectDir)
withAction {
val fileSystem = service<FileSystemWizardService>()
@@ -103,7 +102,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
}
}
val importProject by pipelineTask(PATH, GenerationPhase.PROJECT_IMPORT) {
val importProject by pipelineTask(GenerationPhase.PROJECT_IMPORT) {
runAfter(createModules)
withAction {
val data = buildSystemData.propertyValue.first { it.type == buildSystemType }
@@ -111,13 +110,6 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
.importProject(this, StructurePlugin.projectPath.settingValue, allIRModules, buildSystemType)
}
}
fun addBuildSystemData(prefix: String, data: BuildSystemData) = pipelineTask(prefix, GenerationPhase.PREPARE) {
runBefore(createModules)
withAction {
buildSystemData.addValues(data)
}
}
}
override val settings: List<PluginSetting<*, *>> = listOf(
@@ -135,6 +127,13 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
)
}
fun PluginSettingsOwner.addBuildSystemData(data: BuildSystemData) = pipelineTask(GenerationPhase.PREPARE) {
runBefore(BuildSystemPlugin.createModules)
withAction {
BuildSystemPlugin.buildSystemData.addValues(data)
}
}
data class BuildSystemData(
val type: BuildSystemType,
val buildFileData: BuildFileData?
@@ -1,15 +1,15 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
class JpsPlugin(context: Context) : BuildSystemPlugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem.jps"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem.jps"
val addBuildSystemData by addBuildSystemData(
PATH,
BuildSystemData(
type = BuildSystemType.Jps,
buildFileData = null
@@ -1,6 +1,7 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.asSuccess
import org.jetbrains.kotlin.tools.projectWizard.core.checker
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
@@ -14,16 +15,16 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.MavenPrinter
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.updateBuildFiles
class MavenPlugin(context: Context) : BuildSystemPlugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem.maven"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem.maven"
private val isMaven = checker {
type.settingValue == BuildSystemType.Maven
}
val createSettingsFileTask by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createSettingsFileTask by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
runBefore(createModules)
isAvailable = isMaven
@@ -45,7 +46,7 @@ class MavenPlugin(context: Context) : BuildSystemPlugin(context) {
}
}
val addBuildSystemPluginRepositories by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val addBuildSystemPluginRepositories by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createPluginRepositories)
runBefore(createModules)
isAvailable = isMaven
@@ -59,7 +60,6 @@ class MavenPlugin(context: Context) : BuildSystemPlugin(context) {
}
val addBuildSystemData by addBuildSystemData(
PATH,
BuildSystemData(
type = BuildSystemType.Maven,
buildFileData = BuildFileData(
@@ -21,25 +21,24 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.printBuildFile
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectPath
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.DefaultRepository
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
import org.jetbrains.kotlin.tools.projectWizard.templates.FileTemplate
import org.jetbrains.kotlin.tools.projectWizard.templates.FileTemplateDescriptor
abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem.gradle"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem.gradle"
val gradleProperties by listProperty(
PATH,
"kotlin.code.style" to "official"
)
val settingsGradleFileIRs by listProperty<BuildSystemIR>(PATH)
val settingsGradleFileIRs by listProperty<BuildSystemIR>()
val createGradlePropertiesFile by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createGradlePropertiesFile by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
runBefore(TemplatesPlugin.renderFileTemplates)
isAvailable = isGradle
@@ -61,9 +60,9 @@ abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
}
}
val localProperties by listProperty<Pair<String, String>>(PATH)
val localProperties by listProperty<Pair<String, String>>()
val createLocalPropertiesFile by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createLocalPropertiesFile by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
runBefore(TemplatesPlugin.renderFileTemplates)
isAvailable = isGradle
@@ -85,7 +84,7 @@ abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
private val isGradle = checker { buildSystemType.isGradle }
val initGradleWrapperTask by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val initGradleWrapperTask by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(TemplatesPlugin.renderFileTemplates)
isAvailable = isGradle
withAction {
@@ -105,7 +104,7 @@ abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
}
val createSettingsFileTask by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createSettingsFileTask by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
runAfter(KotlinPlugin.createPluginRepositories)
isAvailable = isGradle
@@ -1,20 +1,21 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildFileData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.addBuildSystemData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.GradlePrinter
class GroovyDslPlugin(context: Context) : GradlePlugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem.gradle.groovyDsl"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem.gradle.groovyDsl"
val addBuildSystemData by addBuildSystemData(
PATH,
BuildSystemData(
type = BuildSystemType.GradleGroovyDsl,
buildFileData = BuildFileData(
@@ -1,20 +1,21 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildFileData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.addBuildSystemData
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.GradlePrinter
class KotlinDslPlugin(context: Context) : GradlePlugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "buildSystem.gradle.kotlinDsl"
companion object : PluginSettingsOwner() {
override val pluginPath = "buildSystem.gradle.kotlinDsl"
val addBuildSystemData by addBuildSystemData(
PATH,
BuildSystemData(
type = BuildSystemType.GradleKotlinDsl,
buildFileData = BuildFileData(
@@ -21,10 +21,10 @@ import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
import java.nio.file.Path
class KotlinPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "kotlin"
companion object : PluginSettingsOwner() {
override val pluginPath = "kotlin"
private val moduleDependenciesValidator = settingValidator<List<Module>> { modules ->
val allModules = modules.withAllSubModules(includeSourcesets = true).toSet()
@@ -47,12 +47,11 @@ class KotlinPlugin(context: Context) : Plugin(context) {
}
val version by property(
PATH,
// todo do not hardcode kind & repository
WizardKotlinVersion(Versions.KOTLIN, KotlinVersionKind.M, Repositories.KOTLIN_EAP_BINTRAY)
)
val initKotlinVersions by pipelineTask(PATH, GenerationPhase.PREPARE_GENERATION) {
val initKotlinVersions by pipelineTask(GenerationPhase.PREPARE_GENERATION) {
title = KotlinNewProjectWizardBundle.message("plugin.kotlin.downloading.kotlin.versions")
withAction {
@@ -64,7 +63,6 @@ class KotlinPlugin(context: Context) : Plugin(context) {
val projectKind by enumSetting<ProjectKind>(
KotlinNewProjectWizardBundle.message("plugin.kotlin.setting.project.kind"),
GenerationPhase.FIRST_STEP,
PATH
)
private fun List<Module>.findDuplicatesByName() =
@@ -74,7 +72,6 @@ class KotlinPlugin(context: Context) : Plugin(context) {
KotlinNewProjectWizardBundle.message("plugin.kotlin.setting.modules"),
GenerationPhase.SECOND_STEP,
Module.parser,
PATH
) {
validate { value ->
val allModules = value.withAllSubModules()
@@ -106,7 +103,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
validate(moduleDependenciesValidator)
}
val createModules by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(BuildSystemPlugin.createModules)
runAfter(StructurePlugin.createProjectDir)
withAction {
@@ -118,7 +115,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
}
}
val createPluginRepositories by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createPluginRepositories by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(BuildSystemPlugin.createModules)
withAction {
val version = version.propertyValue
@@ -131,7 +128,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
}
}
val createSourcesetDirectories by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val createSourcesetDirectories by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
withAction {
fun Path.createKotlinAndResourceDirectories(moduleConfigurator: ModuleConfigurator) =
@@ -12,10 +12,10 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.withAllSubModules
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
class ProjectTemplatesPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
const val PATH = "projectTemplates"
companion object : PluginSettingsOwner() {
override val pluginPath = "projectTemplates"
val template by dropDownSetting<ProjectTemplate>(
KotlinNewProjectWizardBundle.message("plugin.templates.setting.template"),
@@ -23,7 +23,6 @@ class ProjectTemplatesPlugin(context: Context) : Plugin(context) {
parser = valueParserM { _, _ ->
Failure(ParseError("Project templates is not supported in yaml for now"))
},
PATH
) {
values = ProjectTemplate.ALL
isRequired = false
@@ -1,17 +1,18 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.templates.ConsoleJvmApplicationTemplate
class ConsoleJvmApplicationTemplatePlugin(context: Context) : TemplatePlugin(context) {
override val path = PATH
override val path = pluginPath
override val pipelineTasks: List<PipelineTask> = super.pipelineTasks + listOf(addTemplate)
companion object {
private const val PATH = "template.consoleJvmApplicationTemplate"
companion object : PluginSettingsOwner() {
override val pluginPath = "template.consoleJvmApplicationTemplate"
val addTemplate by addTemplateTask(PATH, ConsoleJvmApplicationTemplate())
val addTemplate by addTemplateTask(ConsoleJvmApplicationTemplate())
}
}
@@ -1,20 +1,21 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.templates.SimpleJsClientTemplate
class JsTemplatesPlugin(context: Context) : TemplatePlugin(context) {
override val path = PATH
override val path = pluginPath
override val pipelineTasks: List<PipelineTask> = super.pipelineTasks +
listOf(
addTemplate,
)
companion object {
private const val PATH = "template.jsTemplates"
companion object : PluginSettingsOwner() {
override val pluginPath = "template.jsTemplates"
val addTemplate by addTemplateTask(PATH, SimpleJsClientTemplate())
val addTemplate by addTemplateTask(SimpleJsClientTemplate())
}
}
@@ -1,20 +1,21 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.templates.KtorServerTemplate
class KtorTemplatesPlugin(context: Context) : TemplatePlugin(context) {
override val path = PATH
override val path = pluginPath
override val pipelineTasks: List<PipelineTask> = super.pipelineTasks +
listOf(
addTemplate,
)
companion object {
private const val PATH = "template.ktorTemplates"
companion object: PluginSettingsOwner() {
override val pluginPath = "template.ktorTemplates"
val addTemplate by addTemplateTask(PATH, KtorServerTemplate())
val addTemplate by addTemplateTask(KtorServerTemplate())
}
}
@@ -6,20 +6,21 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.templates.NativeConsoleApplicationTemplate
class NativeConsoleApplicationTemplatePlugin(context: Context) : TemplatePlugin(context) {
override val path = PATH
override val path = pluginPath
override val pipelineTasks: List<PipelineTask> = super.pipelineTasks +
listOf(
addTemplate,
)
companion object {
private const val PATH = "template.nativeConsoleApplicationTemplate"
companion object : PluginSettingsOwner() {
override val pluginPath = "template.nativeConsoleApplicationTemplate"
val addTemplate by addTemplateTask(PATH, NativeConsoleApplicationTemplate())
val addTemplate by addTemplateTask( NativeConsoleApplicationTemplate())
}
}
@@ -6,24 +6,24 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.templates.KtorServerTemplate
import org.jetbrains.kotlin.tools.projectWizard.templates.SimpleJsClientTemplate
import org.jetbrains.kotlin.tools.projectWizard.templates.SimpleNodeJsTemplate
class SimpleNodeJsTemplatesPlugin(context: Context) : TemplatePlugin(context) {
override val path = PATH
override val path = pluginPath
override val pipelineTasks: List<PipelineTask> = super.pipelineTasks +
listOf(
KtorTemplatesPlugin.addTemplate,
)
val addTemplate by addTemplateTask(PATH, SimpleNodeJsTemplate())
val addTemplate by addTemplateTask(SimpleNodeJsTemplate())
companion object {
private const val PATH = "template.simpleNodeJs"
companion object : PluginSettingsOwner() {
override val pluginPath = "template.simpleNodeJs"
val addTemplate by addTemplateTask(PATH, KtorServerTemplate())
val addTemplate by addTemplateTask(KtorServerTemplate())
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.Plugin
import org.jetbrains.kotlin.tools.projectWizard.core.PluginSettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.core.entity.Property
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.PluginSetting
@@ -9,16 +10,16 @@ import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.templates.Template
abstract class TemplatePlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
override val settings: List<PluginSetting<*, *>> = emptyList()
override val pipelineTasks: List<PipelineTask> = emptyList()
override val properties: List<Property<*>> = emptyList()
companion object {
const val PATH = "template"
companion object : PluginSettingsOwner() {
override val pluginPath = "template"
fun addTemplateTask(prefix: String, template: Template) = pipelineTask(prefix, GenerationPhase.PREPARE) {
fun addTemplateTask(template: Template) = pipelineTask(GenerationPhase.PREPARE) {
withAction {
TemplatesPlugin.addTemplate.execute(template)
}
@@ -24,37 +24,34 @@ import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.settingValue
import java.nio.file.Path
class TemplatesPlugin(context: Context) : Plugin(context) {
override val path = PATH
override val path = pluginPath
companion object {
private const val PATH = "templates"
companion object : PluginSettingsOwner() {
override val pluginPath = "templates"
val templates by property<Map<String, Template>>(
PATH,
emptyMap()
)
val templates by property<Map<String, Template>>(emptyMap())
val addTemplate by task1<Template, Unit>(PATH) {
val addTemplate by task1<Template, Unit> {
withAction { template ->
templates.update { success(it + (template.id to template)) }
}
}
val fileTemplatesToRender by property<List<FileTemplate>>(PATH, emptyList())
val fileTemplatesToRender by property<List<FileTemplate>>(emptyList())
val addFileTemplate by task1<FileTemplate, Unit>(PATH) {
val addFileTemplate by task1<FileTemplate, Unit> {
withAction { template ->
fileTemplatesToRender.update { success(it + template) }
}
}
val addFileTemplates by task1<List<FileTemplate>, Unit>(PATH) {
val addFileTemplates by task1<List<FileTemplate>, Unit> {
withAction { templates ->
fileTemplatesToRender.addValues(templates)
}
}
val renderFileTemplates by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val renderFileTemplates by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin.createModules)
withAction {
val templateEngine = service<TemplateEngineService>()
@@ -64,7 +61,7 @@ class TemplatesPlugin(context: Context) : Plugin(context) {
}
}
val addTemplatesToModules by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val addTemplatesToModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(BuildSystemPlugin.createModules)
runAfter(KotlinPlugin.createModules)
@@ -92,7 +89,7 @@ class TemplatesPlugin(context: Context) : Plugin(context) {
}
}
val postApplyTemplatesToModules by pipelineTask(PATH, GenerationPhase.PROJECT_GENERATION) {
val postApplyTemplatesToModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runBefore(BuildSystemPlugin.createModules)
runAfter(KotlinPlugin.createModules)
runAfter(TemplatesPlugin.addTemplatesToModules)
@@ -66,7 +66,6 @@ fun <V : Any, T : SettingType<V>> Reader.settingValue(module: Module, setting: T
abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSettingItem {
final override fun <V : Any, T : SettingType<V>> settingDelegate(
prefix: String,
create: (path: String) -> SettingBuilder<V, T>
): ReadOnlyProperty<Any, TemplateSetting<V, T>> = cached { name ->
TemplateSetting(create(name).buildInternal())
@@ -158,14 +157,12 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: DropDownSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<V, DropDownSettingType<V>>> =
super.dropDownSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<V, DropDownSettingType<V>>>
@@ -173,13 +170,11 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
final override fun stringSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: StringSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<String, StringSettingType>> =
super.stringSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<String, StringSettingType>>
@@ -187,13 +182,11 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
final override fun booleanSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: BooleanSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<Boolean, BooleanSettingType>> =
super.booleanSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<Boolean, BooleanSettingType>>
@@ -202,14 +195,12 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ValueSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<V, ValueSettingType<V>>> =
super.valueSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<V, ValueSettingType<V>>>
@@ -217,13 +208,11 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
final override fun versionSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: VersionSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<Version, VersionSettingType>> =
super.versionSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<Version, VersionSettingType>>
@@ -232,14 +221,12 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
title: String,
neededAtPhase: GenerationPhase,
parser: Parser<V>,
prefix: String,
init: ListSettingType.Builder<V>.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<List<V>, ListSettingType<V>>> =
super.listSetting(
title,
neededAtPhase,
parser,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<List<V>, ListSettingType<V>>>
@@ -248,13 +235,11 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
final override fun pathSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String,
init: PathSettingType.Builder.() -> Unit
): ReadOnlyProperty<Any, TemplateSetting<Path, PathSettingType>> =
super.pathSetting(
title,
neededAtPhase,
prefix,
init
) as ReadOnlyProperty<Any, TemplateSetting<Path, PathSettingType>>
@@ -262,10 +247,9 @@ abstract class Template : SettingsOwner, EntitiesOwnerDescriptor, DisplayableSet
inline fun <reified E> enumSetting(
title: String,
neededAtPhase: GenerationPhase,
prefix: String = "",
crossinline init: DropDownSettingType.Builder<E>.() -> Unit = {}
): ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>> where E : Enum<E>, E : DisplayableSettingItem =
enumSettingImpl(title, neededAtPhase, prefix, init) as ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>>
enumSettingImpl(title, neededAtPhase, init) as ReadOnlyProperty<Any, TemplateSetting<E, DropDownSettingType<E>>>
companion object {
fun parser(templateId: Identificator): Parser<Template> = mapParser { map, path ->