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
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
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.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.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.ui.*
|
||||
import java.awt.BorderLayout
|
||||
@@ -54,6 +57,23 @@ class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
// TODO do not use settingContext directly
|
||||
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<*, *>?) {
|
||||
|
||||
+2
-2
@@ -31,12 +31,12 @@ class ModulesEditorComponent(
|
||||
allowAndroid = isMppProject,
|
||||
allowIos = isMppProject,
|
||||
allModules = value ?: emptyList(),
|
||||
createModule = { model.add(it) }
|
||||
createModule = model::add
|
||||
)?.showInCenterOf(component)
|
||||
}
|
||||
)
|
||||
|
||||
private val model = TargetsModel(tree, ::value)
|
||||
private val model = TargetsModel(tree, ::value, valuesReadingContext.context)
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
|
||||
+4
-1
@@ -1,5 +1,6 @@
|
||||
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.ModuleKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
@@ -9,7 +10,8 @@ import kotlin.reflect.KMutableProperty0
|
||||
|
||||
class TargetsModel(
|
||||
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
|
||||
|
||||
@@ -57,6 +59,7 @@ class TargetsModel(
|
||||
}
|
||||
|
||||
fun add(module: Module) {
|
||||
module.initDefaultValuesForSettings(context)
|
||||
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -100,7 +100,9 @@ class DropdownSettingComponent(
|
||||
valuesReadingContext = valuesReadingContext,
|
||||
initialValues = setting.type.values,
|
||||
validator = setting.validator,
|
||||
filter = { value -> setting.type.filter(valuesReadingContext, reference, value) },
|
||||
filter = { value ->
|
||||
setting.type.filter(valuesReadingContext, reference, value)
|
||||
},
|
||||
labelText = setting.title,
|
||||
onValueUpdate = { newValue -> value = newValue }
|
||||
).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.Parser
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
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)
|
||||
}
|
||||
|
||||
data class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
||||
val descriptor: ModuleConfigurator,
|
||||
val moduleId: Identificator,
|
||||
val setting: ModuleConfiguratorSetting<V, T>
|
||||
) : SettingReference<V, T>() {
|
||||
constructor(descriptor: ModuleConfigurator, module: Module, setting: ModuleConfiguratorSetting<V, T>) :
|
||||
this(descriptor, module.identificator, setting)
|
||||
sealed class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>> : SettingReference<V, T>() {
|
||||
abstract val descriptor: ModuleConfigurator
|
||||
abstract val moduleId: Identificator
|
||||
abstract val setting: ModuleConfiguratorSetting<V, T>
|
||||
|
||||
override val path: String
|
||||
get() = "${descriptor.id}/$moduleId/${setting.path}"
|
||||
@@ -56,6 +53,24 @@ data class ModuleConfiguratorSettingReference<V : Any, T : SettingType<V>>(
|
||||
get() = setting.type::class
|
||||
|
||||
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>() {
|
||||
|
||||
+34
-9
@@ -19,22 +19,37 @@ import java.nio.file.Path
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
|
||||
|
||||
class ModuleSettingsEnvironment(private val configurator: ModuleConfigurator, private val moduleId: Identificator) {
|
||||
val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference
|
||||
get() = ModuleConfiguratorSettingReference(configurator, moduleId, this)
|
||||
sealed class ModuleCondifuratorSettingsEnvironment {
|
||||
abstract val <V : Any, T : SettingType<V>> ModuleConfiguratorSetting<V, T>.reference: ModuleConfiguratorSettingReference<V, T>
|
||||
}
|
||||
|
||||
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(
|
||||
moduleId: Identificator,
|
||||
configurator: ModuleConfigurator,
|
||||
function: ModuleSettingsEnvironment.() -> T
|
||||
): T = function(ModuleSettingsEnvironment(configurator, moduleId))
|
||||
function: ModuleCondifuratorSettingsEnvironment.() -> T
|
||||
): T = function(IdBasedConfiguratorSettingsEnvironment(configurator, moduleId))
|
||||
|
||||
fun <T> withSettingsOf(
|
||||
module: Module,
|
||||
configurator: ModuleConfigurator = module.configurator,
|
||||
function: ModuleSettingsEnvironment.() -> T
|
||||
): T = function(ModuleSettingsEnvironment(configurator, module.identificator))
|
||||
function: ModuleCondifuratorSettingsEnvironment.() -> T
|
||||
): T = function(ModuleBasedConfiguratorSettingsEnvironment(configurator, module))
|
||||
|
||||
|
||||
abstract class ModuleConfiguratorWithSettings : ModuleConfigurator, SettingsOwner {
|
||||
@@ -144,6 +159,16 @@ abstract class ModuleConfiguratorWithSettings : ModuleConfigurator, SettingsOwne
|
||||
values = enumValues<E>().asList()
|
||||
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
|
||||
@@ -154,7 +179,7 @@ val ModuleConfigurator.settings
|
||||
|
||||
val Module.configuratorSettings
|
||||
get() = configurator.settings.map { setting ->
|
||||
ModuleConfiguratorSettingReference(configurator, this, setting)
|
||||
ModuleBasedConfiguratorSettingReference(configurator, this, setting)
|
||||
}
|
||||
|
||||
interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
@@ -169,7 +194,7 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
fun createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
abstract class TargetConfiguratorWithTests : ModuleConfiguratorWithTests(), TargetConfigurator
|
||||
|
||||
interface SingleCoexistenceTargetConfigurator : TargetConfigurator {
|
||||
override fun canCoexistsWith(other: List<TargetConfigurator>): Boolean =
|
||||
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 fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
|
||||
}
|
||||
|
||||
object JsBrowserTargetConfigurator : JsTargetConfigurator {
|
||||
object JsBrowserTargetConfigurator : JsTargetConfigurator() {
|
||||
override val id = "jsBrowser"
|
||||
override val text = "Browser"
|
||||
override val suggestedModuleName = "browser"
|
||||
@@ -70,11 +74,12 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
object JsNodeTargetConfigurator : JsTargetConfigurator {
|
||||
object JsNodeTargetConfigurator : JsTargetConfigurator() {
|
||||
override val id = "jsNode"
|
||||
override val text = "Node.js"
|
||||
override val suggestedModuleName = "nodeJs"
|
||||
|
||||
|
||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
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 fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.COMMON
|
||||
}
|
||||
|
||||
object JvmTargetConfigurator : TargetConfigurator,
|
||||
object JvmTargetConfigurator : TargetConfiguratorWithTests(),
|
||||
TargetConfigurator,
|
||||
SimpleTargetConfigurator,
|
||||
JvmModuleConfigurator,
|
||||
SingleCoexistenceTargetConfigurator {
|
||||
override val moduleSubType = ModuleSubType.jvm
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||
}
|
||||
|
||||
object AndroidTargetConfigurator : TargetConfigurator,
|
||||
|
||||
+6
-3
@@ -31,12 +31,15 @@ interface SinglePlatformModuleConfigurator : ModuleConfigurator {
|
||||
|
||||
}
|
||||
|
||||
object JvmSinglePlatformModuleConfigurator : SinglePlatformModuleConfigurator,
|
||||
object JvmSinglePlatformModuleConfigurator : ModuleConfiguratorWithTests(),
|
||||
SinglePlatformModuleConfigurator,
|
||||
JvmModuleConfigurator {
|
||||
override val moduleType = ModuleType.jvm
|
||||
override val moduleType get() = ModuleType.jvm
|
||||
override val suggestedModuleName = "jvm"
|
||||
override val id = "JVM Module"
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||
|
||||
override val canContainSubModules = true
|
||||
|
||||
override fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
||||
@@ -49,7 +52,7 @@ object JvmSinglePlatformModuleConfigurator : SinglePlatformModuleConfigurator,
|
||||
|
||||
object IOSSinglePlatformModuleConfigurator :
|
||||
SinglePlatformModuleConfigurator {
|
||||
override val moduleType = ModuleType.jvm //todo
|
||||
override val moduleType get() = ModuleType.jvm //todo
|
||||
override val id = "IOS Module"
|
||||
override val suggestedModuleName = "ios"
|
||||
override val greyText = "Requires Apple Xcode"
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ object Plugins {
|
||||
ProjectTemplatesPlugin(context),
|
||||
|
||||
// templates
|
||||
KotlinTestTemplatePlugin(context),
|
||||
ConsoleJvmApplicationTemplatePlugin(context),
|
||||
KtorTemplatesPlugin(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>> =
|
||||
ModulesToIRsConverter(
|
||||
ModuleConfigurationData(
|
||||
modules,
|
||||
projectPath,
|
||||
StructurePlugin::name.settingValue,
|
||||
KotlinPlugin::version.settingValue,
|
||||
buildSystemType,
|
||||
pomIR(),
|
||||
this
|
||||
with(
|
||||
ModulesToIRsConverter(
|
||||
ModuleConfigurationData(
|
||||
modules,
|
||||
projectPath,
|
||||
StructurePlugin::name.settingValue,
|
||||
KotlinPlugin::version.settingValue,
|
||||
buildSystemType,
|
||||
pomIR(),
|
||||
this
|
||||
)
|
||||
)
|
||||
).createBuildFiles()
|
||||
) { createBuildFiles() }
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ class ModulesToIRsConverter(
|
||||
else -> rootPath / module.name
|
||||
}
|
||||
|
||||
fun createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
fun ValuesReadingContext.createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
val needExplicitRootBuildFile = !needFlattening
|
||||
val parentModuleHasTransitivelySpecifiedKotlinVersion = allModules.any { modules ->
|
||||
modules.configurator == AndroidSinglePlatformModuleConfigurator
|
||||
@@ -82,7 +82,7 @@ class ModulesToIRsConverter(
|
||||
}
|
||||
|
||||
|
||||
private fun createBuildFileForModule(
|
||||
private fun ValuesReadingContext.createBuildFileForModule(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
): TaskResult<List<BuildFileIR>> = when (module.kind) {
|
||||
@@ -91,7 +91,7 @@ class ModulesToIRsConverter(
|
||||
else -> Success(emptyList())
|
||||
}
|
||||
|
||||
private fun createSinglePlatformModule(
|
||||
private fun ValuesReadingContext.createSinglePlatformModule(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
@@ -102,7 +102,7 @@ class ModulesToIRsConverter(
|
||||
+module.sourcesets.flatMap { sourceset ->
|
||||
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
||||
}
|
||||
+configurator.createModuleIRs(data, module)
|
||||
with(configurator) { +createModuleIRs(data, module) }
|
||||
addIfNotNull(
|
||||
configurator.createStdlibType(data, module)?.let { stdlibType ->
|
||||
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(
|
||||
"library",
|
||||
listOf(
|
||||
ModuleType.common.createDefaultTarget().apply {
|
||||
// testSourceset?.withTemplate(KotlinTestTemplate()) {
|
||||
// template.framework withValue KotlinTestFramework.COMMON
|
||||
// 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.common.createDefaultTarget(),
|
||||
ModuleType.jvm.createDefaultTarget(),
|
||||
ModuleType.js.createDefaultTarget(),
|
||||
ModuleType.native.createDefaultTarget()
|
||||
)
|
||||
)
|
||||
|
||||
+5
@@ -75,6 +75,11 @@ class Module(
|
||||
else -> "Module"
|
||||
}
|
||||
|
||||
fun initDefaultValuesForSettings(context: Context) {
|
||||
configurator.safeAs<ModuleConfiguratorWithSettings>()?.initDefaultValuesFor(this, context)
|
||||
template?.initDefaultValuesFor(this, context)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val parser: Parser<Module> = mapParser { map, path ->
|
||||
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 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()
|
||||
|
||||
//TODO: use setting reading context
|
||||
|
||||
Reference in New Issue
Block a user