Refactoring: move kapt tests to separate class
This commit is contained in:
+9
-3
@@ -48,11 +48,17 @@ fun Project.initKapt(
|
|||||||
kotlinTask.extensions.extraProperties.set("kaptStubsDir", stubsDir)
|
kotlinTask.extensions.extraProperties.set("kaptStubsDir", stubsDir)
|
||||||
javaTask.appendClasspathDynamically(stubsDir)
|
javaTask.appendClasspathDynamically(stubsDir)
|
||||||
|
|
||||||
|
val javaDestinationDir = project.files(javaTask.destinationDir)
|
||||||
javaTask.doLast {
|
javaTask.doLast {
|
||||||
kotlinAfterJavaTask.source(kotlinTask.source)
|
kotlinAfterJavaTask.source(kotlinTask.source)
|
||||||
kotlinAfterJavaTask.source(kaptManager.javaAptSourceDir)
|
|
||||||
// we don't want kotlinAfterJavaTask to track modifications in generated class
|
// we don't want kotlinAfterJavaTask to track modifications in generated class
|
||||||
kotlinAfterJavaTask.classpath -= project.files(javaTask.destinationDir)
|
kotlinAfterJavaTask.classpath -= javaDestinationDir
|
||||||
|
}
|
||||||
|
kotlinAfterJavaTask.doFirst {
|
||||||
|
kotlinAfterJavaTask.classpath += javaDestinationDir
|
||||||
|
}
|
||||||
|
kotlinAfterJavaTask.doLast {
|
||||||
|
kotlinAfterJavaTask.classpath -= javaDestinationDir
|
||||||
}
|
}
|
||||||
|
|
||||||
subpluginEnvironment.addSubpluginArguments(this, kotlinAfterJavaTask)
|
subpluginEnvironment.addSubpluginArguments(this, kotlinAfterJavaTask)
|
||||||
@@ -123,7 +129,7 @@ public class AnnotationProcessingManager(
|
|||||||
private val javaTask: JavaCompile,
|
private val javaTask: JavaCompile,
|
||||||
private val taskQualifier: String,
|
private val taskQualifier: String,
|
||||||
private val aptFiles: Set<File>,
|
private val aptFiles: Set<File>,
|
||||||
private val aptOutputDir: File,
|
val aptOutputDir: File,
|
||||||
private val aptWorkingDir: File,
|
private val aptWorkingDir: File,
|
||||||
private val coreClassLoader: ClassLoader,
|
private val coreClassLoader: ClassLoader,
|
||||||
private val androidVariant: Any? = null) {
|
private val androidVariant: Any? = null) {
|
||||||
|
|||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class KaptIT: BaseGradleIT() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val GRADLE_VERSION = "2.10"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun defaultBuildOptions(): BuildOptions =
|
||||||
|
super.defaultBuildOptions().copy(withDaemon = true)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSimple() {
|
||||||
|
val project = Project("kaptSimple", GRADLE_VERSION)
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains("kapt: Class file stubs are not used")
|
||||||
|
assertContains(":compileKotlin")
|
||||||
|
assertContains(":compileJava")
|
||||||
|
assertFileExists("build/tmp/kapt/main/wrappers/annotations.main.txt")
|
||||||
|
assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java")
|
||||||
|
assertFileExists("build/classes/main/example/TestClass.class")
|
||||||
|
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStubs() {
|
||||||
|
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||||
|
|
||||||
|
project.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/TestClassGenerated.java")
|
||||||
|
assertFileExists("build/classes/main/example/TestClass.class")
|
||||||
|
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSimpleIncrementalBuild() {
|
||||||
|
doTestIncrementalBuild("kaptSimple", arrayOf(":compileKotlin", ":compileJava"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStubsIncrementalBuild() {
|
||||||
|
doTestIncrementalBuild("kaptStubs", arrayOf(":compileKotlin", ":compileJava", ":compileKotlinAfterJava"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doTestIncrementalBuild(projectName: String, compileTasks: Array<String>) {
|
||||||
|
val compileTasksUpToDate = compileTasks.map { it + " UP-TO-DATE" }.toTypedArray()
|
||||||
|
val project = Project(projectName, GRADLE_VERSION)
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
|
||||||
|
project.projectDir.getFileByName("test.kt").appendText(" ")
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(*compileTasks)
|
||||||
|
assertNotContains(*compileTasksUpToDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(2) {
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(*compileTasksUpToDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build("clean", "build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(*compileTasks)
|
||||||
|
assertNotContains(*compileTasksUpToDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(2) {
|
||||||
|
project.build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains(*compileTasksUpToDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testArguments() {
|
||||||
|
Project("kaptArguments", GRADLE_VERSION).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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testInheritedAnnotations() {
|
||||||
|
Project("kaptInheritedAnnotations", GRADLE_VERSION).build("build") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java")
|
||||||
|
assertFileExists("build/generated/source/kapt/main/AncestorClassGenerated.java")
|
||||||
|
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
||||||
|
assertFileExists("build/classes/main/example/AncestorClassGenerated.class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOutputKotlinCode() {
|
||||||
|
Project("kaptOutputKotlinCode", GRADLE_VERSION).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/tmp/kapt/main/kotlinGenerated/TestClass.kt")
|
||||||
|
assertFileExists("build/classes/main/example/TestClass.class")
|
||||||
|
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-127
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.gradle
|
|||||||
import org.gradle.api.logging.LogLevel
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.jetbrains.kotlin.gradle.plugin.CleanUpBuildListener
|
import org.jetbrains.kotlin.gradle.plugin.CleanUpBuildListener
|
||||||
import org.jetbrains.kotlin.gradle.tasks.USING_EXPERIMENTAL_INCREMENTAL_MESSAGE
|
import org.jetbrains.kotlin.gradle.tasks.USING_EXPERIMENTAL_INCREMENTAL_MESSAGE
|
||||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@@ -182,132 +181,6 @@ class KotlinGradleIT: BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptSimple() {
|
|
||||||
val project = Project("kaptSimple", GRADLE_VERSION)
|
|
||||||
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertContains("kapt: Class file stubs are not used")
|
|
||||||
assertContains(":compileKotlin")
|
|
||||||
assertContains(":compileJava")
|
|
||||||
assertFileExists("build/tmp/kapt/main/wrappers/annotations.main.txt")
|
|
||||||
assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java")
|
|
||||||
assertFileExists("build/classes/main/example/TestClass.class")
|
|
||||||
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
|
||||||
}
|
|
||||||
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptStubs() {
|
|
||||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
|
||||||
|
|
||||||
project.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/TestClassGenerated.java")
|
|
||||||
assertFileExists("build/classes/main/example/TestClass.class")
|
|
||||||
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
|
||||||
}
|
|
||||||
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptSimpleIncrementalBuild() {
|
|
||||||
doTestKaptIncrementalBuild("kaptSimple", arrayOf(":compileKotlin", ":compileJava"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptStubsIncrementalBuild() {
|
|
||||||
doTestKaptIncrementalBuild("kaptStubs", arrayOf(":compileKotlin", ":compileJava", ":compileKotlinAfterJava"))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun doTestKaptIncrementalBuild(projectName: String, compileTasks: Array<String>) {
|
|
||||||
val compileTasksUpToDate = compileTasks.map { it + " UP-TO-DATE" }.toTypedArray()
|
|
||||||
val project = Project(projectName, GRADLE_VERSION)
|
|
||||||
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
}
|
|
||||||
|
|
||||||
project.projectDir.getFileByName("test.kt").appendText(" ")
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertContains(*compileTasks)
|
|
||||||
assertNotContains(*compileTasksUpToDate)
|
|
||||||
}
|
|
||||||
|
|
||||||
repeat(2) {
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertContains(*compileTasksUpToDate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project.build("clean", "build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertContains(*compileTasks)
|
|
||||||
assertNotContains(*compileTasksUpToDate)
|
|
||||||
}
|
|
||||||
|
|
||||||
repeat(2) {
|
|
||||||
project.build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertContains(*compileTasksUpToDate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptArguments() {
|
|
||||||
Project("kaptArguments", GRADLE_VERSION).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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptInheritedAnnotations() {
|
|
||||||
Project("kaptInheritedAnnotations", GRADLE_VERSION).build("build") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertFileExists("build/generated/source/kapt/main/TestClassGenerated.java")
|
|
||||||
assertFileExists("build/generated/source/kapt/main/AncestorClassGenerated.java")
|
|
||||||
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
|
||||||
assertFileExists("build/classes/main/example/AncestorClassGenerated.class")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testKaptOutputKotlinCode() {
|
|
||||||
Project("kaptOutputKotlinCode", GRADLE_VERSION).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/tmp/kapt/main/kotlinGenerated/TestClass.kt")
|
|
||||||
assertFileExists("build/classes/main/example/TestClass.class")
|
|
||||||
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIncrementalPropertyFromLocalPropertiesFile() {
|
fun testIncrementalPropertyFromLocalPropertiesFile() {
|
||||||
val project = Project("kotlinProject", GRADLE_VERSION)
|
val project = Project("kotlinProject", GRADLE_VERSION)
|
||||||
|
|||||||
Reference in New Issue
Block a user