diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index 8e274a6f..dbc71200 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -41,6 +41,9 @@ class Args { @Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)") var log: Int = 1 + @Parameter(names = arrayOf("--noIncremental"), description = "Turn off incremental builds") + var noIncremental: Boolean = false + companion object { const val DEFAULT_SERVER_PORT = 1234 } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt index 64997291..b562f282 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.internal +import com.beust.kobalt.Args import com.beust.kobalt.IncrementalTaskInfo import com.beust.kobalt.TaskResult import com.beust.kobalt.Variant @@ -9,6 +10,8 @@ import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.log import com.google.gson.Gson import com.google.gson.GsonBuilder +import com.google.inject.Inject +import com.google.inject.Singleton import java.io.File import java.io.FileReader import java.nio.charset.Charset @@ -21,10 +24,13 @@ data class TaskInfo(val taskName: String, var inputChecksum: String? = null, var class BuildInfo(var tasks: List) /** - * Manage the file .kobalt/build-info.kt, which keeps track of input and output checksums to manage + * Manage the file .kobalt/buildInfo.json, which keeps track of input and output checksums to manage * incremental builds. */ -class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FILE) { +@Singleton +class IncrementalManager @Inject constructor(val args: Args) { + val fileName = IncrementalManager.BUILD_INFO_FILE + companion object { val BUILD_INFO_FILE = KFiles.joinDir(KFiles.KOBALT_DOT_DIR, "buildInfo.json") } @@ -85,12 +91,18 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI var upToDate = false var taskOutputChecksum : String? = null - if (iti.context.previousTaskWasIncrementalSuccess(project.name)) { + if (args.noIncremental) { // - // If the previous task was an incremental success, no need to run + // If the user turned off incremental builds, always run this task + // + logIncremental(LEVEL, "Incremental builds are turned off, running $taskName") + upToDate = false + } else if (iti.context.previousTaskWasIncrementalSuccess(project.name)) { + // + // If the previous task was an incremental success, no need to run this task // logIncremental(LEVEL, "Previous incremental task was a success, not running $shortTaskName") - TaskResult() + upToDate = true } else { // // First, compare the input checksums @@ -119,33 +131,33 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI project.projectExtra.isDirty = true } } + } - if (!upToDate) { - // - // The task is out of date, invoke the task on the IncrementalTaskInfo object - // - val result = iti.task(project) - if (result.success) { - logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums") - iti.inputChecksum()?.let { - saveInputChecksum(taskName, it) - logIncremental(LEVEL, " input checksum \"$it\" saved") - } - // Important to rerun the checksum here since the output of the task might have changed it - iti.outputChecksum()?.let { - saveOutputChecksum(taskName, it) - logIncremental(LEVEL, " output checksum \"$it\" saved") - } + if (!upToDate) { + // + // The task is out of date, invoke the task on the IncrementalTaskInfo object + // + val result = iti.task(project) + if (result.success) { + logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums") + iti.inputChecksum()?.let { + saveInputChecksum(taskName, it) + logIncremental(LEVEL, " input checksum \"$it\" saved") + } + // Important to rerun the checksum here since the output of the task might have changed it + iti.outputChecksum()?.let { + saveOutputChecksum(taskName, it) + logIncremental(LEVEL, " output checksum \"$it\" saved") } - result - } else { - // - // Identical input and output checksums, don't run the task - // - logIncremental(LEVEL, "Incremental task \"$taskName\" is up to date, not running it") - iti.context.setIncrementalSuccess(project.name) - TaskResult() } + result + } else { + // + // Identical input and output checksums, don't run the task + // + logIncremental(LEVEL, "Incremental task \"$taskName\" is up to date, not running it") + iti.context.setIncrementalSuccess(project.name) + TaskResult() } } } diff --git a/src/test/kotlin/com/beust/kobalt/internal/IncrementalManagerTest.kt b/src/test/kotlin/com/beust/kobalt/internal/IncrementalManagerTest.kt index 7600d17e..65a039f6 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/IncrementalManagerTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/IncrementalManagerTest.kt @@ -1,5 +1,6 @@ package com.beust.kobalt.internal +import com.beust.kobalt.Args import org.testng.Assert import org.testng.annotations.Test import java.io.File @@ -12,7 +13,7 @@ class IncrementalManagerTest { fun shouldSave() { val file = File.createTempFile("kobalt-", "") println("File: $file") - val im = IncrementalManager(file.absolutePath) + val im = IncrementalManager(Args())//, file.absolutePath) val v = im.inputChecksumFor(TASK) Assert.assertNull(v) im.saveInputChecksum(TASK, "44")