From 38d836dece5c42fb2e913b6c7e8ebb3ca6bd6251 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Tue, 25 Dec 2018 21:54:46 +0300 Subject: [PATCH] Build: Don't instrument NotNulls during form instrumentation --- buildSrc/src/main/kotlin/instrument.kt | 13 +++++++++---- buildSrc/src/main/kotlin/instrument.kt.181 | 13 +++++++++---- idea/build.gradle.kts | 2 +- idea/idea-gradle-native/build.gradle.kts | 2 +- idea/idea-gradle/build.gradle.kts | 2 +- idea/idea-jvm/build.gradle.kts | 2 +- idea/idea-native/build.gradle.kts | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/kotlin/instrument.kt b/buildSrc/src/main/kotlin/instrument.kt index 17009b71035..fc49ab87821 100644 --- a/buildSrc/src/main/kotlin/instrument.kt +++ b/buildSrc/src/main/kotlin/instrument.kt @@ -28,7 +28,7 @@ import org.gradle.api.tasks.compile.AbstractCompile import org.gradle.kotlin.dsl.* import java.io.File -fun Project.configureInstrumentation() { +fun Project.configureFormInstrumentation() { plugins.matching { it::class.java.canonicalName.startsWith("org.jetbrains.kotlin.gradle.plugin") }.all { // When we change the output classes directory, Gradle will automatically configure // the test compile tasks to use the instrumented classes. Normally this is fine, @@ -100,6 +100,9 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { @Input var originalClassesDirs: FileCollection? = null + @get:Input + var instrumentNotNull: Boolean = false + @get:InputFiles val sourceDirs: FileCollection get() = project.files(sourceSet!!.allSource.srcDirs.filter { !sourceSet!!.resources.contains(it) && it.exists() }) @@ -129,7 +132,10 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { } logger.info("Compiling forms and instrumenting code with nullability preconditions") - val instrumentNotNull = prepareNotNullInstrumenting(classpath.asPath) + if (instrumentNotNull) { + prepareNotNullInstrumenting(classpath.asPath) + } + instrumentCode(sourceDirs, instrumentNotNull) } @@ -140,7 +146,7 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { } } - private fun prepareNotNullInstrumenting(classpath: String): Boolean { + private fun prepareNotNullInstrumenting(classpath: String) { ant.withGroovyBuilder { "typedef"( "name" to "skip", @@ -149,7 +155,6 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { "classname" to FILTER_ANNOTATION_REGEXP_CLASS ) } - return true } private fun instrumentCode(srcDirs: FileCollection, instrumentNotNull: Boolean) { diff --git a/buildSrc/src/main/kotlin/instrument.kt.181 b/buildSrc/src/main/kotlin/instrument.kt.181 index 29275b96620..6af034f266f 100644 --- a/buildSrc/src/main/kotlin/instrument.kt.181 +++ b/buildSrc/src/main/kotlin/instrument.kt.181 @@ -28,7 +28,7 @@ import org.gradle.api.tasks.compile.AbstractCompile import org.gradle.kotlin.dsl.* import java.io.File -fun Project.configureInstrumentation() { +fun Project.configureFormInstrumentation() { plugins.matching { it::class.java.canonicalName.startsWith("org.jetbrains.kotlin.gradle.plugin") }.all { // When we change the output classes directory, Gradle will automatically configure // the test compile tasks to use the instrumented classes. Normally this is fine, @@ -100,6 +100,9 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { @Input var originalClassesDirs: FileCollection? = null + @get:Input + var instrumentNotNull: Boolean = false + @get:InputFiles val sourceDirs: FileCollection get() = project.files(sourceSet!!.allSource.srcDirs.filter { !sourceSet!!.resources.contains(it) && it.exists() }) @@ -129,7 +132,10 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { } logger.info("Compiling forms and instrumenting code with nullability preconditions") - val instrumentNotNull = prepareNotNullInstrumenting(classpath.asPath) + if (instrumentNotNull) { + prepareNotNullInstrumenting(classpath.asPath) + } + instrumentCode(sourceDirs, instrumentNotNull) } @@ -140,7 +146,7 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { } } - private fun prepareNotNullInstrumenting(classpath: String): Boolean { + private fun prepareNotNullInstrumenting(classpath: String) { ant.withGroovyBuilder { "typedef"( "name" to "skip", @@ -149,7 +155,6 @@ open class IntelliJInstrumentCodeTask : ConventionTask() { "classname" to FILTER_ANNOTATION_REGEXP_CLASS ) } - return true } private fun instrumentCode(srcDirs: FileCollection, instrumentNotNull: Boolean) { diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index 413b5ea9faf..5e198a552fa 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -205,5 +205,5 @@ projectTest(taskName = "performanceTest") { testsJar {} classesDirsArtifact() -configureInstrumentation() +configureFormInstrumentation() diff --git a/idea/idea-gradle-native/build.gradle.kts b/idea/idea-gradle-native/build.gradle.kts index d4ad5af2536..ff9ce203bde 100644 --- a/idea/idea-gradle-native/build.gradle.kts +++ b/idea/idea-gradle-native/build.gradle.kts @@ -30,4 +30,4 @@ sourceSets { "test" { none() } } -configureInstrumentation() +configureFormInstrumentation() diff --git a/idea/idea-gradle/build.gradle.kts b/idea/idea-gradle/build.gradle.kts index 1ee11069553..fcc6229929b 100644 --- a/idea/idea-gradle/build.gradle.kts +++ b/idea/idea-gradle/build.gradle.kts @@ -74,4 +74,4 @@ projectTest { useAndroidSdk() } -configureInstrumentation() +configureFormInstrumentation() diff --git a/idea/idea-jvm/build.gradle.kts b/idea/idea-jvm/build.gradle.kts index ca98cb6a9d9..36d906d5faf 100644 --- a/idea/idea-jvm/build.gradle.kts +++ b/idea/idea-jvm/build.gradle.kts @@ -28,7 +28,7 @@ sourceSets { "test" { none() } } -configureInstrumentation() +configureFormInstrumentation() runtimeJar { archiveName = "jvm-ide.jar" diff --git a/idea/idea-native/build.gradle.kts b/idea/idea-native/build.gradle.kts index 896a7525970..df9c08f75b0 100644 --- a/idea/idea-native/build.gradle.kts +++ b/idea/idea-native/build.gradle.kts @@ -17,7 +17,7 @@ sourceSets { "test" { none() } } -configureInstrumentation() +configureFormInstrumentation() runtimeJar { archiveName = "native-ide.jar"