Skip to content

Commit

Permalink
Merge pull request #215 from eatkins/swoval-update
Browse files Browse the repository at this point in the history
Don't automatically add path on error
  • Loading branch information
eatkins authored Dec 19, 2018
2 parents ca3deaf + a98343e commit 277853c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
11 changes: 4 additions & 7 deletions io/src/main/scala/sbt/internal/io/DefaultFileTreeView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package sbt.internal.io

import java.nio.file.{ NoSuchFileException, NotDirectoryException, Path }

import com.swoval.files.{ TypedPath => STypedPath }
import com.swoval.files.FileTreeViews
import com.swoval.files.{ FileTreeViews, TypedPath => STypedPath }
import com.swoval.functional.Filters
import sbt.internal.io.SwovalConverters._
import sbt.io.{ FileTreeView, TypedPath }

import scala.collection.JavaConverters._
import SwovalConverters._

import scala.util.Try

private[sbt] object DefaultFileTreeView extends FileTreeView {
private[this] val fileTreeView =
Expand Down Expand Up @@ -44,8 +41,8 @@ private[sbt] object DefaultFileTreeView extends FileTreeView {
case _ => None
})
} catch {
case _: NotDirectoryException | _: NoSuchFileException =>
Try(Seq(TypedPath(path))).getOrElse(Nil)
case _: NoSuchFileException | _: NotDirectoryException =>
Nil
}
}

Expand Down
20 changes: 8 additions & 12 deletions io/src/main/scala/sbt/io/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.nio.file.{

import com.swoval.files.FileTreeViews
import com.swoval.functional.Filter
import sbt.io.FileTreeView.AllPass

import scala.collection.JavaConverters._
import scala.collection.mutable
Expand Down Expand Up @@ -308,15 +307,13 @@ object Path extends Mapper {
} else {
val fileTreeView = FileTreeView.DEFAULT
(file, filter) =>
val unfiltered = fileTreeView.list(file.toPath, 0, AllPass)
unfiltered.flatMap { tp =>
val fileName = tp.toPath.toString
val file = new File(fileName) {
val typedPathFilter: TypedPath => Boolean = tp => {
filter.accept(new File(tp.toPath.toString) {
override def isDirectory: Boolean = tp.isDirectory
override def isFile: Boolean = tp.isFile
}
if (filter.accept(file)) Some(new File(fileName)) else None
})
}
fileTreeView.list(file.toPath, 0, typedPathFilter).map(_.toPath.toFile)
}
}

Expand Down Expand Up @@ -501,16 +498,15 @@ private object DescendantOrSelfPathFinder {
Integer.MAX_VALUE,
new Filter[com.swoval.files.TypedPath] {
override def accept(t: com.swoval.files.TypedPath): Boolean = {
val file = new File(t.getPath.toString) {
filter.accept(new File(t.getPath.toString) {
override def isDirectory: Boolean = t.isDirectory

override def isFile: Boolean = t.isFile
}
if (filter.accept(file)) fileSet.add(t.getPath.toFile)
t.isDirectory // We need to accept directories for recursive traversal to work
})
}
}
)
.asScala
.foreach(tp => fileSet += tp.getPath.toFile)
val typedFile = new File(file.toString) {
override def isDirectory: Boolean = true
override def isFile: Boolean = false
Expand Down
24 changes: 24 additions & 0 deletions io/src/test/scala/sbt/io/FileTreeViewSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sbt.io

import java.nio.file._
import org.scalatest.FlatSpec
import sbt.io.FileTreeView.AllPass

class FileTreeViewSpec extends FlatSpec {
val view = FileTreeView.DEFAULT
"FileTreeView" should "return the source root with depth == -1" in IO.withTemporaryDirectory {
dir =>
assert(view.list(dir.toPath, -1, AllPass).map(_.toPath) == Seq(dir.toPath))
}
"FileTreeView" should "not return the source root with depth >= 0" in IO.withTemporaryDirectory {
dir =>
assert(view.list(dir.toPath, 0, AllPass).isEmpty)
assert(view.list(dir.toPath, 10, AllPass).isEmpty)
}
"FileTreeView" should "get recursive files" in IO.withTemporaryDirectory { dir =>
val subdir = Files.createDirectory(dir.toPath.resolve("subdir"))
val nestedSubdir = Files.createDirectory(subdir.resolve("nested-subdir"))
val file = Files.createFile(nestedSubdir.resolve("file"))
assert(view.list(dir.toPath, 3, (_: TypedPath).toPath == file).map(_.toPath) == Seq(file))
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ object Dependencies {
val scalatest = "org.scalatest" %% "scalatest" % "3.0.6-SNAP3"
val jna = "net.java.dev.jna" % "jna" % "4.5.0"
val jnaPlatform = "net.java.dev.jna" % "jna-platform" % "4.5.0"
val swovalFiles = "com.swoval" % "file-tree-views" % "2.0.5"
val swovalFiles = "com.swoval" % "file-tree-views" % "2.0.6"
}

0 comments on commit 277853c

Please sign in to comment.