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

org.jetbrains.kotlin.gradle.plugin.mpp.kotlinTargetPresets.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2020 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.plugin.mpp

import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.DeprecatedTargetPresetApi
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.android.internal.InternalKotlinTargetPreset

@DeprecatedTargetPresetApi
abstract class KotlinOnlyTargetPreset, T : KotlinCompilation<*>>(
    protected val project: Project,
) : InternalKotlinTargetPreset {

    protected abstract fun createKotlinTargetConfigurator(): AbstractKotlinTargetConfigurator

    protected open fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget): String? =
        target.targetName

    // This function is used in IDE import in order to indicate that sourceSetName=disambiguationClassifier+compilationName
    @Deprecated("Scheduled for removal with Kotlin 2.2", level = DeprecationLevel.ERROR)
    protected open fun useDisambiguationClassifierAsSourceSetNamePrefix() = true

    // This function is used in IDE import in order to override sourceSetName
    @Deprecated("Scheduled for removal with Kotlin 2.2", level = DeprecationLevel.ERROR)
    protected open fun overrideDisambiguationClassifierOnIdeImport(name: String): String? = null

    protected abstract fun instantiateTarget(name: String): R

    override fun createTargetInternal(name: String): R {
        val result = instantiateTarget(name).apply {
            targetName = name
            disambiguationClassifier = provideTargetDisambiguationClassifier(this@apply)
            preset = this@KotlinOnlyTargetPreset

            val compilationFactory = createCompilationFactory(this)
            compilations = project.container(compilationFactory.itemClass, compilationFactory)
        }

        createKotlinTargetConfigurator().configureTarget(result)
        return result
    }

    protected abstract fun createCompilationFactory(forTarget: R): KotlinCompilationFactory
    protected abstract val platformType: KotlinPlatformType
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy