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

pcimcioch.gitlabci.dsl.include.IncludeDsl.kt Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
package pcimcioch.gitlabci.dsl.include

import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.list
import pcimcioch.gitlabci.dsl.DslBase
import pcimcioch.gitlabci.dsl.serializer.ValueSerializer

@Serializable(with = IncludeDsl.IncludeDslSerializer::class)
class IncludeDsl : DslBase() {
    private val includes = mutableListOf()

    fun local(local: String) = addAndReturn(includes, IncludeLocalDsl(local))
    fun file(project: String, file: String, ref: String? = null) = addAndReturn(includes, IncludeFileDsl(project, file, ref))
    fun template(template: String) = addAndReturn(includes, IncludeTemplateDsl(template))
    fun remote(remote: String) = addAndReturn(includes, IncludeRemoteDsl(remote))
    operator fun IncludeDetailsDsl.unaryPlus() = [email protected](this)

    override fun validate(errors: MutableList) {
        addErrors(errors, "[include]", includes)
    }

    object IncludeDslSerializer : ValueSerializer>(IncludeDetailsDsl.serializer().list, IncludeDsl::includes)
    companion object {
        init {
            addSerializer(IncludeDsl::class, serializer())
        }
    }
}

@Serializable(with = DslBase.DslBaseSerializer::class)
sealed class IncludeDetailsDsl : DslBase()

@Serializable
class IncludeLocalDsl(
        var local: String
) : IncludeDetailsDsl() {
    companion object {
        init {
            addSerializer(IncludeLocalDsl::class, serializer())
        }
    }
}

fun createIncludeLocal(local: String) = IncludeLocalDsl(local)

@Serializable
class IncludeFileDsl(
        var project: String,
        var file: String,
        var ref: String? = null
) : IncludeDetailsDsl() {
    companion object {
        init {
            addSerializer(IncludeFileDsl::class, serializer())
        }
    }
}

fun createIncludeFile(project: String, file: String, ref: String? = null) = IncludeFileDsl(project, file, ref)

@Serializable
class IncludeTemplateDsl(
        var template: String
) : IncludeDetailsDsl() {
    companion object {
        init {
            addSerializer(IncludeTemplateDsl::class, serializer())
        }
    }
}

fun createIncludeTemplate(template: String) = IncludeTemplateDsl(template)

@Serializable
class IncludeRemoteDsl(
        var remote: String
) : IncludeDetailsDsl() {
    companion object {
        init {
            addSerializer(IncludeRemoteDsl::class, serializer())
        }
    }
}

fun createIncludeRemote(remote: String) = IncludeRemoteDsl(remote)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy