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

name.remal.gradle_plugins.dsl.utils.newFileCollection.kt Maven / Gradle / Ivy

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

import name.remal.KotlinAllOpen
import name.remal.gradle_plugins.dsl.GradleEnumVersion.GRADLE_VERSION_6_0
import name.remal.gradle_plugins.dsl.extensions.compareTo
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.file.AbstractFileCollection
import org.gradle.util.GradleVersion
import java.io.File

fun newFileCollection(filesFactory: () -> Iterable): FileCollection {
    val filesSet = lazy { filesFactory().toSet() }
    if (GradleVersion.current() >= GRADLE_VERSION_6_0) {
        return FileCollectionImpl_6(filesSet)
    } else {
        return FileCollectionImpl_5(filesSet)
    }
}

fun newFileCollection(files: Iterable) = newFileCollection({ files })
fun newFileCollection(vararg files: File) = newFileCollection(files.toList())


@KotlinAllOpen
private class FileCollectionImpl_6(private val filesSet: Lazy>) : AbstractFileCollection() {
    override fun getFiles(): Set = filesSet.value
    override fun getDisplayName() = "file collection"
    override fun equals(other: Any?) = other is FileCollection && other.files == files
    override fun hashCode() = 1 + files.hashCode()
}

@KotlinAllOpen
private class FileCollectionImpl_5(private val filesSet: Lazy>) : AbstractFileCollection() {
    override fun getFiles(): Set = filesSet.value
    override fun getBuildDependencies() = EmptyTaskDependencies
    override fun getDisplayName() = "file collection"
    override fun equals(other: Any?) = other is FileCollection && other.files == files
    override fun hashCode() = 1 + files.hashCode()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy