Wizard: Move test framework settings to module configurators
This commit is contained in:
+20
@@ -1,10 +1,13 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep
|
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectTemplates.ProjectTemplatesPlugin
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectTemplates.ProjectTemplatesPlugin
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
|
import org.jetbrains.kotlin.tools.projectWizard.projectTemplates.ProjectTemplate
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard
|
import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.*
|
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.*
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
@@ -54,6 +57,23 @@ class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
|||||||
// TODO do not use settingContext directly
|
// TODO do not use settingContext directly
|
||||||
context.settingContext[setting] = value
|
context.settingContext[setting] = value
|
||||||
}
|
}
|
||||||
|
allModules().forEach { module ->
|
||||||
|
module.initDefaultValuesForSettings(valuesReadingContext.context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun allModules(): List<Module> {
|
||||||
|
val modules = mutableListOf<Module>()
|
||||||
|
|
||||||
|
fun addModule(module: Module) {
|
||||||
|
modules += module
|
||||||
|
module.subModules.forEach(::addModule)
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesReadingContext.context.settingContext[KotlinPlugin::modules.reference]
|
||||||
|
?.forEach(::addModule)
|
||||||
|
|
||||||
|
return modules
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||||
|
|||||||
+2
-2
@@ -31,12 +31,12 @@ class ModulesEditorComponent(
|
|||||||
allowAndroid = isMppProject,
|
allowAndroid = isMppProject,
|
||||||
allowIos = isMppProject,
|
allowIos = isMppProject,
|
||||||
allModules = value ?: emptyList(),
|
allModules = value ?: emptyList(),
|
||||||
createModule = { model.add(it) }
|
createModule = model::add
|
||||||
)?.showInCenterOf(component)
|
)?.showInCenterOf(component)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
private val model = TargetsModel(tree, ::value)
|
private val model = TargetsModel(tree, ::value, valuesReadingContext.context)
|
||||||
|
|
||||||
override fun onInit() {
|
override fun onInit() {
|
||||||
super.onInit()
|
super.onInit()
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor
|
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
@@ -9,7 +10,8 @@ import kotlin.reflect.KMutableProperty0
|
|||||||
|
|
||||||
class TargetsModel(
|
class TargetsModel(
|
||||||
private val tree: ModulesEditorTree,
|
private val tree: ModulesEditorTree,
|
||||||
private val value: KMutableProperty0<List<Module>?>
|
private val value: KMutableProperty0<List<Module>?>,
|
||||||
|
private val context: Context
|
||||||
) {
|
) {
|
||||||
private val root get() = tree.model.root as DefaultMutableTreeNode
|
private val root get() = tree.model.root as DefaultMutableTreeNode
|
||||||
|
|
||||||
@@ -57,6 +59,7 @@ class TargetsModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun add(module: Module) {
|
fun add(module: Module) {
|
||||||
|
module.initDefaultValuesForSettings(context)
|
||||||
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -100,7 +100,9 @@ class DropdownSettingComponent(
|
|||||||
valuesReadingContext = valuesReadingContext,
|
valuesReadingContext = valuesReadingContext,
|
||||||
initialValues = setting.type.values,
|
initialValues = setting.type.values,
|
||||||
validator = setting.validator,
|
validator = setting.validator,
|
||||||
filter = { value -> setting.type.filter(valuesReadingContext, reference, value) },
|
filter = { value ->
|
||||||
|
setting.type.filter(valuesReadingContext, reference, value)
|
||||||
|
},
|
||||||
labelText = setting.title,
|
labelText = setting.title,
|
||||||
onValueUpdate = { newValue -> value = newValue }
|
onValueUpdate = { newValue -> value = newValue }
|
||||||
).asSubComponent()
|
).asSubComponent()
|
||||||
|
|||||||
+1
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.EntitiesOwnerDescriptor
|
import org.jetbrains.kotlin.tools.projectWizard.core.EntitiesOwnerDescriptor
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.Parser
|
import org.jetbrains.kotlin.tools.projectWizard.core.Parser
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||||
|
|||||||
+22
-7
@@ -41,13 +41,10 @@ data class PluginSettingReference<V : Any, T : SettingType<V>>(
|
|||||||
settingContext.getPluginSetting(this@PluginSettingReference)
|
settingContext.getPluginSetting(this@PluginSettingReference)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
sealed class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>> : SettingReference<V, T>() {
|
||||||
val descriptor: ModuleConfigurator,
|
abstract val descriptor: ModuleConfigurator
|
||||||
val moduleId: Identificator,
|
abstract val moduleId: Identificator
|
||||||
val setting: ModuleConfiguratorSetting<V, T>
|
abstract val setting: ModuleConfiguratorSetting<V, T>
|
||||||
) : SettingReference<V, T>() {
|
|
||||||
constructor(descriptor: ModuleConfigurator, module: Module, setting: ModuleConfiguratorSetting<V, T>) :
|
|
||||||
this(descriptor, module.identificator, setting)
|
|
||||||
|
|
||||||
override val path: String
|
override val path: String
|
||||||
get() = "${descriptor.id}/$moduleId/${setting.path}"
|
get() = "${descriptor.id}/$moduleId/${setting.path}"
|
||||||
@@ -56,6 +53,24 @@ data class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
|||||||
get() = setting.type::class
|
get() = setting.type::class
|
||||||
|
|
||||||
override fun Context.getSetting(): Setting<V, T> = setting
|
override fun Context.getSetting(): Setting<V, T> = setting
|
||||||
|
abstract val module: Module?
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ModuleBasedConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
||||||
|
override val descriptor: ModuleConfigurator,
|
||||||
|
override val module: Module,
|
||||||
|
override val setting: ModuleConfiguratorSetting<V, T>
|
||||||
|
) : ModuleConfiguratorSettingReference<V, T>() {
|
||||||
|
override val moduleId: Identificator
|
||||||
|
get() = module.identificator
|
||||||
|
}
|
||||||
|
|
||||||
|
data class IdBasedConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
||||||
|
override val descriptor: ModuleConfigurator,
|
||||||
|
override val moduleId: Identificator,
|
||||||
|
override val setting: ModuleConfiguratorSetting<V, T>
|
||||||
|
) : ModuleConfiguratorSettingReference<V, T>() {
|
||||||
|
override val module: Module? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class TemplateSettingReference<V : Any, T : SettingType<V>> : SettingReference<V, T>() {
|
sealed class TemplateSettingReference<V : Any, T : SettingType<V>> : SettingReference<V, T>() {
|
||||||
|
|||||||
+34
-9
@@ -19,22 +19,37 @@ import java.nio.file.Path
|
|||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
|
|
||||||
|
|
||||||
class ModuleSettingsEnvironment(private val configurator: ModuleConfigurator, private val moduleId: Identificator) {
|
sealed class ModuleCondifuratorSettingsEnvironment {
|
||||||
val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference
|
abstract val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference: ModuleConfiguratorSettingReference<V, T>
|
||||||
get() = ModuleConfiguratorSettingReference(configurator, moduleId, this)
|
}
|
||||||
|
|
||||||
|
class ModuleBasedConfiguratorSettingsEnvironment(
|
||||||
|
private val configurator: ModuleConfigurator,
|
||||||
|
private val module: Module
|
||||||
|
) : ModuleCondifuratorSettingsEnvironment() {
|
||||||
|
override val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference: ModuleConfiguratorSettingReference<V, T>
|
||||||
|
get() = ModuleBasedConfiguratorSettingReference(configurator, module, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class IdBasedConfiguratorSettingsEnvironment(
|
||||||
|
private val configurator: ModuleConfigurator,
|
||||||
|
private val moduleId: Identificator
|
||||||
|
) : ModuleCondifuratorSettingsEnvironment() {
|
||||||
|
override val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference: ModuleConfiguratorSettingReference<V, T>
|
||||||
|
get() = IdBasedConfiguratorSettingReference(configurator, moduleId, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> withSettingsOf(
|
fun <T> withSettingsOf(
|
||||||
moduleId: Identificator,
|
moduleId: Identificator,
|
||||||
configurator: ModuleConfigurator,
|
configurator: ModuleConfigurator,
|
||||||
function: ModuleSettingsEnvironment.() -> T
|
function: ModuleCondifuratorSettingsEnvironment.() -> T
|
||||||
): T = function(ModuleSettingsEnvironment(configurator, moduleId))
|
): T = function(IdBasedConfiguratorSettingsEnvironment(configurator, moduleId))
|
||||||
|
|
||||||
fun <T> withSettingsOf(
|
fun <T> withSettingsOf(
|
||||||
module: Module,
|
module: Module,
|
||||||
configurator: ModuleConfigurator = module.configurator,
|
configurator: ModuleConfigurator = module.configurator,
|
||||||
function: ModuleSettingsEnvironment.() -> T
|
function: ModuleCondifuratorSettingsEnvironment.() -> T
|
||||||
): T = function(ModuleSettingsEnvironment(configurator, module.identificator))
|
): T = function(ModuleBasedConfiguratorSettingsEnvironment(configurator, module))
|
||||||
|
|
||||||
|
|
||||||
abstract class ModuleConfiguratorWithSettings : ModuleConfigurator, SettingsOwner {
|
abstract class ModuleConfiguratorWithSettings : ModuleConfigurator, SettingsOwner {
|
||||||
@@ -144,6 +159,16 @@ abstract class ModuleConfiguratorWithSettings : ModuleConfigurator, SettingsOwne
|
|||||||
values = enumValues<E>().asList()
|
values = enumValues<E>().asList()
|
||||||
init()
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun initDefaultValuesFor(module: Module, context: Context) {
|
||||||
|
withSettingsOf(module) {
|
||||||
|
settings.forEach { setting ->
|
||||||
|
val defaultValue = setting.defaultValue ?: return@forEach
|
||||||
|
context.settingContext[setting.reference] = defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ModuleConfigurator.settings
|
val ModuleConfigurator.settings
|
||||||
@@ -154,7 +179,7 @@ val ModuleConfigurator.settings
|
|||||||
|
|
||||||
val Module.configuratorSettings
|
val Module.configuratorSettings
|
||||||
get() = configurator.settings.map { setting ->
|
get() = configurator.settings.map { setting ->
|
||||||
ModuleConfiguratorSettingReference(configurator, this, setting)
|
ModuleBasedConfiguratorSettingReference(configurator, this, setting)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||||
@@ -169,7 +194,7 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
|||||||
fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||||
emptyList()
|
emptyList()
|
||||||
|
|
||||||
fun createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||||
emptyList()
|
emptyList()
|
||||||
|
|
||||||
fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.moduleConfigurators
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSetting
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSettingReference
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSettingReference
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.DependencyType
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinArbitraryDependencyIR
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleConfigurationData
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||||
|
|
||||||
|
abstract class ModuleConfiguratorWithTests : ModuleConfiguratorWithSettings() {
|
||||||
|
val framework by enumSetting<KotlinTestFramework>(
|
||||||
|
"Test Framework",
|
||||||
|
neededAtPhase = GenerationPhase.PROJECT_GENERATION
|
||||||
|
) {
|
||||||
|
defaultValue = defaultTestFramework()
|
||||||
|
|
||||||
|
filter = filter@{ reference, kotlinTestFramework ->
|
||||||
|
if (reference !is ModuleConfiguratorSettingReference<*, *>) return@filter true
|
||||||
|
|
||||||
|
val moduleType = reference.module?.configurator?.moduleType
|
||||||
|
kotlinTestFramework.moduleType == moduleType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun defaultTestFramework(): KotlinTestFramework
|
||||||
|
|
||||||
|
override fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||||
|
withSettingsOf(module) {
|
||||||
|
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
||||||
|
KotlinArbitraryDependencyIR(
|
||||||
|
dependencyName,
|
||||||
|
isInMppModule = module.kind
|
||||||
|
.let { it == ModuleKind.multiplatform || it == ModuleKind.target },
|
||||||
|
version = KotlinPlugin::version.settingValue,
|
||||||
|
dependencyType = DependencyType.TEST
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val settings: List<ModuleConfiguratorSetting<*, *>> = listOf(framework)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum class KotlinTestFramework(
|
||||||
|
override val text: String,
|
||||||
|
val moduleType: ModuleType,
|
||||||
|
val dependencyNames: List<String>
|
||||||
|
) : DisplayableSettingItem {
|
||||||
|
JUNIT4("JUnit 4 Test Framework", ModuleType.jvm, listOf("test-junit")),
|
||||||
|
JUNIT5("JUnit 5 Test Framework", ModuleType.jvm, listOf("test-junit5")),
|
||||||
|
TEST_NG("Test NG Test Framework", ModuleType.jvm, listOf("test-testng")),
|
||||||
|
JS("JavaScript Test Framework", ModuleType.js, listOf("test-js")),
|
||||||
|
COMMON("Common Test Framework", ModuleType.common, listOf("test-common", "test-annotations-common")),
|
||||||
|
}
|
||||||
+15
-5
@@ -20,6 +20,8 @@ interface TargetConfigurator : ModuleConfigurator {
|
|||||||
fun createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
fun createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class TargetConfiguratorWithTests : ModuleConfiguratorWithTests(), TargetConfigurator
|
||||||
|
|
||||||
interface SingleCoexistenceTargetConfigurator : TargetConfigurator {
|
interface SingleCoexistenceTargetConfigurator : TargetConfigurator {
|
||||||
override fun canCoexistsWith(other: List<TargetConfigurator>): Boolean =
|
override fun canCoexistsWith(other: List<TargetConfigurator>): Boolean =
|
||||||
other.none { it == this }
|
other.none { it == this }
|
||||||
@@ -49,11 +51,13 @@ private fun Module.createTargetAccessIr(moduleSubType: ModuleSubType) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
interface JsTargetConfigurator : TargetConfigurator, SingleCoexistenceTargetConfigurator {
|
abstract class JsTargetConfigurator : TargetConfiguratorWithTests(), SingleCoexistenceTargetConfigurator {
|
||||||
override val moduleType: ModuleType get() = ModuleType.js
|
override val moduleType: ModuleType get() = ModuleType.js
|
||||||
|
|
||||||
|
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
|
||||||
}
|
}
|
||||||
|
|
||||||
object JsBrowserTargetConfigurator : JsTargetConfigurator {
|
object JsBrowserTargetConfigurator : JsTargetConfigurator() {
|
||||||
override val id = "jsBrowser"
|
override val id = "jsBrowser"
|
||||||
override val text = "Browser"
|
override val text = "Browser"
|
||||||
override val suggestedModuleName = "browser"
|
override val suggestedModuleName = "browser"
|
||||||
@@ -70,11 +74,12 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object JsNodeTargetConfigurator : JsTargetConfigurator {
|
object JsNodeTargetConfigurator : JsTargetConfigurator() {
|
||||||
override val id = "jsNode"
|
override val id = "jsNode"
|
||||||
override val text = "Node.js"
|
override val text = "Node.js"
|
||||||
override val suggestedModuleName = "nodeJs"
|
override val suggestedModuleName = "nodeJs"
|
||||||
|
|
||||||
|
|
||||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||||
+DefaultTargetConfigurationIR(
|
+DefaultTargetConfigurationIR(
|
||||||
module.createTargetAccessIr(ModuleSubType.js),
|
module.createTargetAccessIr(ModuleSubType.js),
|
||||||
@@ -87,15 +92,20 @@ object JsNodeTargetConfigurator : JsTargetConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object CommonTargetConfigurator : SimpleTargetConfigurator, SingleCoexistenceTargetConfigurator {
|
object CommonTargetConfigurator : TargetConfiguratorWithTests(), SimpleTargetConfigurator, SingleCoexistenceTargetConfigurator {
|
||||||
override val moduleSubType = ModuleSubType.common
|
override val moduleSubType = ModuleSubType.common
|
||||||
|
|
||||||
|
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.COMMON
|
||||||
}
|
}
|
||||||
|
|
||||||
object JvmTargetConfigurator : TargetConfigurator,
|
object JvmTargetConfigurator : TargetConfiguratorWithTests(),
|
||||||
|
TargetConfigurator,
|
||||||
SimpleTargetConfigurator,
|
SimpleTargetConfigurator,
|
||||||
JvmModuleConfigurator,
|
JvmModuleConfigurator,
|
||||||
SingleCoexistenceTargetConfigurator {
|
SingleCoexistenceTargetConfigurator {
|
||||||
override val moduleSubType = ModuleSubType.jvm
|
override val moduleSubType = ModuleSubType.jvm
|
||||||
|
|
||||||
|
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||||
}
|
}
|
||||||
|
|
||||||
object AndroidTargetConfigurator : TargetConfigurator,
|
object AndroidTargetConfigurator : TargetConfigurator,
|
||||||
|
|||||||
+6
-3
@@ -31,12 +31,15 @@ interface SinglePlatformModuleConfigurator : ModuleConfigurator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object JvmSinglePlatformModuleConfigurator : SinglePlatformModuleConfigurator,
|
object JvmSinglePlatformModuleConfigurator : ModuleConfiguratorWithTests(),
|
||||||
|
SinglePlatformModuleConfigurator,
|
||||||
JvmModuleConfigurator {
|
JvmModuleConfigurator {
|
||||||
override val moduleType = ModuleType.jvm
|
override val moduleType get() = ModuleType.jvm
|
||||||
override val suggestedModuleName = "jvm"
|
override val suggestedModuleName = "jvm"
|
||||||
override val id = "JVM Module"
|
override val id = "JVM Module"
|
||||||
|
|
||||||
|
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||||
|
|
||||||
override val canContainSubModules = true
|
override val canContainSubModules = true
|
||||||
|
|
||||||
override fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
override fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
||||||
@@ -49,7 +52,7 @@ object JvmSinglePlatformModuleConfigurator : SinglePlatformModuleConfigurator,
|
|||||||
|
|
||||||
object IOSSinglePlatformModuleConfigurator :
|
object IOSSinglePlatformModuleConfigurator :
|
||||||
SinglePlatformModuleConfigurator {
|
SinglePlatformModuleConfigurator {
|
||||||
override val moduleType = ModuleType.jvm //todo
|
override val moduleType get() = ModuleType.jvm //todo
|
||||||
override val id = "IOS Module"
|
override val id = "IOS Module"
|
||||||
override val suggestedModuleName = "ios"
|
override val suggestedModuleName = "ios"
|
||||||
override val greyText = "Requires Apple Xcode"
|
override val greyText = "Requires Apple Xcode"
|
||||||
|
|||||||
-1
@@ -24,7 +24,6 @@ object Plugins {
|
|||||||
ProjectTemplatesPlugin(context),
|
ProjectTemplatesPlugin(context),
|
||||||
|
|
||||||
// templates
|
// templates
|
||||||
KotlinTestTemplatePlugin(context),
|
|
||||||
ConsoleJvmApplicationTemplatePlugin(context),
|
ConsoleJvmApplicationTemplatePlugin(context),
|
||||||
KtorTemplatesPlugin(context),
|
KtorTemplatesPlugin(context),
|
||||||
JsTemplatesPlugin(context),
|
JsTemplatesPlugin(context),
|
||||||
|
|||||||
+12
-10
@@ -77,17 +77,19 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
|||||||
|
|
||||||
|
|
||||||
private fun TaskRunningContext.createBuildFiles(modules: List<Module>): TaskResult<List<BuildFileIR>> =
|
private fun TaskRunningContext.createBuildFiles(modules: List<Module>): TaskResult<List<BuildFileIR>> =
|
||||||
ModulesToIRsConverter(
|
with(
|
||||||
ModuleConfigurationData(
|
ModulesToIRsConverter(
|
||||||
modules,
|
ModuleConfigurationData(
|
||||||
projectPath,
|
modules,
|
||||||
StructurePlugin::name.settingValue,
|
projectPath,
|
||||||
KotlinPlugin::version.settingValue,
|
StructurePlugin::name.settingValue,
|
||||||
buildSystemType,
|
KotlinPlugin::version.settingValue,
|
||||||
pomIR(),
|
buildSystemType,
|
||||||
this
|
pomIR(),
|
||||||
|
this
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).createBuildFiles()
|
) { createBuildFiles() }
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+4
-4
@@ -57,7 +57,7 @@ class ModulesToIRsConverter(
|
|||||||
else -> rootPath / module.name
|
else -> rootPath / module.name
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
fun ValuesReadingContext.createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
||||||
val needExplicitRootBuildFile = !needFlattening
|
val needExplicitRootBuildFile = !needFlattening
|
||||||
val parentModuleHasTransitivelySpecifiedKotlinVersion = allModules.any { modules ->
|
val parentModuleHasTransitivelySpecifiedKotlinVersion = allModules.any { modules ->
|
||||||
modules.configurator == AndroidSinglePlatformModuleConfigurator
|
modules.configurator == AndroidSinglePlatformModuleConfigurator
|
||||||
@@ -82,7 +82,7 @@ class ModulesToIRsConverter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun createBuildFileForModule(
|
private fun ValuesReadingContext.createBuildFileForModule(
|
||||||
module: Module,
|
module: Module,
|
||||||
state: ModulesToIrsState
|
state: ModulesToIrsState
|
||||||
): TaskResult<List<BuildFileIR>> = when (module.kind) {
|
): TaskResult<List<BuildFileIR>> = when (module.kind) {
|
||||||
@@ -91,7 +91,7 @@ class ModulesToIRsConverter(
|
|||||||
else -> Success(emptyList())
|
else -> Success(emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSinglePlatformModule(
|
private fun ValuesReadingContext.createSinglePlatformModule(
|
||||||
module: Module,
|
module: Module,
|
||||||
state: ModulesToIrsState
|
state: ModulesToIrsState
|
||||||
): TaskResult<List<BuildFileIR>> = with(data) {
|
): TaskResult<List<BuildFileIR>> = with(data) {
|
||||||
@@ -102,7 +102,7 @@ class ModulesToIRsConverter(
|
|||||||
+module.sourcesets.flatMap { sourceset ->
|
+module.sourcesets.flatMap { sourceset ->
|
||||||
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
||||||
}
|
}
|
||||||
+configurator.createModuleIRs(data, module)
|
with(configurator) { +createModuleIRs(data, module) }
|
||||||
addIfNotNull(
|
addIfNotNull(
|
||||||
configurator.createStdlibType(data, module)?.let { stdlibType ->
|
configurator.createStdlibType(data, module)?.let { stdlibType ->
|
||||||
KotlinStdlibDependencyIR(
|
KotlinStdlibDependencyIR(
|
||||||
|
|||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.plugins.templates
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.templates.*
|
|
||||||
|
|
||||||
class KotlinTestTemplatePlugin(context: Context) : TemplatePlugin(context) {
|
|
||||||
val addTemplate by addTemplateTask(KotlinTestTemplate())
|
|
||||||
}
|
|
||||||
+3
-18
@@ -157,24 +157,9 @@ object MultiplatformLibrary : ProjectTemplate() {
|
|||||||
MultiplatformModule(
|
MultiplatformModule(
|
||||||
"library",
|
"library",
|
||||||
listOf(
|
listOf(
|
||||||
ModuleType.common.createDefaultTarget().apply {
|
ModuleType.common.createDefaultTarget(),
|
||||||
// testSourceset?.withTemplate(KotlinTestTemplate()) {
|
ModuleType.jvm.createDefaultTarget(),
|
||||||
// template.framework withValue KotlinTestFramework.COMMON
|
ModuleType.js.createDefaultTarget(),
|
||||||
// template.generateDummyTest withValue false
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
ModuleType.jvm.createDefaultTarget().apply {
|
|
||||||
// testSourceset?.withTemplate(KotlinTestTemplate()) {
|
|
||||||
// template.framework withValue KotlinTestFramework.JUNIT4
|
|
||||||
// template.generateDummyTest withValue false
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
ModuleType.js.createDefaultTarget().apply {
|
|
||||||
// testSourceset?.withTemplate(KotlinTestTemplate()) {
|
|
||||||
// template.framework withValue KotlinTestFramework.JS
|
|
||||||
// template.generateDummyTest withValue false
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
ModuleType.native.createDefaultTarget()
|
ModuleType.native.createDefaultTarget()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
+5
@@ -75,6 +75,11 @@ class Module(
|
|||||||
else -> "Module"
|
else -> "Module"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun initDefaultValuesForSettings(context: Context) {
|
||||||
|
configurator.safeAs<ModuleConfiguratorWithSettings>()?.initDefaultValuesFor(this, context)
|
||||||
|
template?.initDefaultValuesFor(this, context)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val parser: Parser<Module> = mapParser { map, path ->
|
val parser: Parser<Module> = mapParser { map, path ->
|
||||||
val (name) = map.parseValue<String>(path, "name")
|
val (name) = map.parseValue<String>(path, "name")
|
||||||
|
|||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.templates
|
|
||||||
|
|
||||||
import org.intellij.lang.annotations.Language
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSetting
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSettingReference
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.SourcesetType
|
|
||||||
|
|
||||||
class KotlinTestTemplate : Template() {
|
|
||||||
override val id: String = "kotlinTest"
|
|
||||||
override val title: String = "Kotlin Test framework"
|
|
||||||
@Language("HTML")
|
|
||||||
override val htmlDescription = """A unit test module using Kotlin Test Framework <br>
|
|
||||||
| For JVM JUnit4/5 and TestNG can be used <br>
|
|
||||||
| For Kotlin/JS Jasmine, Mocha, and Jest may be used<br><br>
|
|
||||||
| More information can be found <a href='https://kotlinlang.org/api/latest/kotlin.test/index.html'>here</a>
|
|
||||||
""".trimMargin()
|
|
||||||
override val moduleTypes = setOf(ModuleType.common, ModuleType.js, ModuleType.jvm)
|
|
||||||
|
|
||||||
override fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> =
|
|
||||||
withSettingsOf(module.originalModule) {
|
|
||||||
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
|
||||||
KotlinArbitraryDependencyIR(
|
|
||||||
dependencyName,
|
|
||||||
isInMppModule = module.originalModule.kind
|
|
||||||
.let { it == ModuleKind.multiplatform || it == ModuleKind.target },
|
|
||||||
version = KotlinPlugin::version.settingValue,
|
|
||||||
dependencyType = DependencyType.MAIN
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun TaskRunningContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> =
|
|
||||||
withSettingsOf(module.originalModule) {
|
|
||||||
buildList {
|
|
||||||
if (generateDummyTest.reference.settingValue) {
|
|
||||||
+(FileTemplateDescriptor("kotlinTestFramework/dummyTest.kt.vm", "Test.kt".asPath()) asSrcOf SourcesetType.main)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val framework by enumSetting<KotlinTestFramework>(
|
|
||||||
"Test Framework",
|
|
||||||
neededAtPhase = GenerationPhase.PROJECT_GENERATION
|
|
||||||
) {
|
|
||||||
filter = filter@{ reference, kotlinTestFramework ->
|
|
||||||
if (reference !is TemplateSettingReference) return@filter true
|
|
||||||
|
|
||||||
val moduleType = reference.module?.configurator?.moduleType
|
|
||||||
kotlinTestFramework.moduleType == moduleType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val generateDummyTest by booleanSetting(
|
|
||||||
"Generate Simple test case",
|
|
||||||
neededAtPhase = GenerationPhase.PROJECT_GENERATION
|
|
||||||
) {
|
|
||||||
defaultValue = false
|
|
||||||
}
|
|
||||||
override val settings: List<TemplateSetting<*, *>> =
|
|
||||||
listOf(framework, generateDummyTest)
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class KotlinTestFramework(
|
|
||||||
override val text: String,
|
|
||||||
val moduleType: ModuleType,
|
|
||||||
val dependencyNames: List<String>
|
|
||||||
) : DisplayableSettingItem {
|
|
||||||
JUNIT4("JUnit 4 Test Framework", ModuleType.jvm, listOf("test-junit")),
|
|
||||||
JUNIT5("JUnit 5 Test Framework", ModuleType.jvm, listOf("test-junit5")),
|
|
||||||
TEST_NG("Test NG Test Framework", ModuleType.jvm, listOf("test-testng")),
|
|
||||||
JS("JavaScript Test Framework", ModuleType.js, listOf("test-js")),
|
|
||||||
COMMON("Common Test Framework", ModuleType.common, listOf("test-common", "test-annotations-common")),
|
|
||||||
}
|
|
||||||
+9
@@ -66,6 +66,15 @@ abstract class Template : SettingsOwner {
|
|||||||
open val settings: List<TemplateSetting<*, *>> = emptyList()
|
open val settings: List<TemplateSetting<*, *>> = emptyList()
|
||||||
open val interceptionPoints: List<InterceptionPoint<Any>> = emptyList()
|
open val interceptionPoints: List<InterceptionPoint<Any>> = emptyList()
|
||||||
|
|
||||||
|
fun initDefaultValuesFor(module: Module, context: Context) {
|
||||||
|
withSettingsOf(module) {
|
||||||
|
settings.forEach { setting ->
|
||||||
|
val defaultValue = setting.defaultValue ?: return@forEach
|
||||||
|
context.settingContext[setting.reference] = defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = emptyList()
|
open fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = emptyList()
|
||||||
|
|
||||||
//TODO: use setting reading context
|
//TODO: use setting reading context
|
||||||
|
|||||||
Reference in New Issue
Block a user