Merge pull request #3438 from Duhemm/source-appender

[1.0.x] `Append` instance to add `File` to `Seq[Source]`
This commit is contained in:
eugene yokota 2017-08-23 18:31:58 -04:00 committed by GitHub
commit 33d3ba9d7c
3 changed files with 39 additions and 5 deletions

View File

@ -6,11 +6,12 @@ package sbt
import BasicCommandStrings.ClearOnFailure import BasicCommandStrings.ClearOnFailure
import State.FailureWall import State.FailureWall
import annotation.tailrec import annotation.tailrec
import java.io.File
import java.nio.file.FileSystems import java.nio.file.FileSystems
import scala.concurrent.duration._ import scala.concurrent.duration._
import sbt.io.WatchService import sbt.io.{ AllPassFilter, NothingFilter, FileFilter, WatchService }
import sbt.internal.io.{ Source, SourceModificationWatch, WatchState } import sbt.internal.io.{ Source, SourceModificationWatch, WatchState }
import sbt.internal.util.AttributeKey import sbt.internal.util.AttributeKey
import sbt.internal.util.Types.const import sbt.internal.util.Types.const
@ -18,7 +19,7 @@ import sbt.internal.util.Types.const
trait Watched { trait Watched {
/** The files watched when an action is run with a preceeding ~ */ /** The files watched when an action is run with a preceeding ~ */
def watchSources(s: State): Seq[Source] = Nil def watchSources(s: State): Seq[Watched.WatchSource] = Nil
def terminateWatch(key: Int): Boolean = Watched.isEnter(key) def terminateWatch(key: Int): Boolean = Watched.isEnter(key)
/** /**
@ -44,6 +45,30 @@ object Watched {
val clearWhenTriggered: WatchState => String = const(clearScreen) val clearWhenTriggered: WatchState => String = const(clearScreen)
def clearScreen: String = "\u001b[2J\u001b[0;0H" def clearScreen: String = "\u001b[2J\u001b[0;0H"
type WatchSource = Source
object WatchSource {
/**
* Creates a new `WatchSource` for watching files, with the given filters.
*
* @param base The base directory from which to include files.
* @param includeFilter Choose what children of `base` to include.
* @param excludeFilter Choose what children of `base` to exclude.
* @return An instance of `Source`.
*/
def apply(base: File, includeFilter: FileFilter, excludeFilter: FileFilter): Source =
new Source(base, includeFilter, excludeFilter)
/**
* Creates a new `WatchSource` for watching files.
*
* @param base The base directory from which to include files.
* @return An instance of `Source`.
*/
def apply(base: File): Source =
apply(base, AllPassFilter, NothingFilter)
}
private[this] class AWatched extends Watched private[this] class AWatched extends Watched
def multi(base: Watched, paths: Seq[Watched]): Watched = def multi(base: Watched, paths: Seq[Watched]): Watched =

View File

@ -6,6 +6,8 @@ import scala.annotation.implicitNotFound
import sbt.internal.util.Attributed import sbt.internal.util.Attributed
import Def.Initialize import Def.Initialize
import reflect.internal.annotations.compileTimeOnly import reflect.internal.annotations.compileTimeOnly
import sbt.internal.io.Source
import sbt.io.{ AllPassFilter, NothingFilter }
object Append { object Append {
@implicitNotFound( @implicitNotFound(
@ -96,4 +98,11 @@ object Append {
def appendValue(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a :+ _) def appendValue(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a :+ _)
def appendValues(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a :+ _) def appendValues(a: Seq[T], b: Option[T]): Seq[T] = b.fold(a)(a :+ _)
} }
implicit def appendSource: Sequence[Seq[Source], Seq[File], File] =
new Sequence[Seq[Source], Seq[File], File] {
def appendValue(a: Seq[Source], b: File): Seq[Source] =
appendValues(a, Seq(b))
def appendValues(a: Seq[Source], b: Seq[File]): Seq[Source] =
a ++ b.map(new Source(_, AllPassFilter, NothingFilter))
}
} }

View File

@ -37,7 +37,7 @@ import sbt.internal.{
LogManager LogManager
} }
import sbt.io.{ FileFilter, WatchService } import sbt.io.{ FileFilter, WatchService }
import sbt.internal.io.{ Source, WatchState } import sbt.internal.io.WatchState
import sbt.internal.util.{ AttributeKey, SourcePosition } import sbt.internal.util.{ AttributeKey, SourcePosition }
import sbt.librarymanagement.Configurations.CompilerPlugin import sbt.librarymanagement.Configurations.CompilerPlugin
@ -132,8 +132,8 @@ object Keys {
val suppressSbtShellNotification = settingKey[Boolean]("""True to suppress the "Executing in batch mode.." message.""").withRank(CSetting) val suppressSbtShellNotification = settingKey[Boolean]("""True to suppress the "Executing in batch mode.." message.""").withRank(CSetting)
val pollInterval = settingKey[FiniteDuration]("Interval between checks for modified sources by the continuous execution command.").withRank(BMinusSetting) val pollInterval = settingKey[FiniteDuration]("Interval between checks for modified sources by the continuous execution command.").withRank(BMinusSetting)
val watchService = settingKey[() => WatchService]("Service to use to monitor file system changes.").withRank(BMinusSetting) val watchService = settingKey[() => WatchService]("Service to use to monitor file system changes.").withRank(BMinusSetting)
val watchSources = taskKey[Seq[Source]]("Defines the sources in this project for continuous execution to watch for changes.").withRank(BMinusSetting) val watchSources = taskKey[Seq[Watched.WatchSource]]("Defines the sources in this project for continuous execution to watch for changes.").withRank(BMinusSetting)
val watchTransitiveSources = taskKey[Seq[Source]]("Defines the sources in all projects for continuous execution to watch.").withRank(CSetting) val watchTransitiveSources = taskKey[Seq[Watched.WatchSource]]("Defines the sources in all projects for continuous execution to watch.").withRank(CSetting)
val watchingMessage = settingKey[WatchState => String]("The message to show when triggered execution waits for sources to change.").withRank(DSetting) val watchingMessage = settingKey[WatchState => String]("The message to show when triggered execution waits for sources to change.").withRank(DSetting)
val triggeredMessage = settingKey[WatchState => String]("The message to show before triggered execution executes an action after sources change.").withRank(DSetting) val triggeredMessage = settingKey[WatchState => String]("The message to show before triggered execution executes an action after sources change.").withRank(DSetting)