mirror of https://github.com/sbt/sbt.git
Merge pull request #1533 from sbt/fix/1530
Fixes #1530. Fixes NPE by using IO.listFiles
This commit is contained in:
commit
6cc4c18405
|
|
@ -1,7 +1,7 @@
|
|||
package sbt.complete
|
||||
|
||||
import java.io.File
|
||||
import sbt.IO._
|
||||
import sbt.IO
|
||||
|
||||
/**
|
||||
* These sources of examples are used in parsers for user input completion. An example of such a source is the
|
||||
|
|
@ -48,9 +48,9 @@ class FileExamples(base: File, prefix: String = "") extends ExampleSource {
|
|||
override def withAddedPrefix(addedPrefix: String): FileExamples = new FileExamples(base, prefix + addedPrefix)
|
||||
|
||||
protected def files(directory: File): Stream[String] = {
|
||||
val childPaths = directory.listFiles().toStream
|
||||
val prefixedDirectChildPaths = childPaths.map(relativize(base, _).get).filter(_ startsWith prefix)
|
||||
val dirsToRecurseInto = childPaths.filter(_.isDirectory).map(relativize(base, _).get).filter(dirStartsWithPrefix)
|
||||
val childPaths = IO.listFiles(directory).toStream
|
||||
val prefixedDirectChildPaths = childPaths map { IO.relativize(base, _).get } filter { _ startsWith prefix }
|
||||
val dirsToRecurseInto = childPaths filter { _.isDirectory } map { IO.relativize(base, _).get } filter { dirStartsWithPrefix }
|
||||
prefixedDirectChildPaths append dirsToRecurseInto.flatMap(dir => files(new File(base, dir)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,7 @@ class FileExamplesTest extends Specification {
|
|||
(childDirectories ++ nestedDirectories).map(_.mkdirs())
|
||||
(childFiles ++ nestedFiles).map(_.createNewFile())
|
||||
|
||||
// NOTE: Creating a new file here because `tempDir.listFiles()` returned an empty list.
|
||||
baseDir = new File(tempDir.getCanonicalPath)
|
||||
baseDir = tempDir
|
||||
}
|
||||
|
||||
private def toChildFiles(baseDir: File, files: List[String]): List[File] = files.map(new File(baseDir, _))
|
||||
|
|
|
|||
Loading…
Reference in New Issue