All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.gradle.plugin.KotlinProperties.kt Maven / Gradle / Ivy

There is a newer version: 2.1.20-Beta1
Show newest version
package org.jetbrains.kotlin.gradle.plugin

import org.gradle.api.Project
import org.gradle.api.tasks.compile.AbstractCompile
import java.util.*

fun mapKotlinTaskProperties(project: Project, task: AbstractCompile) {
    propertyMappings.forEach { it.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) }
    }
}

private val propertyMappings = listOf(
        KotlinPropertyMapping("kotlin.incremental", "incremental", String::toBoolean)
)

private class KotlinPropertyMapping(
        private val projectPropName: String,
        private val taskPropName: String,
        private val transform: (String) -> T
) {
    fun apply(project: Project, task: AbstractCompile) {
        if (!project.hasProperty(projectPropName)) 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
        task.setProperty(taskPropName, transformedValue)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy