1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Test for existence.

This commit is contained in:
Cedric Beust 2017-03-29 15:57:57 -07:00
parent 397b60b60a
commit b58c495bbd

View file

@ -11,6 +11,7 @@ import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildSources
import com.beust.kobalt.misc.*
import com.google.inject.Inject
import jdk.nashorn.internal.objects.NativeArray.forEach
import java.io.File
import java.net.URL
import java.nio.file.*
@ -52,12 +53,17 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
private fun findFiles(file: File, accept: (File) -> Boolean) : List<File> {
val result = arrayListOf<File>()
Files.walkFileTree(Paths.get(file.path), object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult {
if (accept(file.toFile())) result.add(file.toFile())
return FileVisitResult.CONTINUE
}
})
// It's possible for no build file to be present (e.g. testing)
if (file.exists()) {
Files.walkFileTree(Paths.get(file.path), object : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult {
if (accept(file.toFile())) result.add(file.toFile())
return FileVisitResult.CONTINUE
}
})
}
return result
}
@ -67,8 +73,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
val result = arrayListOf<File>()
val sourceDirs = arrayListOf<String>().apply { add(root + File.separator + KOBALT_SRC) }.map(::File)
// It's possible for no build file to be present (e.g. testing)
sourceDirs.filter { it.exists() }.forEach { dir ->
sourceDirs.forEach { dir ->
result.addAll(findFiles(dir, { it.name.endsWith(".kt") }))
}
return result