From 5815f1db0ae109380818423933075be5e1be997d Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Mon, 14 Aug 2017 15:09:10 +0200 Subject: [PATCH 1/2] `Append` instance to add `File` to `Seq[Source]` --- main-settings/src/main/scala/sbt/Append.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main-settings/src/main/scala/sbt/Append.scala b/main-settings/src/main/scala/sbt/Append.scala index 4b2c1987f..bb50f52fa 100644 --- a/main-settings/src/main/scala/sbt/Append.scala +++ b/main-settings/src/main/scala/sbt/Append.scala @@ -6,6 +6,8 @@ import scala.annotation.implicitNotFound import sbt.internal.util.Attributed import Def.Initialize import reflect.internal.annotations.compileTimeOnly +import sbt.internal.io.Source +import sbt.io.{ AllPassFilter, NothingFilter } object Append { @implicitNotFound( @@ -96,4 +98,11 @@ object Append { 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 :+ _) } + 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)) + } } From c1b86c7534a937de9f5843fd292d02f4b83eb335 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Fri, 18 Aug 2017 15:51:53 +0200 Subject: [PATCH 2/2] Address review comments --- main-command/src/main/scala/sbt/Watched.scala | 29 +++++++++++++++++-- main/src/main/scala/sbt/Keys.scala | 6 ++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/main-command/src/main/scala/sbt/Watched.scala b/main-command/src/main/scala/sbt/Watched.scala index d65a32708..08a1c5838 100644 --- a/main-command/src/main/scala/sbt/Watched.scala +++ b/main-command/src/main/scala/sbt/Watched.scala @@ -6,11 +6,12 @@ package sbt import BasicCommandStrings.ClearOnFailure import State.FailureWall import annotation.tailrec +import java.io.File import java.nio.file.FileSystems 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.util.AttributeKey import sbt.internal.util.Types.const @@ -18,7 +19,7 @@ import sbt.internal.util.Types.const trait Watched { /** 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) /** @@ -44,6 +45,30 @@ object Watched { val clearWhenTriggered: WatchState => String = const(clearScreen) 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 def multi(base: Watched, paths: Seq[Watched]): Watched = diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index d85a131fc..a011fd938 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -37,7 +37,7 @@ import sbt.internal.{ LogManager } import sbt.io.{ FileFilter, WatchService } -import sbt.internal.io.{ Source, WatchState } +import sbt.internal.io.WatchState import sbt.internal.util.{ AttributeKey, SourcePosition } 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 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 watchSources = taskKey[Seq[Source]]("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 watchSources = taskKey[Seq[Watched.WatchSource]]("Defines the sources in this project for continuous execution to watch for changes.").withRank(BMinusSetting) + 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 triggeredMessage = settingKey[WatchState => String]("The message to show before triggered execution executes an action after sources change.").withRank(DSetting)