NoArg: Do not invoke initializers by default. Require "invokeInitializers" option to be set explicitly (KT-18667, KT-18668)

This commit is contained in:
Yan Zhulanow
2017-07-04 17:18:41 +03:00
committed by Yan Zhulanow
parent a983137978
commit b99007961f
14 changed files with 160 additions and 9 deletions
@@ -165,6 +165,13 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
}
}
@Test
fun testNoArgKt18668() {
Project("noArgKt18668", GRADLE_VERSION).build("build") {
assertSuccessful()
}
}
@Test
fun testSamWithReceiverSimple() {
Project("samWithReceiverSimple", GRADLE_VERSION).build("build") {
@@ -0,0 +1,28 @@
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
}
}
apply plugin: "kotlin"
apply plugin: "kotlin-noarg"
repositories {
mavenLocal()
}
noArg {
annotation("test.NoArg")
}
sourceSets {
main.kotlin.srcDir 'src'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -0,0 +1,12 @@
package test
annotation class NoArg
@NoArg
class AuthenticationConfiguration(tokenExpiresIn: Long) {
var tokenExpiryDate: String
init {
tokenExpiryDate = tokenExpiresIn.toString()
}
}
@@ -20,6 +20,8 @@ open class NoArgExtension {
internal val myAnnotations = mutableListOf<String>()
internal val myPresets = mutableListOf<String>()
open var invokeInitializers: Boolean = false
open fun annotation(fqName: String) {
myAnnotations.add(fqName)
}
@@ -71,6 +71,7 @@ class NoArgKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
private val ANNOTATION_ARG_NAME = "annotation"
private val PRESET_ARG_NAME = "preset"
private val INVOKE_INITIALIZERS_ARG_NAME = "invokeInitializers"
}
override fun isApplicable(project: Project, task: AbstractCompile) = NoArgGradleSubplugin.isEnabled(project)
@@ -96,6 +97,10 @@ class NoArgKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
options += SubpluginOption(PRESET_ARG_NAME, preset)
}
if (noArgExtension.invokeInitializers) {
options += SubpluginOption(INVOKE_INITIALIZERS_ARG_NAME, "true")
}
return options
}