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

commonMain.co.touchlab.skie.plugin.SkieInternalExtension.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0-RC.5
Show newest version
package co.touchlab.skie.plugin

import co.touchlab.skie.plugin.configuration.skieExtension
import co.touchlab.skie.plugin.shim.KgpShim
import co.touchlab.skie.plugin.shim.KgpShimLoader
import co.touchlab.skie.plugin.shim.SkieKotlinVariantResolver
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import javax.inject.Inject

abstract class SkieInternalExtension @Inject constructor(
    private val project: Project,
    val kotlinVersion: String,
    val kgpShim: KgpShim,
) {

    val targets: NamedDomainObjectContainer
        get() = kgpShim.skieTargets

    val isSkieEnabled: Boolean
        get() = project.skieExtension.isEnabled.get() && kgpShim.hostIsMac

    companion object {

        fun withExtension(project: Project, action: (SkieInternalExtension) -> Unit) {
            SkieKotlinVariantResolver.withSkieKotlinVersion(project) { kotlinVersion ->
                val kgpShim = KgpShimLoader.load(kotlinVersion, project) ?: return@withSkieKotlinVersion

                val extension = project.extensions.create(
                    "skieInternal",
                    SkieInternalExtension::class.java,
                    kotlinVersion,
                    kgpShim,
                )

                action(extension)
            }
        }
    }
}

val Project.skieInternalExtension: SkieInternalExtension
    get() = extensions.getByType(SkieInternalExtension::class.java)

val Project.kgpShim: KgpShim
    get() = skieInternalExtension.kgpShim




© 2015 - 2024 Weber Informatics LLC | Privacy Policy