Add Gradle test for additional kapt arguments
This commit is contained in:
+6
-1
@@ -11,6 +11,7 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
|
|||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
val ANNOTATION_FQ_NAME = javaClass<ExampleAnnotation>().getCanonicalName()
|
val ANNOTATION_FQ_NAME = javaClass<ExampleAnnotation>().getCanonicalName()
|
||||||
|
val SUFFIX_OPTION = "suffix"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
|
||||||
@@ -19,9 +20,11 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
|
|||||||
val elementUtils = processingEnv.getElementUtils()
|
val elementUtils = processingEnv.getElementUtils()
|
||||||
val filer = processingEnv.getFiler()
|
val filer = processingEnv.getFiler()
|
||||||
|
|
||||||
|
val generatedFileSuffix = processingEnv.getOptions().get(SUFFIX_OPTION) ?: "Generated"
|
||||||
|
|
||||||
for (element in elements) {
|
for (element in elements) {
|
||||||
val packageName = elementUtils.getPackageOf(element).getQualifiedName().toString()
|
val packageName = elementUtils.getPackageOf(element).getQualifiedName().toString()
|
||||||
val className = element.getSimpleName().toString().capitalize() + "Generated"
|
val className = element.getSimpleName().toString().capitalize() + generatedFileSuffix
|
||||||
|
|
||||||
filer.createSourceFile(className).openWriter().use { with(it) {
|
filer.createSourceFile(className).openWriter().use { with(it) {
|
||||||
appendln("package $packageName;")
|
appendln("package $packageName;")
|
||||||
@@ -36,4 +39,6 @@ public class ExampleAnnotationProcessor : AbstractProcessor() {
|
|||||||
override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6
|
override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6
|
||||||
|
|
||||||
override fun getSupportedAnnotationTypes() = setOf(ANNOTATION_FQ_NAME)
|
override fun getSupportedAnnotationTypes() = setOf(ANNOTATION_FQ_NAME)
|
||||||
|
|
||||||
|
override fun getSupportedOptions() = setOf(SUFFIX_OPTION)
|
||||||
}
|
}
|
||||||
+13
@@ -85,4 +85,17 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Test fun testKaptArguments() {
|
||||||
|
Project("kaptArguments", "1.12").build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains("kapt: Using class file stubs")
|
||||||
|
assertContains(":compileKotlin")
|
||||||
|
assertContains(":compileJava")
|
||||||
|
assertFileExists("build/tmp/kapt/main/wrappers/annotations.main.txt")
|
||||||
|
assertFileExists("build/generated/source/kapt/main/TestClassCustomized.java")
|
||||||
|
assertFileExists("build/classes/main/example/TestClass.class")
|
||||||
|
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url 'file://' + pathToKotlinPlugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: "java"
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'file://' + pathToKotlinPlugin
|
||||||
|
}
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT"
|
||||||
|
compile "org.jetbrains.kotlin:annotation-processor-example:0.1-SNAPSHOT"
|
||||||
|
kapt "org.jetbrains.kotlin:annotation-processor-example:0.1-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
task show << {
|
||||||
|
buildscript.configurations.classpath.each { println it }
|
||||||
|
}
|
||||||
|
|
||||||
|
task wrapper(type: Wrapper) {
|
||||||
|
gradleVersion="1.12"
|
||||||
|
}
|
||||||
|
|
||||||
|
kapt {
|
||||||
|
generateStubs = true
|
||||||
|
arg("suffix", "Customized")
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
@example.ExampleAnnotation
|
||||||
|
public class TestClass {
|
||||||
|
|
||||||
|
@example.ExampleAnnotation
|
||||||
|
public val testVal: String = "text"
|
||||||
|
|
||||||
|
@example.ExampleAnnotation
|
||||||
|
public fun testFunction(): Class<*> = javaClass<TestClassCustomized>()
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user