Load kotlin.incremental from local.properties file too

This commit is contained in:
Alexey Tsvetkov
2016-03-31 19:28:27 +03:00
parent 781bc13941
commit 0a5db2fea4
3 changed files with 34 additions and 4 deletions
@@ -53,6 +53,7 @@ const val ANNOTATIONS_PLUGIN_NAME = "org.jetbrains.kotlin.kapt"
const val KOTLIN_BUILD_DIR_NAME = "kotlin" const val KOTLIN_BUILD_DIR_NAME = "kotlin"
const val CACHES_DIR_NAME = "caches" const val CACHES_DIR_NAME = "caches"
const val DIRTY_SOURCES_FILE_NAME = "dirty-sources.txt" const val DIRTY_SOURCES_FILE_NAME = "dirty-sources.txt"
const val USING_EXPERIMENTAL_INCREMENTAL_MESSAGE = "Using experimental kotlin incremental compilation"
abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCompile() { abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCompile() {
abstract protected val compiler: CLICompiler<T> abstract protected val compiler: CLICompiler<T>
@@ -360,7 +361,7 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
return return
} }
logger.warn("Using experimental kotlin incremental compilation") logger.warn(USING_EXPERIMENTAL_INCREMENTAL_MESSAGE)
anyClassesCompiled = false anyClassesCompiled = false
// TODO: decide what to do if no files are considered dirty - rebuild or skip the module // TODO: decide what to do if no files are considered dirty - rebuild or skip the module
var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile() var (sourcesToCompile, isIncrementalDecided) = calculateSourcesToCompile()
@@ -2,10 +2,16 @@ package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.compile.AbstractCompile import org.gradle.api.tasks.compile.AbstractCompile
import java.util.*
fun mapKotlinTaskProperties(project: Project, task: AbstractCompile) { fun mapKotlinTaskProperties(project: Project, task: AbstractCompile) {
for (mapping in propertyMappings) { propertyMappings.forEach { it.apply(project, task) }
mapping.apply(project, task)
val localPropertiesFile = project.rootProject.file("local.properties")
if (localPropertiesFile.isFile) {
val properties = Properties()
properties.load(localPropertiesFile.inputStream())
propertyMappings.forEach { it.apply(properties, task) }
} }
} }
@@ -21,7 +27,16 @@ private class KotlinPropertyMapping<T>(
fun apply(project: Project, task: AbstractCompile) { fun apply(project: Project, task: AbstractCompile) {
if (!project.hasProperty(projectPropName)) return if (!project.hasProperty(projectPropName)) return
val value = project.property(projectPropName) as? String ?: return setPropertyValue(task, project.property(projectPropName))
}
fun apply(properties: Properties, task: AbstractCompile) {
setPropertyValue(task, properties.getProperty(projectPropName))
}
private fun setPropertyValue(task: AbstractCompile, value: Any?) {
if (value !is String) return
val transformedValue = transform(value) ?: return val transformedValue = transform(value) ?: return
task.setProperty(taskPropName, transformedValue) task.setProperty(taskPropName, transformedValue)
} }
@@ -2,6 +2,7 @@ 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.junit.Test import org.junit.Test
import java.io.File import java.io.File
import kotlin.test.assertTrue import kotlin.test.assertTrue
@@ -269,4 +270,17 @@ class KotlinGradleIT: BaseGradleIT() {
assertFileExists("build/classes/main/example/TestClassCustomized.class") assertFileExists("build/classes/main/example/TestClassCustomized.class")
} }
} }
@Test
fun testIncrementalPropertyFromLocalPropertiesFile() {
val project = Project("kotlinProject", "2.10")
project.setupWorkingDir()
val localPropertyFile = File(project.projectDir, "local.properties")
localPropertyFile.writeText("kotlin.incremental=true")
project.build("build") {
assertContains(USING_EXPERIMENTAL_INCREMENTAL_MESSAGE)
}
}
} }