mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Make both kotlin and java test compile incremental.
This commit is contained in:
parent
e7f844ab7f
commit
b3107f52b5
3 changed files with 49 additions and 52 deletions
|
@ -69,7 +69,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
|
||||
@Task(name = TASK_TEST, description = "Run the tests",
|
||||
runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE, JvmCompilerPlugin.TASK_COMPILE_TEST))
|
||||
fun taskTest(project: Project) : TaskResult {
|
||||
fun taskTest(project: Project): TaskResult {
|
||||
lp(project, "Running tests")
|
||||
|
||||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
||||
|
@ -84,9 +84,9 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
@Task(name = TASK_CLEAN, description = "Clean the project")
|
||||
fun taskClean(project : Project ) : TaskResult {
|
||||
fun taskClean(project: Project): TaskResult {
|
||||
java.io.File(project.directory, project.buildDirectory).let { dir ->
|
||||
if (! dir.deleteRecursively()) {
|
||||
if (!dir.deleteRecursively()) {
|
||||
warn("Couldn't delete $dir")
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory, outputDir))
|
||||
sourceDirs.map { File(project.directory, it) }.filter {
|
||||
it.exists()
|
||||
} .forEach {
|
||||
}.forEach {
|
||||
log(2, "Copying from $sourceDirs to $absOutputDir")
|
||||
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
protected fun compilerArgsFor(project: Project) : List<String> {
|
||||
protected fun compilerArgsFor(project: Project): List<String> {
|
||||
val result = project.projectProperties.get(COMPILER_ARGS)
|
||||
if (result != null) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
@ -139,8 +139,8 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
project.projectProperties.put(COMPILER_ARGS, arrayListOf(*args))
|
||||
}
|
||||
|
||||
fun isOutdated(project: Project, context: KobaltContext, actionInfo: CompilerActionInfo) : Boolean {
|
||||
fun stripSourceDir(sourceFile: String) : String {
|
||||
fun isOutdated(project: Project, context: KobaltContext, actionInfo: CompilerActionInfo): Boolean {
|
||||
fun stripSourceDir(sourceFile: String): String {
|
||||
project.sourceDirectories.forEach {
|
||||
val d = listOf(project.directory, it).joinToString("/")
|
||||
if (sourceFile.startsWith(d)) return sourceFile.substring(d.length + 1)
|
||||
|
@ -148,7 +148,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
throw KobaltException("Couldn't strip source dir from $sourceFile")
|
||||
}
|
||||
|
||||
fun stripSuffix( sourceFile: String) : String {
|
||||
fun stripSuffix(sourceFile: String): String {
|
||||
val index = sourceFile.indexOf(project.sourceSuffix)
|
||||
if (index >= 0) return sourceFile.substring(0, index)
|
||||
else return sourceFile
|
||||
|
@ -158,7 +158,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
val stripped = stripSourceDir(sourceFile)
|
||||
val classFile = File(KFiles.joinDir(project.directory, project.classesDir(context),
|
||||
toClassFile(stripSuffix(stripped))))
|
||||
if (! classFile.exists() || File(sourceFile).lastModified() > classFile.lastModified()) {
|
||||
if (!classFile.exists() || File(sourceFile).lastModified() > classFile.lastModified()) {
|
||||
log(2, "Outdated $sourceFile $classFile " + Date(File(sourceFile).lastModified()) +
|
||||
" " + classFile.lastModified())
|
||||
return true
|
||||
|
@ -168,7 +168,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
@IncrementalTask(name = JvmCompilerPlugin.TASK_COMPILE, description = "Compile the project")
|
||||
fun taskCompile(project: Project) : IncrementalTaskInfo {
|
||||
fun taskCompile(project: Project): IncrementalTaskInfo {
|
||||
val inputChecksum = Md5.toMd5Directories(project.sourceDirectories.map {
|
||||
File(project.directory, it)
|
||||
})
|
||||
|
@ -181,7 +181,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun doTaskCompile(project: Project) : TaskResult {
|
||||
private fun doTaskCompile(project: Project): TaskResult {
|
||||
// Set up the source files now that we have the variant
|
||||
sourceDirectories.addAll(context.variant.sourceDirectories(project))
|
||||
|
||||
|
@ -201,7 +201,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
override fun projects() = projects
|
||||
|
||||
@Task(name = "doc", description = "Generate the documentation for the project")
|
||||
fun taskJavadoc(project: Project) : TaskResult {
|
||||
fun taskJavadoc(project: Project): TaskResult {
|
||||
val docGenerator = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.docContributors)
|
||||
if (docGenerator != null) {
|
||||
return docGenerator.generateDoc(project, context, createCompilerActionInfo(project, context,
|
||||
|
@ -216,7 +216,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
* Create a CompilerActionInfo (all the information that a compiler needs to know) for the given parameters.
|
||||
* Runs all the contributors and interceptors relevant to that task.
|
||||
*/
|
||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean) :
|
||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean):
|
||||
CompilerActionInfo {
|
||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||
|
||||
|
@ -252,7 +252,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
|
||||
// Now that we have the final list of source dirs, find source files in them
|
||||
val sourceFiles = files.findRecursively(projectDirectory, sourceDirectories,
|
||||
{ it .endsWith(project.sourceSuffix) })
|
||||
{ it.endsWith(project.sourceSuffix) })
|
||||
.map { File(projectDirectory, it).path }
|
||||
|
||||
// Finally, alter the info with the compiler interceptors before returning it
|
||||
|
@ -269,5 +269,22 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
// ISourceDirectoryContributor
|
||||
override fun sourceDirectoriesFor(project: Project, context: KobaltContext)
|
||||
= if (accept(project)) sourceDirectories.toList() else arrayListOf()
|
||||
|
||||
@IncrementalTask(name = TASK_COMPILE_TEST, description = "Compile the tests",
|
||||
runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE))
|
||||
fun taskCompileTest(project: Project): IncrementalTaskInfo {
|
||||
val inputChecksum = Md5.toMd5Directories(project.sourceDirectoriesTest.map {
|
||||
File(project.directory, it)
|
||||
})
|
||||
return IncrementalTaskInfo(
|
||||
inputChecksum = inputChecksum,
|
||||
outputChecksum = {
|
||||
Md5.toMd5Directories(listOf(KFiles.makeOutputTestDir(project)))
|
||||
},
|
||||
task = { project -> doTaskCompileTest(project) }
|
||||
)
|
||||
}
|
||||
|
||||
abstract protected fun doTaskCompileTest(project: Project): TaskResult
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.beust.kobalt.plugin.java
|
|||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
|
@ -51,9 +50,7 @@ class JavaPlugin @Inject constructor(
|
|||
return result
|
||||
}
|
||||
|
||||
@Task(name = TASK_COMPILE_TEST, description = "Compile the tests",
|
||||
runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE))
|
||||
fun taskCompileTest(project: Project): TaskResult {
|
||||
override fun doTaskCompileTest(project: Project): TaskResult {
|
||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST)
|
||||
val compilerActionInfo = createCompilerActionInfo(project, context, isTest = true)
|
||||
val result = javaCompiler.compile(project, context, compilerActionInfo)
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
package com.beust.kobalt.plugin.kotlin
|
||||
|
||||
import com.beust.kobalt.IncrementalTaskInfo
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.IncrementalTask
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
|
@ -75,21 +72,7 @@ class KotlinPlugin @Inject constructor(
|
|||
// return TaskResult(success)
|
||||
// }
|
||||
|
||||
@IncrementalTask(name = TASK_COMPILE_TEST, description = "Compile the tests", runAfter = arrayOf(TASK_COMPILE))
|
||||
fun taskCompileTest(project: Project): IncrementalTaskInfo {
|
||||
val inputChecksum = Md5.toMd5Directories(project.sourceDirectoriesTest.map {
|
||||
File(project.directory, it)
|
||||
})
|
||||
return IncrementalTaskInfo(
|
||||
inputChecksum = inputChecksum,
|
||||
outputChecksum = {
|
||||
Md5.toMd5Directories(listOf(KFiles.makeOutputTestDir(project)))
|
||||
},
|
||||
task = { project -> doTaskCompileTest(project) }
|
||||
)
|
||||
}
|
||||
|
||||
private fun doTaskCompileTest(project: Project) : TaskResult {
|
||||
override protected fun doTaskCompileTest(project: Project) : TaskResult {
|
||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_TEST)
|
||||
val projectDir = File(project.directory)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue