Minor: reformat + clean warnings in org.jetbrains.kotlin.generators.arguments.test

This commit is contained in:
Nikolay Krasko
2021-12-13 13:38:00 +03:00
committed by teamcity
parent e733aa21d5
commit 00f0978b1d
2 changed files with 89 additions and 68 deletions
@@ -39,7 +39,7 @@ interface AdditionalGradleProperties {
object EmptyList : DefaultValues("emptyList()") object EmptyList : DefaultValues("emptyList()")
} }
fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()->Unit)->Unit) { fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() -> Unit) -> Unit) {
val apiSrcDir = File("libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin") val apiSrcDir = File("libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin")
val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/main/kotlin") val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/main/kotlin")
@@ -47,9 +47,11 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions") val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
val commonOptions = gradleOptions<CommonToolArguments>() val commonOptions = gradleOptions<CommonToolArguments>()
val additionalOptions = gradleOptions<AdditionalGradleProperties>() val additionalOptions = gradleOptions<AdditionalGradleProperties>()
withPrinterToFile(File(apiSrcDir, commonInterfaceFqName)) { withPrinterToFile(file(apiSrcDir, commonInterfaceFqName)) {
generateInterface(commonInterfaceFqName, generateInterface(
commonOptions + additionalOptions) commonInterfaceFqName,
commonOptions + additionalOptions
)
} }
println("### Attributes common for JVM, JS, and JS DCE\n") println("### Attributes common for JVM, JS, and JS DCE\n")
@@ -57,10 +59,12 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
val commonCompilerInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions") val commonCompilerInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions")
val commonCompilerOptions = gradleOptions<CommonCompilerArguments>() val commonCompilerOptions = gradleOptions<CommonCompilerArguments>()
withPrinterToFile(File(apiSrcDir, commonCompilerInterfaceFqName)) { withPrinterToFile(file(apiSrcDir, commonCompilerInterfaceFqName)) {
generateInterface(commonCompilerInterfaceFqName, generateInterface(
commonCompilerInterfaceFqName,
commonCompilerOptions, commonCompilerOptions,
parentType = commonInterfaceFqName) parentType = commonInterfaceFqName
)
} }
println("\n### Attributes common for JVM and JS\n") println("\n### Attributes common for JVM and JS\n")
@@ -69,20 +73,24 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
// generate jvm interface // generate jvm interface
val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions") val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions")
val jvmOptions = gradleOptions<K2JVMCompilerArguments>() val jvmOptions = gradleOptions<K2JVMCompilerArguments>()
withPrinterToFile(File(srcDir, jvmInterfaceFqName)) { withPrinterToFile(file(srcDir, jvmInterfaceFqName)) {
generateInterface(jvmInterfaceFqName, generateInterface(
jvmInterfaceFqName,
jvmOptions, jvmOptions,
parentType = commonCompilerInterfaceFqName) parentType = commonCompilerInterfaceFqName
)
} }
// generate jvm impl // generate jvm impl
val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!) val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!)
val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase") val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase")
withPrinterToFile(File(srcDir, jvmImplFqName)) { withPrinterToFile(file(srcDir, jvmImplFqName)) {
generateImpl(jvmImplFqName, generateImpl(
jvmImplFqName,
jvmInterfaceFqName, jvmInterfaceFqName,
k2JvmCompilerArgumentsFqName, k2JvmCompilerArgumentsFqName,
commonOptions + commonCompilerOptions + jvmOptions) commonOptions + commonCompilerOptions + jvmOptions
)
} }
println("\n### Attributes specific for JVM\n") println("\n### Attributes specific for JVM\n")
@@ -91,19 +99,23 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
// generate js interface // generate js interface
val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions") val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions")
val jsOptions = gradleOptions<K2JSCompilerArguments>() val jsOptions = gradleOptions<K2JSCompilerArguments>()
withPrinterToFile(File(srcDir, jsInterfaceFqName)) { withPrinterToFile(file(srcDir, jsInterfaceFqName)) {
generateInterface(jsInterfaceFqName, generateInterface(
jsInterfaceFqName,
jsOptions, jsOptions,
parentType = commonCompilerInterfaceFqName) parentType = commonCompilerInterfaceFqName
)
} }
val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!) val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!)
val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase") val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase")
withPrinterToFile(File(srcDir, jsImplFqName)) { withPrinterToFile(file(srcDir, jsImplFqName)) {
generateImpl(jsImplFqName, generateImpl(
jsImplFqName,
jsInterfaceFqName, jsInterfaceFqName,
k2JsCompilerArgumentsFqName, k2JsCompilerArgumentsFqName,
commonOptions + commonCompilerOptions + jsOptions) commonOptions + commonCompilerOptions + jsOptions
)
} }
println("\n### Attributes specific for JS\n") println("\n### Attributes specific for JS\n")
@@ -112,43 +124,51 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
// generate JS DCE interface and implementation // generate JS DCE interface and implementation
val jsDceInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions") val jsDceInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptions")
val jsDceOptions = gradleOptions<K2JSDceArguments>() val jsDceOptions = gradleOptions<K2JSDceArguments>()
withPrinterToFile(File(srcDir, jsDceInterfaceFqName)) { withPrinterToFile(file(srcDir, jsDceInterfaceFqName)) {
generateInterface(jsDceInterfaceFqName, generateInterface(
jsDceInterfaceFqName,
jsDceOptions, jsDceOptions,
parentType = commonInterfaceFqName) parentType = commonInterfaceFqName
)
} }
val k2JsDceArgumentsFqName = FqName(K2JSDceArguments::class.qualifiedName!!) val k2JsDceArgumentsFqName = FqName(K2JSDceArguments::class.qualifiedName!!)
val jsDceImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptionsBase") val jsDceImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsDceOptionsBase")
withPrinterToFile(File(srcDir, jsDceImplFqName)) { withPrinterToFile(file(srcDir, jsDceImplFqName)) {
generateImpl(jsDceImplFqName, generateImpl(
jsDceImplFqName,
jsDceInterfaceFqName, jsDceInterfaceFqName,
k2JsDceArgumentsFqName, k2JsDceArgumentsFqName,
commonOptions + jsDceOptions) commonOptions + jsDceOptions
)
} }
// generate multiplatform common interface and implementation // generate multiplatform common interface and implementation
val multiplatformCommonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonOptions") val multiplatformCommonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonOptions")
val multiplatformCommonOptions = gradleOptions<K2MetadataCompilerArguments>() val multiplatformCommonOptions = gradleOptions<K2MetadataCompilerArguments>()
withPrinterToFile(File(srcDir, multiplatformCommonInterfaceFqName)) { withPrinterToFile(file(srcDir, multiplatformCommonInterfaceFqName)) {
generateInterface(multiplatformCommonInterfaceFqName, generateInterface(
multiplatformCommonInterfaceFqName,
multiplatformCommonOptions, multiplatformCommonOptions,
parentType = commonCompilerInterfaceFqName) parentType = commonCompilerInterfaceFqName
)
} }
val k2metadataCompilerArgumentsFqName = FqName(K2MetadataCompilerArguments::class.qualifiedName!!) val k2metadataCompilerArgumentsFqName = FqName(K2MetadataCompilerArguments::class.qualifiedName!!)
val multiplatformCommonImplFqName = FqName(multiplatformCommonInterfaceFqName.asString() + "Base") val multiplatformCommonImplFqName = FqName(multiplatformCommonInterfaceFqName.asString() + "Base")
withPrinterToFile(File(srcDir, multiplatformCommonImplFqName)) { withPrinterToFile(file(srcDir, multiplatformCommonImplFqName)) {
generateImpl(multiplatformCommonImplFqName, generateImpl(
multiplatformCommonImplFqName,
multiplatformCommonInterfaceFqName, multiplatformCommonInterfaceFqName,
k2metadataCompilerArgumentsFqName, k2metadataCompilerArgumentsFqName,
commonOptions + commonCompilerOptions + multiplatformCommonOptions) commonOptions + commonCompilerOptions + multiplatformCommonOptions
)
} }
} }
fun main() { fun main() {
fun getPrinter(file: File, fn: Printer.()->Unit) { fun getPrinter(file: File, fn: Printer.() -> Unit) {
if (!file.exists()) { if (!file.exists()) {
file.parentFile.mkdirs() file.parentFile.mkdirs()
file.createNewFile() file.createNewFile()
@@ -172,7 +192,7 @@ private inline fun <reified T : Any> List<KProperty1<T, *>>.filterToBeDeleted()
private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> = private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> =
T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != null }.filterToBeDeleted().sortedBy { it.name } T::class.declaredMemberProperties.filter { it.findAnnotation<GradleOption>() != null }.filterToBeDeleted().sortedBy { it.name }
private fun File(baseDir: File, fqName: FqName): File { private fun file(baseDir: File, fqName: FqName): File {
val fileRelativePath = fqName.asString().replace(".", "/") + ".kt" val fileRelativePath = fqName.asString().replace(".", "/") + ".kt"
return File(baseDir, fileRelativePath) return File(baseDir, fileRelativePath)
} }
@@ -244,7 +264,7 @@ private fun Printer.generateDeclaration(
modifiers: String, modifiers: String,
type: FqName, type: FqName,
afterType: String? = null, afterType: String? = null,
generateBody: Printer.()->Unit generateBody: Printer.() -> Unit
) { ) {
println("// DO NOT EDIT MANUALLY!") println("// DO NOT EDIT MANUALLY!")
println("// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt") println("// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt")
@@ -288,7 +308,7 @@ private fun Printer.generateDoc(property: KProperty1<*, *>) {
println(" */") println(" */")
} }
private inline fun Printer.withIndent(fn: Printer.()->Unit) { private inline fun Printer.withIndent(fn: Printer.() -> Unit) {
pushIndent() pushIndent()
fn() fn()
popIndent() popIndent()
@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("PackageDirectoryMismatch")
package org.jetbrains.kotlin.generators.arguments.test package org.jetbrains.kotlin.generators.arguments.test
import junit.framework.TestCase import junit.framework.TestCase
@@ -26,7 +27,7 @@ import java.io.PrintStream
class GenerateKotlinGradleOptionsTest : TestCase() { class GenerateKotlinGradleOptionsTest : TestCase() {
fun testKotlinGradleOptionsAreUpToDate() { fun testKotlinGradleOptionsAreUpToDate() {
fun getPrinter(file: File, fn: Printer.()->Unit) { fun getPrinter(file: File, fn: Printer.() -> Unit) {
val bytesOut = ByteArrayOutputStream() val bytesOut = ByteArrayOutputStream()
PrintStream(bytesOut).use { PrintStream(bytesOut).use {