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

org.jetbrains.kotlin.gradle.tasks.kotlinCompileTaskData.kt Maven / Gradle / Ivy

There is a newer version: 2.0.20-RC
Show newest version
/*
 * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.gradle.tasks

import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.provider.Property
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinCompilation
import java.io.File

internal open class KotlinCompileTaskData(
    val taskName: String,
    val compilation: AbstractKotlinCompilation<*>,
    val destinationDir: Property,
    val useModuleDetection: Property
) {
    private val taskBuildDirectory: File
        get() = File(File(compilation.target.project.buildDir, KOTLIN_BUILD_DIR_NAME), taskName)

    val buildHistoryFile: File
        get() = File(taskBuildDirectory, "build-history.bin")

    var javaOutputDir: File? = null

    companion object {
        fun get(project: Project, taskName: String): KotlinCompileTaskData = project.getTaskDataMap().getValue(taskName)

        fun getTaskDataContainer(project: Project): Iterable =
            project.getTaskDataMap().values.toSet()

        fun register(
            taskName: String,
            compilation: AbstractKotlinCompilation<*>
        ): KotlinCompileTaskData {
            val project = compilation.target.project
            val container = project.getTaskDataMap()

            @Suppress("UnstableApiUsage")
            return KotlinCompileTaskData(
                taskName,
                compilation,
                project.objects.property(File::class.java).apply {
                    set(project.provider { error("destinationDir was not set for task ${project.path}$taskName") })
                },
                project.objects.property(Boolean::class.javaObjectType).apply { set(false) }
            ).also {
                container[taskName] = it
            }
        }

        private fun Project.getTaskDataMap(): MutableMap {
            val ext = project.extensions.getByType(ExtraPropertiesExtension::class.java)
            if (!ext.has(EXT_NAME)) {
                ext.set(EXT_NAME, mutableMapOf())
            }
            @Suppress("UNCHECKED_CAST")
            return ext.get(EXT_NAME) as MutableMap
        }

        private const val EXT_NAME = "kotlin.incremental.taskdata"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy