Filter out non-Java files from kapt inputs
#KT-23878 fixed
This commit is contained in:
+18
-5
@@ -9,7 +9,23 @@ import org.junit.Test
|
||||
class KaptIncrementalNoStubsIT : KaptIncrementalBaseIT(shouldUseStubs = false)
|
||||
class KaptIncrementalWithStubsIT : KaptIncrementalBaseIT(shouldUseStubs = true)
|
||||
|
||||
class Kapt3Incremental : KaptIncrementalBaseIT(shouldUseStubs = false, useKapt3 = true)
|
||||
class Kapt3Incremental : KaptIncrementalBaseIT(shouldUseStubs = false, useKapt3 = true) {
|
||||
@Test
|
||||
fun testAddNewLine() {
|
||||
val project = Project("simple", directoryPrefix = "kapt2")
|
||||
|
||||
project.build("clean", "build") {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
project.projectFile("test.kt").modify { "\n$it" }
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":kaptGenerateStubsKotlin", ":compileJava", ":compileKotlin")
|
||||
assertTasksUpToDate(":kaptKotlin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KaptIncrementalBaseIT(val shouldUseStubs: Boolean, val useKapt3: Boolean = false) : BaseGradleIT() {
|
||||
init {
|
||||
@@ -277,10 +293,7 @@ abstract class KaptIncrementalBaseIT(val shouldUseStubs: Boolean, val useKapt3:
|
||||
|
||||
private fun CompiledProject.assertKapt3FullyExecuted() {
|
||||
if (useKapt3) {
|
||||
assertNotContains(
|
||||
":kaptKotlin UP-TO-DATE",
|
||||
":kaptGenerateStubsKotlin UP-TO-DATE"
|
||||
)
|
||||
assertTasksExecuted(":kaptKotlin", ":kaptGenerateStubsKotlin")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-20
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.incremental.isJavaFile
|
||||
import java.io.File
|
||||
|
||||
@CacheableTask
|
||||
@@ -36,11 +37,6 @@ open class KaptTask : ConventionTask(), CompilerArgumentAwareWithInput<K2JVMComp
|
||||
@get:Internal
|
||||
internal lateinit var stubsDir: File
|
||||
|
||||
private fun isInsideDestinationDirs(file: File): Boolean {
|
||||
return FileUtil.isAncestor(destinationDir, file, /* strict = */ false)
|
||||
|| FileUtil.isAncestor(classesDir, file, /* strict = */ false)
|
||||
}
|
||||
|
||||
@get:Classpath @get:InputFiles
|
||||
val kaptClasspath: FileCollection
|
||||
get() = project.files(*kaptClasspathConfigurations.toTypedArray())
|
||||
@@ -87,25 +83,29 @@ open class KaptTask : ConventionTask(), CompilerArgumentAwareWithInput<K2JVMComp
|
||||
internal val pluginClasspath get() = pluginOptions.classpath
|
||||
|
||||
@get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
val source: FileCollection
|
||||
val source: Collection<File>
|
||||
get() {
|
||||
val sourcesFromKotlinTask = kotlinCompileTask.source
|
||||
.filter { it.extension == "java" && !isInsideDestinationDirs(it) }
|
||||
|
||||
val stubSources = project.fileTree(stubsDir)
|
||||
return sourcesFromKotlinTask + stubSources
|
||||
val result = HashSet<File>()
|
||||
for (root in javaSourceRoots) {
|
||||
root.walk().filterTo(result) { it.isJavaFile() }
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private val javaSourceRoots: Set<File>
|
||||
get() = (kotlinCompileTask.sourceRootsContainer.sourceRoots + stubsDir)
|
||||
.filterTo(HashSet(), ::isRootAllowed)
|
||||
|
||||
private fun isRootAllowed(file: File): Boolean =
|
||||
!FileUtil.isAncestor(destinationDir, file, /* strict = */ false) &&
|
||||
!FileUtil.isAncestor(classesDir, file, /* strict = */ false)
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
/** Delete everything inside generated sources and classes output directory
|
||||
* (annotation processing is not incremental) */
|
||||
clearOutputDirectories()
|
||||
|
||||
val sourceRootsFromKotlin = kotlinCompileTask.sourceRootsContainer.sourceRoots
|
||||
val rawSourceRoots = FilteringSourceRootsContainer(sourceRootsFromKotlin, { !isInsideDestinationDirs(it) })
|
||||
val sourceRoots = SourceRoots.ForJvm.create(kotlinCompileTask.source, rawSourceRoots)
|
||||
|
||||
val args = prepareCompilerArguments()
|
||||
|
||||
val messageCollector = GradleMessageCollector(logger)
|
||||
@@ -117,11 +117,12 @@ open class KaptTask : ConventionTask(), CompilerArgumentAwareWithInput<K2JVMComp
|
||||
|
||||
val compilerRunner = GradleCompilerRunner(project)
|
||||
val exitCode = compilerRunner.runJvmCompiler(
|
||||
sourceRoots.kotlinSourceFiles,
|
||||
sourceRoots.javaSourceRoots,
|
||||
kotlinCompileTask.javaPackagePrefix,
|
||||
args,
|
||||
environment)
|
||||
sourcesToCompile = emptyList(),
|
||||
javaSourceRoots = javaSourceRoots,
|
||||
javaPackagePrefix = kotlinCompileTask.javaPackagePrefix,
|
||||
args = args,
|
||||
environment = environment
|
||||
)
|
||||
throwGradleExceptionIfError(exitCode)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user