Wizard: add jvm target setting for JVM configurations
#KT-36180 fixed
This commit is contained in:
+5
-1
@@ -8,7 +8,11 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = '1.8'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
jvmMain {
|
||||
dependencies {
|
||||
|
||||
+5
-1
@@ -8,7 +8,11 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ kotlin:
|
||||
name: a
|
||||
subModules:
|
||||
- type:
|
||||
targetJvmVersion: "1.8"
|
||||
name: jvmTarget
|
||||
testFramework: JUNIT4
|
||||
kind: target
|
||||
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
|
||||
}
|
||||
@@ -10,4 +12,7 @@ repositories {
|
||||
dependencies {
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||
}
|
||||
tasks.withType(KotlinCompile) {
|
||||
kotlinOptions.jvmTarget = '1.6'
|
||||
}
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.3.61"
|
||||
}
|
||||
@@ -10,4 +12,7 @@ repositories {
|
||||
dependencies {
|
||||
testImplementation(kotlin("test-junit"))
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
tasks.withType<KotlinCompile>() {
|
||||
kotlinOptions.jvmTarget = "1.6"
|
||||
}
|
||||
+1
@@ -14,6 +14,7 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kotlin.code.style>official</kotlin.code.style>
|
||||
<kotlin.compiler.jvmTarget>1.6</kotlin.compiler.jvmTarget>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
||||
+1
@@ -2,6 +2,7 @@ kotlin:
|
||||
projectKind: Singleplatform
|
||||
modules:
|
||||
- type:
|
||||
targetJvmVersion: "1.6"
|
||||
name: JVM Module
|
||||
testFramework: JUNIT4
|
||||
name: nya
|
||||
|
||||
+5
-1
@@ -8,7 +8,11 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = '9'
|
||||
}
|
||||
}
|
||||
js('a') {
|
||||
browser {
|
||||
|
||||
|
||||
+5
-1
@@ -8,7 +8,11 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = "9"
|
||||
}
|
||||
}
|
||||
js("a") {
|
||||
browser {
|
||||
|
||||
|
||||
+3
-2
@@ -6,6 +6,7 @@ kotlin:
|
||||
name: a
|
||||
subModules:
|
||||
- type:
|
||||
targetJvmVersion: "9"
|
||||
name: jvmTarget
|
||||
testFramework: JUNIT4
|
||||
kind: target
|
||||
@@ -14,8 +15,8 @@ kotlin:
|
||||
- type: main
|
||||
- type: test
|
||||
- type:
|
||||
name: jsBrowser
|
||||
testFramework: JS
|
||||
name: jsBrowser
|
||||
testFramework: JS
|
||||
kind: target
|
||||
name: a
|
||||
sourcesets:
|
||||
|
||||
+10
-8
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.core
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.Template
|
||||
import java.nio.file.Paths
|
||||
import kotlin.reflect.KClass
|
||||
@@ -31,16 +32,17 @@ fun <T : Any> alwaysFailingParser() = object : Parser<T>() {
|
||||
fun <T : Any> Parser<T>.parse(context: ParsingContext, value: Any?, path: String) =
|
||||
with(context) { parse(value, path) }
|
||||
|
||||
inline fun <reified E : Enum<E>> enumParser(): Parser<E> = object : Parser<E>() {
|
||||
inline fun <reified E> enumParser(): Parser<E> where E : Enum<E>, E : DisplayableSettingItem = object : Parser<E>() {
|
||||
override fun ParsingContext.parse(value: Any?, path: String): TaskResult<E> = computeM {
|
||||
val (enumName) = value.parseAs<String>(path)
|
||||
safe { enumValueOf<E>(enumName) }.mapFailure {
|
||||
listOf(
|
||||
ParseError(
|
||||
"For setting `$path` one of [${enumValues<E>().joinToString { it.name }}] was expected but `$enumName` was found"
|
||||
)
|
||||
val (name) = value.parseAs<String>(path)
|
||||
val createError = {
|
||||
ParseError(
|
||||
"For setting `$path` one of [${enumValues<E>().joinToString { it.name }}] was expected but `$name` was found"
|
||||
)
|
||||
}
|
||||
val byEnumName = safe { enumValueOf<E>(name) }.mapFailure { createError() }
|
||||
val byText = enumValues<E>().firstOrNull { it.text == name }.toResult { createError() }
|
||||
byEnumName.recover { byText }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +191,7 @@ val pathParser = valueParser { value, path ->
|
||||
value.parseAs<String>(path).map { Paths.get(it) }.get()
|
||||
}
|
||||
|
||||
infix fun <V: Any> Parser<V>.or(alternative: Parser<V>): Parser<V> = object : Parser<V>() {
|
||||
infix fun <V : Any> Parser<V>.or(alternative: Parser<V>): Parser<V> = object : Parser<V>() {
|
||||
override fun ParsingContext.parse(value: Any?, path: String): TaskResult<V> =
|
||||
this@or.parse(this, value, path).recover { alternative.parse(this, value, path) }
|
||||
}
|
||||
+1
-1
@@ -111,7 +111,7 @@ fun <T : Any, R : Any> TaskResult<T>.map(f: (T) -> R): TaskResult<R> = when (thi
|
||||
is Success<T> -> Success(f(value))
|
||||
}
|
||||
|
||||
fun <T : Any> TaskResult<T>.mapFailure(f: (List<Error>) -> List<Error>): TaskResult<T> = when (this) {
|
||||
fun <T : Any> TaskResult<T>.mapFailure(f: (List<Error>) -> Error): TaskResult<T> = when (this) {
|
||||
is Failure -> Failure(f(errors))
|
||||
is Success<T> -> this
|
||||
}
|
||||
|
||||
+2
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.safeAs
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.multiplatform.DefaultTargetConfigurationIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.multiplatform.TargetConfigurationIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.maven.MavenPropertyIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.maven.PluginRepositoryMavenIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleSubType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.BuildFilePrinter
|
||||
@@ -83,6 +84,7 @@ data class BuildFileIR(
|
||||
node("properties") {
|
||||
singleLineNode("project.build.sourceEncoding") { +"UTF-8" }
|
||||
singleLineNode("kotlin.code.style") { +"official" }
|
||||
irsOfType<MavenPropertyIR>().listNl()
|
||||
}
|
||||
|
||||
distinctRepositories().takeIf { it.isNotEmpty() }?.let { repositories ->
|
||||
|
||||
+17
-4
@@ -5,12 +5,10 @@ import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.FreeIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.render
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.GradlePrinter
|
||||
|
||||
interface GradleTaskAccessIR : GradleIR {
|
||||
val name: String
|
||||
}
|
||||
interface GradleTaskAccessIR : GradleIR
|
||||
|
||||
data class GradleByNameTaskAccessIR(
|
||||
override val name: String,
|
||||
val name: String,
|
||||
val taskClass: String? = null
|
||||
) : GradleTaskAccessIR {
|
||||
override fun GradlePrinter.renderGradle() {
|
||||
@@ -27,6 +25,21 @@ data class GradleByNameTaskAccessIR(
|
||||
}
|
||||
}
|
||||
|
||||
data class GradleByClassTasksAccessIR(
|
||||
val taskClass: String
|
||||
) : GradleTaskAccessIR {
|
||||
override fun GradlePrinter.renderGradle() {
|
||||
when (dsl) {
|
||||
GradlePrinter.GradleDsl.GROOVY -> {
|
||||
+"tasks.withType($taskClass)"
|
||||
}
|
||||
GradlePrinter.GradleDsl.KOTLIN -> {
|
||||
+"tasks.withType<$taskClass>()"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class GradleConfigureTaskIR(
|
||||
val taskAccess: GradleTaskAccessIR,
|
||||
val dependsOn: List<BuildSystemIR> = emptyList(),
|
||||
|
||||
+10
-1
@@ -20,7 +20,7 @@ interface MavenIR : BuildSystemIR {
|
||||
|
||||
data class PluginRepositoryMavenIR(
|
||||
val repository: Repository
|
||||
): MavenIR {
|
||||
) : MavenIR {
|
||||
override fun MavenPrinter.renderMaven() {
|
||||
node("pluginRepository") {
|
||||
singleLineNode("id") { +repository.idForMaven }
|
||||
@@ -29,4 +29,13 @@ data class PluginRepositoryMavenIR(
|
||||
}
|
||||
}
|
||||
|
||||
data class MavenPropertyIR(
|
||||
val name: String,
|
||||
val value: String
|
||||
) : MavenIR {
|
||||
override fun MavenPrinter.renderMaven() {
|
||||
singleLineNode(name) { +value }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-1
@@ -46,7 +46,10 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
}
|
||||
|
||||
|
||||
override fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module) =
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
) =
|
||||
buildList<BuildSystemIR> {
|
||||
+GradleOnlyPluginByNameIR("com.android.application")
|
||||
|
||||
|
||||
+5
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystemPluginIR
|
||||
@@ -34,7 +35,10 @@ object JsSingleplatformModuleConfigurator : JSConfigurator, ModuleConfiguratorWi
|
||||
version = configurationData.kotlinVersion
|
||||
)
|
||||
|
||||
override fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> = buildList {
|
||||
+RawGradleIR {
|
||||
+"kotlin.target.browser { }"
|
||||
}
|
||||
|
||||
+19
-16
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleConfigurationData
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.correspondingStdlib
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
|
||||
@@ -190,7 +189,10 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
val suggestedModuleName: String? get() = null
|
||||
val canContainSubModules: Boolean get() = false
|
||||
|
||||
fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
fun ValuesReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
@@ -232,19 +234,20 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
val BY_ID = ALL.associateBy(ModuleConfigurator::id)
|
||||
val BY_MODULE_KIND = ALL.groupBy(ModuleConfigurator::moduleKind)
|
||||
|
||||
fun getParser(moduleIdentificator: Identificator): Parser<ModuleConfigurator> = mapParser { map, path ->
|
||||
val (id) = map.parseValue<String>(path, "name")
|
||||
val (configurator) = BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
||||
val (settingsWithValues) = configurator.settings.mapComputeM { setting ->
|
||||
val (settingValue) = map[setting.path].toResult { ParseError("No value was found for a key `$path.${setting.path}`") }
|
||||
val reference = withSettingsOf(moduleIdentificator, configurator) { setting.reference }
|
||||
setting.type.parse(this, settingValue, setting.path).map { reference to it }
|
||||
}.sequence()
|
||||
updateState { it.withSettings(settingsWithValues) }
|
||||
configurator
|
||||
} or valueParserM { value, path ->
|
||||
val (id) = value.parseAs<String>(path)
|
||||
BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
||||
}
|
||||
fun getParser(moduleIdentificator: Identificator): Parser<ModuleConfigurator> =
|
||||
valueParserM { value, path ->
|
||||
val (id) = value.parseAs<String>(path)
|
||||
BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
||||
} or mapParser { map, path ->
|
||||
val (id) = map.parseValue<String>(path, "name")
|
||||
val (configurator) = BY_ID[id].toResult { ConfiguratorNotFoundError(id) }
|
||||
val (settingsWithValues) = configurator.settings.mapComputeM { setting ->
|
||||
val (settingValue) = map[setting.path].toResult { ParseError("No value was found for a key `$path.${setting.path}`") }
|
||||
val reference = withSettingsOf(moduleIdentificator, configurator) { setting.reference }
|
||||
setting.type.parse(this, settingValue, setting.path).map { reference to it }
|
||||
}.sequence()
|
||||
updateState { it.withSettings(settingsWithValues) }
|
||||
configurator
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.CreateGradleValueIR
|
||||
@@ -33,7 +34,7 @@ object NativeForCurrentSystemTarget : NativeTargetConfigurator, SingleCoexistenc
|
||||
override val text = "For Current System"
|
||||
|
||||
|
||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> {
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> {
|
||||
val moduleName = module.name
|
||||
val variableName = "${moduleName}Target"
|
||||
|
||||
@@ -73,7 +74,10 @@ object NativeForCurrentSystemTarget : NativeTargetConfigurator, SingleCoexistenc
|
||||
}
|
||||
}
|
||||
|
||||
override fun createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> = buildList {
|
||||
if (configurationData.buildSystemType == BuildSystemType.GradleGroovyDsl) {
|
||||
+GradleImportIR("org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests")
|
||||
}
|
||||
|
||||
+25
-8
@@ -1,10 +1,14 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.RawGradleIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.multiplatform.DefaultTargetConfigurationIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.multiplatform.TargetAccessIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.buildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.isGradle
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleSubType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
@@ -16,8 +20,8 @@ interface TargetConfigurator : ModuleConfiguratorWithModuleType {
|
||||
|
||||
fun canCoexistsWith(other: List<TargetConfigurator>): Boolean = true
|
||||
|
||||
fun createTargetIrs(module: Module): List<BuildSystemIR>
|
||||
fun createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
||||
fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR>
|
||||
fun ValuesReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
||||
}
|
||||
|
||||
abstract class TargetConfiguratorWithTests : ModuleConfiguratorWithTests(), TargetConfigurator
|
||||
@@ -36,7 +40,7 @@ interface SimpleTargetConfigurator : TargetConfigurator, SingleCoexistenceTarget
|
||||
override val suggestedModuleName: String? get() = moduleSubType.name
|
||||
|
||||
|
||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(moduleSubType),
|
||||
createInnerTargetIrs(module)
|
||||
@@ -60,7 +64,7 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator, ModuleConfiguratorWit
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
|
||||
|
||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(ModuleSubType.js),
|
||||
buildList {
|
||||
@@ -78,7 +82,7 @@ object JsNodeTargetConfigurator : JsTargetConfigurator {
|
||||
override val suggestedModuleName = "nodeJs"
|
||||
|
||||
|
||||
override fun createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(ModuleSubType.js),
|
||||
buildList {
|
||||
@@ -96,14 +100,27 @@ object CommonTargetConfigurator : TargetConfiguratorWithTests(), SimpleTargetCon
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.COMMON
|
||||
}
|
||||
|
||||
object JvmTargetConfigurator : TargetConfiguratorWithTests(),
|
||||
object JvmTargetConfigurator : JvmModuleConfigurator(),
|
||||
TargetConfigurator,
|
||||
SimpleTargetConfigurator,
|
||||
JvmModuleConfigurator,
|
||||
SingleCoexistenceTargetConfigurator {
|
||||
override val moduleSubType = ModuleSubType.jvm
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||
|
||||
override fun ValuesReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
val targetVersionValue = withSettingsOf(module) { targetJvmVersion.reference.settingValue.value }
|
||||
when {
|
||||
buildSystemType.isGradle -> {
|
||||
+GradleSectionIR(
|
||||
"compilations.all",
|
||||
BodyIR(
|
||||
GradleAssignmentIR("kotlinOptions.jvmTarget", GradleStringConstIR(targetVersionValue))
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object AndroidTargetConfigurator : TargetConfigurator,
|
||||
|
||||
+53
-3
@@ -1,13 +1,43 @@
|
||||
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.safeAs
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystemPluginIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
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
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.maven.MavenPropertyIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.isGradle
|
||||
|
||||
abstract class JvmModuleConfigurator : ModuleConfiguratorWithTests() {
|
||||
val targetJvmVersion by enumSetting<TargetJvmVersion>("Target JVM Version", GenerationPhase.PROJECT_GENERATION) {
|
||||
defaultValue = TargetJvmVersion.JVM_1_8
|
||||
}
|
||||
override val settings: List<ModuleConfiguratorSetting<*, *>>
|
||||
get() = super.settings + targetJvmVersion
|
||||
}
|
||||
|
||||
enum class TargetJvmVersion(val value: String) : DisplayableSettingItem {
|
||||
JVM_1_6("1.6"),
|
||||
JVM_1_8("1.8"),
|
||||
JVM_9("9"),
|
||||
JVM_10("10"),
|
||||
JVM_11("11"),
|
||||
JVM_12("12"),
|
||||
JVM_13("13");
|
||||
|
||||
override val text: String
|
||||
get() = value
|
||||
}
|
||||
|
||||
interface JvmModuleConfigurator : ModuleConfigurator
|
||||
interface AndroidModuleConfigurator : ModuleConfigurator
|
||||
|
||||
interface ModuleConfiguratorWithModuleType : ModuleConfigurator {
|
||||
@@ -36,9 +66,8 @@ interface SinglePlatformModuleConfigurator : ModuleConfigurator {
|
||||
override val moduleKind get() = ModuleKind.singleplatformJvm
|
||||
}
|
||||
|
||||
object JvmSinglePlatformModuleConfigurator : ModuleConfiguratorWithTests(),
|
||||
object JvmSinglePlatformModuleConfigurator : JvmModuleConfigurator(),
|
||||
SinglePlatformModuleConfigurator,
|
||||
JvmModuleConfigurator,
|
||||
ModuleConfiguratorWithModuleType {
|
||||
override val moduleType get() = ModuleType.jvm
|
||||
override val suggestedModuleName = "jvm"
|
||||
@@ -53,6 +82,27 @@ object JvmSinglePlatformModuleConfigurator : ModuleConfiguratorWithTests(),
|
||||
KotlinBuildSystemPluginIR.Type.jvm,
|
||||
version = configurationData.kotlinVersion
|
||||
)
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
buildList {
|
||||
+GradleImportIR("org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
|
||||
val targetVersionValue = withSettingsOf(module) { targetJvmVersion.reference.settingValue.value }
|
||||
when {
|
||||
configurationData.buildSystemType.isGradle -> {
|
||||
+GradleConfigureTaskIR(
|
||||
GradleByClassTasksAccessIR("KotlinCompile"),
|
||||
irs = listOf(
|
||||
GradleAssignmentIR("kotlinOptions.jvmTarget", GradleStringConstIR(targetVersionValue))
|
||||
)
|
||||
)
|
||||
}
|
||||
configurationData.buildSystemType == BuildSystemType.Maven -> {
|
||||
+MavenPropertyIR("kotlin.compiler.jvmTarget", targetVersionValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -156,7 +156,7 @@ class ModulesToIRsConverter(
|
||||
val modulePath = calculatePathForModule(module, state.parentPath)
|
||||
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
val targetIrs = module.subModules.flatMap { subModule ->
|
||||
(subModule.configurator as TargetConfigurator).createTargetIrs(subModule)
|
||||
with(subModule.configurator as TargetConfigurator) { createTargetIrs(subModule) }
|
||||
}
|
||||
|
||||
val targetModuleIrs = module.subModules.map { target ->
|
||||
@@ -223,7 +223,7 @@ class ModulesToIRsConverter(
|
||||
runArbitraryTask(data, module, modulePath)
|
||||
}
|
||||
|
||||
private fun createBuildFileIRs(
|
||||
private fun ValuesReadingContext.createBuildFileIRs(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
) = buildList<BuildSystemIR> {
|
||||
@@ -239,7 +239,7 @@ class ModulesToIRsConverter(
|
||||
}
|
||||
}
|
||||
addIfNotNull(kotlinPlugin)
|
||||
+module.configurator.createBuildFileIRs(data, module)
|
||||
+with(module.configurator) { createBuildFileIRs(data, module) }
|
||||
}
|
||||
|
||||
private fun SourcesetDependency.toIR(type: DependencyType): DependencyIR = with(data) {
|
||||
|
||||
+5
-2
@@ -10,11 +10,14 @@ import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.Template
|
||||
|
||||
@Suppress("EnumEntryName")
|
||||
enum class ModuleKind {
|
||||
enum class ModuleKind : DisplayableSettingItem {
|
||||
multiplatform,
|
||||
target,
|
||||
singleplatformJvm,
|
||||
singleplatformJs,
|
||||
singleplatformJs, ;
|
||||
|
||||
override val text: String
|
||||
get() = name
|
||||
}
|
||||
|
||||
// TODO separate to classes
|
||||
|
||||
+4
-1
@@ -59,9 +59,12 @@ class Sourceset(
|
||||
}
|
||||
|
||||
@Suppress("EnumEntryName")
|
||||
enum class SourcesetType {
|
||||
enum class SourcesetType: DisplayableSettingItem {
|
||||
main, test;
|
||||
|
||||
override val text: String
|
||||
get() = name
|
||||
|
||||
companion object {
|
||||
val ALL = values().toSet()
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ class Version private constructor(internal val mavenVersion: ArtifactVersion) :
|
||||
val parser: Parser<Version> = valueParser { value, path ->
|
||||
val (stringVersion) = value.parseAs<String>(path)
|
||||
safe { fromString(stringVersion) }.mapFailure {
|
||||
listOf(ParseError("Bad version format for setting `$path`"))
|
||||
ParseError("Bad version format for setting `$path`")
|
||||
}.get()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ class SimpleJsClientTemplate : Template() {
|
||||
+interceptTemplate(KtorServerTemplate()) {
|
||||
applicableIf { buildFileIR ->
|
||||
val tasks = buildFileIR.irsOfTypeOrNull<GradleConfigureTaskIR>() ?: return@applicableIf false
|
||||
tasks.none { it.taskAccess.name.endsWith("Jar") }
|
||||
tasks.none { it.taskAccess.safeAs<GradleByNameTaskAccessIR>()?.name?.endsWith("Jar") == true }
|
||||
}
|
||||
|
||||
interceptAtPoint(template.routes) { value ->
|
||||
|
||||
Reference in New Issue
Block a user