From 17fc10a8afedb7c0a281fe90d7ceb5f8b142148c Mon Sep 17 00:00:00 2001 From: Yaroslav Chernyshev Date: Tue, 9 Feb 2021 12:02:34 +0300 Subject: [PATCH] Mark obsolete Gradle JVM options as Deprecated with Error Options `includeRuntime`, `noStdlib` and `noReflect` were affected #Fixed KT-44361 --- .../cli/common/arguments/DeprecatedOption.kt | 13 ++++++++ .../arguments/K2JVMCompilerArguments.kt | 3 ++ .../arguments/GenerateGradleOptions.kt | 30 +++++++++++++++++-- .../kotlin/gradle/dsl/KotlinJvmOptions.kt | 3 ++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DeprecatedOption.kt diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DeprecatedOption.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DeprecatedOption.kt new file mode 100644 index 00000000000..51a0b8ad15f --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/DeprecatedOption.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2021 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.cli.common.arguments + +@Retention(AnnotationRetention.RUNTIME) +annotation class DeprecatedOption( + val message: String = "This option has no effect and will be removed in a future release.", + val removeAfter: String, + val level: DeprecationLevel +) \ No newline at end of file diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 9eb8a13aed3..2690da7b26f 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -25,6 +25,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { description = "List of directories and JAR/ZIP archives to search for user class files") var classpath: String? by NullableStringFreezableVar(null) + @DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR) @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-include-runtime", description = "Include Kotlin runtime into the resulting JAR") var includeRuntime: Boolean by FreezableVar(false) @@ -41,10 +42,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime into the classpath") var noJdk: Boolean by FreezableVar(false) + @DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-no-stdlib", description = "Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath") var noStdlib: Boolean by FreezableVar(false) + @DeprecatedOption(removeAfter = "1.5", level = DeprecationLevel.ERROR) @GradleOption(DefaultValues.BooleanTrueDefault::class) @Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath") var noReflect: Boolean by FreezableVar(false) diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt index 91f7264992f..00b34b829cc 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.generators.arguments import org.jetbrains.kotlin.cli.common.arguments.* +import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.utils.Printer import java.io.File @@ -159,8 +160,15 @@ fun main() { generateKotlinGradleOptions(::getPrinter) } +private inline fun List>.filterToBeDeleted() = filter { prop -> + prop.findAnnotation() + ?.let { LanguageVersion.fromVersionString(it.removeAfter) } + ?.let { it >= LanguageVersion.LATEST_STABLE } + ?: true +} + private inline fun gradleOptions(): List> = - T::class.declaredMemberProperties.filter { it.findAnnotation() != null }.sortedBy { it.name } + T::class.declaredMemberProperties.filter { it.findAnnotation() != null }.filterToBeDeleted().sortedBy { it.name } private fun File(baseDir: File, fqName: FqName): File { val fileRelativePath = fqName.asString().replace(".", "/") + ".kt" @@ -173,6 +181,7 @@ private fun Printer.generateInterface(type: FqName, properties: List, modi println("$modifiers var ${property.name}: $returnType") } +private fun Printer.generateOptionDeprecation(property: KProperty1<*, *>) { + property.findAnnotation() + ?.let { DeprecatedOptionAnnotator.generateOptionAnnotation(it) } + ?.also { println(it) } +} + private fun Printer.generateDoc(property: KProperty1<*, *>) { val description = property.findAnnotation()!!.description val possibleValues = property.gradleValues.possibleValues @@ -274,6 +289,8 @@ private fun generateMarkdown(properties: List>) { for (property in properties) { val name = property.name if (name == "includeRuntime") continue // This option has no effect in Gradle builds + val renderName = listOfNotNull("`$name`", property.findAnnotation()?.let { "__(Deprecated)__" }) + .joinToString(" ") val description = property.findAnnotation()!!.description val possibleValues = property.gradleValues.possibleValues val defaultValue = when (property.gradleDefaultValue) { @@ -282,7 +299,7 @@ private fun generateMarkdown(properties: List>) { else -> property.gradleDefaultValue } - println("| `$name` | $description | ${possibleValues.orEmpty().joinToString()} | $defaultValue |") + println("| $renderName | $description | ${possibleValues.orEmpty().joinToString()} | $defaultValue |") } } @@ -304,3 +321,12 @@ private val KProperty1<*, *>.gradleReturnType: String private inline fun KAnnotatedElement.findAnnotation(): T? = annotations.filterIsInstance().firstOrNull() + +object DeprecatedOptionAnnotator { + fun generateOptionAnnotation(annotation: DeprecatedOption): String { + val message = annotation.message.takeIf { it.isNotEmpty() }?.let { "message = \"$it\"" } + val level = "level = DeprecationLevel.${annotation.level.name}" + val arguments = listOfNotNull(message, level).joinToString() + return "@Deprecated($arguments)" + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt index d1b1e9eb076..850d925c275 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt @@ -8,6 +8,7 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption * Include Kotlin runtime into the resulting JAR * Default value: false */ + @Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR) var includeRuntime: kotlin.Boolean /** @@ -45,12 +46,14 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption * Don't automatically include Kotlin reflection into the classpath * Default value: true */ + @Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR) var noReflect: kotlin.Boolean /** * Don't automatically include the Kotlin/JVM stdlib and Kotlin reflection into the classpath * Default value: true */ + @Deprecated(message = "This option has no effect and will be removed in a future release.", level = DeprecationLevel.ERROR) var noStdlib: kotlin.Boolean /**