name.remal.gradle_plugins.dsl.utils.newFileCollection.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugins-kotlin-dsl Show documentation
Show all versions of gradle-plugins-kotlin-dsl Show documentation
Remal Gradle plugins: gradle-plugins-kotlin-dsl
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()
}