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

name.remal.gradle_plugins.dsl.extensions.org.gradle.api.NamedDomainObjectCollection.kt Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package name.remal.gradle_plugins.dsl.extensions

import org.gradle.api.DomainObjectCollection
import org.gradle.api.NamedDomainObjectCollection

operator fun  NamedDomainObjectCollection.get(type: Class): NamedDomainObjectCollection = withType(type)

operator fun NamedDomainObjectCollection<*>.contains(name: String): Boolean = findByName(name) != null
operator fun  NamedDomainObjectCollection.get(name: String): T = getByName(name)
operator fun  NamedDomainObjectCollection.get(type: Class, name: String): S = withType(type).getByName(name)


fun  NamedDomainObjectCollection.all(name: String, configureAction: (T) -> Unit) = all {
    if (name == namer.determineName(it)) {
        configureAction(it)
    }
}

fun  NamedDomainObjectCollection.all(nameProviders: DomainObjectCollection, nameGetter: (nameProvider: N) -> String, configureAction: (T) -> Unit) = all {
    nameProviders.all { nameProvider ->
        val name = nameGetter(nameProvider)
        if (name == namer.determineName(it)) {
            configureAction(it)
        }
    }
}

fun  NamedDomainObjectCollection.all(type: Class, name: String, configureAction: (S) -> Unit) = withType(type).all(name, configureAction)

fun  NamedDomainObjectCollection.all(type: Class, nameProviders: DomainObjectCollection, nameGetter: (nameProvider: N) -> String, configureAction: (S) -> Unit) = withType(type).all(nameProviders, nameGetter, configureAction)

fun  NamedDomainObjectCollection.forEach(name: String, configureAction: (T) -> Unit) = forEach {
    if (name == namer.determineName(it)) {
        configureAction(it)
    }
}

fun  NamedDomainObjectCollection.forEach(nameProviders: DomainObjectCollection, nameGetter: (nameProvider: N) -> String, configureAction: (T) -> Unit) = forEach {
    nameProviders.forEach { nameProvider ->
        val name = nameGetter(nameProvider)
        if (name == namer.determineName(it)) {
            configureAction(it)
        }
    }
}

fun  NamedDomainObjectCollection.forEach(type: Class, name: String, configureAction: (S) -> Unit) = withType(type).forEach(name, configureAction)

@Suppress("MaxLineLength")
fun  NamedDomainObjectCollection.forEach(type: Class, nameProviders: DomainObjectCollection, nameGetter: (nameProvider: N) -> String, configureAction: (S) -> Unit) = withType(type).forEach(nameProviders, nameGetter, configureAction)