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

com.prof18.kmpframeworkbundler.data.PluginConfig.kt Maven / Gradle / Ivy

Go to download

Gradle plugin to manage the distribution via CocoaPod of a Kotlin Multiplatform library for Apple platforms with a XCFramework or a FatFramework

There is a newer version: 0.0.16
Show newest version
package com.prof18.kmpframeworkbundler.data

import com.prof18.kmpframeworkbundler.CocoaPodRepoDSL
import com.prof18.kmpframeworkbundler.KMPFrameworkBundlerExtension
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask
import java.io.File

internal class PluginConfig private constructor(
    val debugFrameworkList: List,
    val releaseFrameworkList: List,
    val frameworkName: Property,
    val outputPath: Property,
    val versionName: Property,
    val cocoaPodRepoInfo: CocoaPodRepoDSL,
    private val xcFrameworkTasks: List,
    val frameworkType: FrameworkType,
) {

    internal fun getPodSpecFile() = File("${outputPath.get()}/${frameworkName.get()}.podspec")

    internal fun getXCFrameworkDebugBuildTask(): XCFrameworkTask {
        val buildTask = xcFrameworkTasks.firstOrNull {
            (it as XCFrameworkTask).buildType == NativeBuildType.DEBUG
        } as? XCFrameworkTask ?: throw ClassNotFoundException(ErrorMessages.XC_FRAMEWORK_DEBUG_TASK_NOT_FOUND)
        return buildTask
    }

    internal fun getXCFrameworkReleaseBuildTask(): XCFrameworkTask {
        val buildTask = xcFrameworkTasks.firstOrNull {
            (it as XCFrameworkTask).buildType == NativeBuildType.RELEASE
        } as? XCFrameworkTask ?: throw IllegalArgumentException(ErrorMessages.XC_FRAMEWORK_RELEASE_TASK_NOT_FOUND)
        return buildTask
    }

    internal companion object {
        fun of(extension: KMPFrameworkBundlerExtension): PluginConfig {
            return PluginConfig(
                debugFrameworkList = extension.debugFrameworkList,
                releaseFrameworkList = extension.releaseFrameworkList,
                frameworkName = extension.frameworkName,
                outputPath = extension.outputPath,
                versionName = extension.versionName,
                cocoaPodRepoInfo = extension.cocoaPodRepoInfo,
                xcFrameworkTasks = extension.xcFrameworkTasks,
                frameworkType = extension.frameworkType,
            )
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy