Test that kotlin gradle options are up to date
#KT-14317 fixed
This commit is contained in:
@@ -39,14 +39,14 @@ interface AdditionalGradleProperties {
|
||||
object EmptyList : DefaultValues("emptyList()")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()->Unit)->Unit) {
|
||||
val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/main/kotlin")
|
||||
val additionalGradleOptions = gradleOptions<AdditionalGradleProperties>()
|
||||
|
||||
// generate jvm interface
|
||||
val jvmInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions")
|
||||
val optionsFromK2JVMCompilerArguments = gradleOptions<K2JVMCompilerArguments>()
|
||||
File(srcDir, jvmInterfaceFqName).usePrinter {
|
||||
withPrinterToFile(File(srcDir, jvmInterfaceFqName)) {
|
||||
generateInterface(jvmInterfaceFqName,
|
||||
optionsFromK2JVMCompilerArguments + additionalGradleOptions)
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fun main(args: Array<String>) {
|
||||
// generate jvm impl
|
||||
val k2JvmCompilerArgumentsFqName = FqName(K2JVMCompilerArguments::class.qualifiedName!!)
|
||||
val jvmImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsBase")
|
||||
File(srcDir, jvmImplFqName).usePrinter {
|
||||
withPrinterToFile(File(srcDir, jvmImplFqName)) {
|
||||
generateImpl(jvmImplFqName,
|
||||
jvmInterfaceFqName,
|
||||
k2JvmCompilerArgumentsFqName,
|
||||
@@ -64,7 +64,7 @@ fun main(args: Array<String>) {
|
||||
// generate js interface
|
||||
val jsInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions")
|
||||
val optionsFromK2JSCompilerArguments = gradleOptions<K2JSCompilerArguments>()
|
||||
File(srcDir, jsInterfaceFqName).usePrinter {
|
||||
withPrinterToFile(File(srcDir, jsInterfaceFqName)) {
|
||||
generateInterface(jsInterfaceFqName,
|
||||
optionsFromK2JSCompilerArguments +
|
||||
additionalGradleOptions)
|
||||
@@ -72,7 +72,7 @@ fun main(args: Array<String>) {
|
||||
|
||||
val k2JsCompilerArgumentsFqName = FqName(K2JSCompilerArguments::class.qualifiedName!!)
|
||||
val jsImplFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsBase")
|
||||
File(srcDir, jsImplFqName).usePrinter {
|
||||
withPrinterToFile(File(srcDir, jsImplFqName)) {
|
||||
generateImpl(jsImplFqName,
|
||||
jsInterfaceFqName,
|
||||
k2JsCompilerArgumentsFqName,
|
||||
@@ -80,6 +80,21 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fun getPrinter(file: File, fn: Printer.()->Unit) {
|
||||
if (!file.exists()) {
|
||||
file.parentFile.mkdirs()
|
||||
file.createNewFile()
|
||||
}
|
||||
PrintStream(file.outputStream()).use {
|
||||
val printer = Printer(it)
|
||||
printer.fn()
|
||||
}
|
||||
}
|
||||
|
||||
generateKotlinGradleOptions(::getPrinter)
|
||||
}
|
||||
|
||||
private inline fun <reified T : Any> gradleOptions(): List<KProperty1<T, *>> =
|
||||
T::class.memberProperties.filter { it.findAnnotation<GradleOption>() != null }.sortedBy { it.name }
|
||||
|
||||
@@ -88,17 +103,6 @@ private fun File(baseDir: File, fqName: FqName): File {
|
||||
return File(baseDir, fileRelativePath)
|
||||
}
|
||||
|
||||
private inline fun File.usePrinter(fn: Printer.()->Unit) {
|
||||
if (!exists()) {
|
||||
parentFile.mkdirs()
|
||||
createNewFile()
|
||||
}
|
||||
PrintStream(outputStream()).use {
|
||||
val printer = Printer(it)
|
||||
printer.fn()
|
||||
}
|
||||
}
|
||||
|
||||
private fun Printer.generateInterface(type: FqName, properties: List<KProperty1<*, *>>) {
|
||||
generateDeclaration("interface", type) {
|
||||
for (property in properties) {
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-20166 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.generators.arguments.test
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.generators.arguments.generateKotlinGradleOptions
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.*
|
||||
|
||||
class GenerateKotlinGradleOptionsTest : UsefulTestCase() {
|
||||
fun testKotlinGradleOptionsAreUpToDate() {
|
||||
fun getPrinter(file: File, fn: Printer.()->Unit) {
|
||||
val bytesOut = ByteArrayOutputStream()
|
||||
|
||||
PrintStream(bytesOut).use {
|
||||
val printer = Printer(it)
|
||||
printer.fn()
|
||||
}
|
||||
|
||||
val upToDateContent = bytesOut.toString()
|
||||
UsefulTestCase.assertSameLinesWithFile(file.absolutePath, upToDateContent)
|
||||
}
|
||||
|
||||
generateKotlinGradleOptions(::getPrinter)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user