提交 17fc10a8 编写于 作者: Y Yaroslav Chernyshev

Mark obsolete Gradle JVM options as Deprecated with Error

Options `includeRuntime`, `noStdlib` and `noReflect` were affected
#Fixed KT-44361
上级 6eaf0a95
/*
* 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
......@@ -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)
......
......@@ -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 <reified T : Any> List<KProperty1<T, *>>.filterToBeDeleted() = filter { prop ->
prop.findAnnotation<DeprecatedOption>()
?.let { LanguageVersion.fromVersionString(it.removeAfter) }
?.let { it >= LanguageVersion.LATEST_STABLE }
?: true
}
private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> =
T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != null }.sortedBy { it.name }
T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != 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<KProperty1<
for (property in properties) {
println()
generateDoc(property)
generateOptionDeprecation(property)
generatePropertyDeclaration(property)
}
}
......@@ -248,6 +257,12 @@ private fun Printer.generatePropertyDeclaration(property: KProperty1<*, *>, modi
println("$modifiers var ${property.name}: $returnType")
}
private fun Printer.generateOptionDeprecation(property: KProperty1<*, *>) {
property.findAnnotation<DeprecatedOption>()
?.let { DeprecatedOptionAnnotator.generateOptionAnnotation(it) }
?.also { println(it) }
}
private fun Printer.generateDoc(property: KProperty1<*, *>) {
val description = property.findAnnotation<Argument>()!!.description
val possibleValues = property.gradleValues.possibleValues
......@@ -274,6 +289,8 @@ private fun generateMarkdown(properties: List<KProperty1<*, *>>) {
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<DeprecatedOption>()?.let { "__(Deprecated)__" })
.joinToString(" ")
val description = property.findAnnotation<Argument>()!!.description
val possibleValues = property.gradleValues.possibleValues
val defaultValue = when (property.gradleDefaultValue) {
......@@ -282,7 +299,7 @@ private fun generateMarkdown(properties: List<KProperty1<*, *>>) {
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 <reified T> KAnnotatedElement.findAnnotation(): T? =
annotations.filterIsInstance<T>().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
......@@ -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
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册