Set scope for fileTreeView

It makes sense to add a scope for the `fileTreeView` key where it is
available. At the moment, there is only one `fileTreeView`
implementation but, if that changes down the road, these tasks will
automatically inherit the correct view.
This commit is contained in:
Ethan Atkins 2019-08-08 14:34:27 -07:00
parent 6700d5f77a
commit 6d482eb166
3 changed files with 11 additions and 8 deletions

View File

@ -616,7 +616,7 @@ object Defaults extends BuildCommon {
val changes = previous
.map(sbt.nio.Settings.changedFiles(_, current))
.getOrElse(FileChanges.noPrevious(current.map(_._1)))
ExternalHooks.default.value(changes)
ExternalHooks.default.value(changes, fileTreeView.value)
},
externalHooks / inputFileStamps := {
compile.value // ensures the inputFileStamps previous value is only set if compile succeeds.

View File

@ -83,7 +83,7 @@ private[sbt] object Clean {
Def.taskDyn {
val state = Keys.state.value
val extracted = Project.extract(state)
val view = fileTreeView.value
val view = (fileTreeView in scope).value
val manager = streamsManager.value
Def.task {
val excludeFilter = cleanFilter(scope).value

View File

@ -16,8 +16,8 @@ import sbt.internal.inc.ExternalLookup
import sbt.internal.inc.Stamp.equivStamp.equiv
import sbt.io.syntax._
import sbt.nio.Keys._
import sbt.nio.file.RecursiveGlob
import sbt.nio.file.syntax._
import sbt.nio.file.{ FileAttributes, FileTreeView, RecursiveGlob }
import sbt.nio.{ FileChanges, FileStamp, FileStamper }
import xsbti.compile._
import xsbti.compile.analysis.Stamp
@ -26,7 +26,8 @@ import scala.collection.JavaConverters._
private[sbt] object ExternalHooks {
private val javaHome = Option(System.getProperty("java.home")).map(Paths.get(_))
def default: Def.Initialize[sbt.Task[FileChanges => ExternalHooks]] = Def.task {
private type Func = (FileChanges, FileTreeView[(Path, FileAttributes)]) => ExternalHooks
def default: Def.Initialize[sbt.Task[Func]] = Def.task {
val unmanagedCache = unmanagedFileStampCache.value
val managedCache = managedFileStampCache.value
val cp = dependencyClasspath.value.map(_.data)
@ -35,11 +36,13 @@ private[sbt] object ExternalHooks {
managedCache.getOrElseUpdate(path, FileStamper.LastModified)
}
val classGlob = classDirectory.value.toGlob / RecursiveGlob / "*.class"
fileTreeView.value.list(classGlob).foreach {
case (path, _) => managedCache.update(path, FileStamper.LastModified)
}
val options = (compileOptions in compile).value
apply(_, options, unmanagedCache, managedCache)
(fc: FileChanges, fileTreeView: FileTreeView[(Path, FileAttributes)]) => {
fileTreeView.list(classGlob).foreach {
case (path, _) => managedCache.update(path, FileStamper.LastModified)
}
apply(fc, options, unmanagedCache, managedCache)
}
}
private def apply(
changedFiles: FileChanges,