Don't expose TypedPath to users

I've decided I don't like the TypedPath interface so I'm not going to
expose it publicly.
This commit is contained in:
Ethan Atkins 2019-03-20 13:59:02 -07:00
parent 6a5f0f2af2
commit 86200345e1
4 changed files with 17 additions and 17 deletions

View File

@ -8,7 +8,7 @@
package sbt package sbt
import java.io.{ File, InputStream } import java.io.{ File, InputStream }
import java.nio.file.FileSystems import java.nio.file.{ FileSystems, Path }
import sbt.BasicCommandStrings.{ import sbt.BasicCommandStrings.{
ContinuousExecutePrefix, ContinuousExecutePrefix,
@ -366,7 +366,7 @@ object Watched {
action action
case (Trigger, Some(event)) => case (Trigger, Some(event)) =>
logger.debug(s"Triggered by ${event.entry.typedPath.toPath}") logger.debug(s"Triggered by ${event.entry.typedPath.toPath}")
config.triggeredMessage(event.entry.typedPath, count).foreach(info) config.triggeredMessage(event.entry.typedPath.toPath, count).foreach(info)
Trigger Trigger
case (Reload, Some(event)) => case (Reload, Some(event)) =>
logger.info(s"Reload triggered by ${event.entry.typedPath.toPath}") logger.info(s"Reload triggered by ${event.entry.typedPath.toPath}")
@ -494,11 +494,11 @@ trait WatchConfig {
/** /**
* The optional message to log when a build is triggered. * The optional message to log when a build is triggered.
* @param typedPath the path that triggered the build * @param path the path that triggered the vuild
* @param count the current iteration * @param count the current iteration
* @return an optional log message. * @return an optional log message.
*/ */
def triggeredMessage(typedPath: TypedPath, count: Int): Option[String] def triggeredMessage(path: Path, count: Int): Option[String]
/** /**
* The optional message to log before each watch iteration. * The optional message to log before each watch iteration.
@ -542,7 +542,7 @@ object WatchConfig {
preWatch: (Int, Boolean) => Watched.Action, preWatch: (Int, Boolean) => Watched.Action,
onWatchEvent: Event[FileCacheEntry] => Watched.Action, onWatchEvent: Event[FileCacheEntry] => Watched.Action,
onWatchTerminated: (Watched.Action, String, State) => State, onWatchTerminated: (Watched.Action, String, State) => State,
triggeredMessage: (TypedPath, Int) => Option[String], triggeredMessage: (Path, Int) => Option[String],
watchingMessage: Int => Option[String] watchingMessage: Int => Option[String]
): WatchConfig = { ): WatchConfig = {
val l = logger val l = logger
@ -562,8 +562,8 @@ object WatchConfig {
override def onWatchEvent(event: Event[FileCacheEntry]): Watched.Action = owe(event) override def onWatchEvent(event: Event[FileCacheEntry]): Watched.Action = owe(event)
override def onWatchTerminated(action: Watched.Action, command: String, state: State): State = override def onWatchTerminated(action: Watched.Action, command: String, state: State): State =
owt(action, command, state) owt(action, command, state)
override def triggeredMessage(typedPath: TypedPath, count: Int): Option[String] = override def triggeredMessage(path: Path, count: Int): Option[String] =
tm(typedPath, count) tm(path, count)
override def watchingMessage(count: Int): Option[String] = wm(count) override def watchingMessage(count: Int): Option[String] = wm(count)
} }
} }

View File

@ -8,7 +8,7 @@
package sbt package sbt
import java.io.{ File, InputStream } import java.io.{ File, InputStream }
import java.nio.file.Files import java.nio.file.{ Files, Path }
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import org.scalatest.{ FlatSpec, Matchers } import org.scalatest.{ FlatSpec, Matchers }
@ -32,7 +32,7 @@ class WatchedSpec extends FlatSpec with Matchers {
handleInput: InputStream => Action = _ => Ignore, handleInput: InputStream => Action = _ => Ignore,
preWatch: (Int, Boolean) => Action = (_, _) => CancelWatch, preWatch: (Int, Boolean) => Action = (_, _) => CancelWatch,
onWatchEvent: Event[FileCacheEntry] => Action = _ => Ignore, onWatchEvent: Event[FileCacheEntry] => Action = _ => Ignore,
triggeredMessage: (TypedPath, Int) => Option[String] = (_, _) => None, triggeredMessage: (Path, Int) => Option[String] = (_, _) => None,
watchingMessage: Int => Option[String] = _ => None watchingMessage: Int => Option[String] = _ => None
): WatchConfig = { ): WatchConfig = {
val monitor = fileEventMonitor.getOrElse { val monitor = fileEventMonitor.getOrElse {
@ -81,7 +81,7 @@ class WatchedSpec extends FlatSpec with Matchers {
} }
it should "filter events" in IO.withTemporaryDirectory { dir => it should "filter events" in IO.withTemporaryDirectory { dir =>
val realDir = dir.toRealPath val realDir = dir.toRealPath
val queue = new mutable.Queue[TypedPath] val queue = new mutable.Queue[Path]
val foo = realDir.toPath.resolve("foo") val foo = realDir.toPath.resolve("foo")
val bar = realDir.toPath.resolve("bar") val bar = realDir.toPath.resolve("bar")
val config = Defaults.config( val config = Defaults.config(
@ -92,11 +92,11 @@ class WatchedSpec extends FlatSpec with Matchers {
watchingMessage = _ => { Files.createFile(bar); Thread.sleep(5); Files.createFile(foo); None } watchingMessage = _ => { Files.createFile(bar); Thread.sleep(5); Files.createFile(foo); None }
) )
Watched.watch(NullInputStream, () => Right(true), config) shouldBe CancelWatch Watched.watch(NullInputStream, () => Right(true), config) shouldBe CancelWatch
queue.toIndexedSeq.map(_.toPath) shouldBe Seq(foo) queue.toIndexedSeq shouldBe Seq(foo)
} }
it should "enforce anti-entropy" in IO.withTemporaryDirectory { dir => it should "enforce anti-entropy" in IO.withTemporaryDirectory { dir =>
val realDir = dir.toRealPath val realDir = dir.toRealPath
val queue = new mutable.Queue[TypedPath] val queue = new mutable.Queue[Path]
val foo = realDir.toPath.resolve("foo") val foo = realDir.toPath.resolve("foo")
val bar = realDir.toPath.resolve("bar") val bar = realDir.toPath.resolve("bar")
val config = Defaults.config( val config = Defaults.config(
@ -116,7 +116,7 @@ class WatchedSpec extends FlatSpec with Matchers {
} }
) )
Watched.watch(NullInputStream, () => Right(true), config) shouldBe CancelWatch Watched.watch(NullInputStream, () => Right(true), config) shouldBe CancelWatch
queue.toIndexedSeq.map(_.toPath) shouldBe Seq(bar, foo) queue.toIndexedSeq shouldBe Seq(bar, foo)
} }
it should "halt on error" in IO.withTemporaryDirectory { dir => it should "halt on error" in IO.withTemporaryDirectory { dir =>
val halted = new AtomicBoolean(false) val halted = new AtomicBoolean(false)

View File

@ -9,6 +9,7 @@ package sbt
import java.io.{ File, PrintWriter } import java.io.{ File, PrintWriter }
import java.net.{ URI, URL } import java.net.{ URI, URL }
import java.nio.file.{ Path => NioPath }
import java.util.Optional import java.util.Optional
import java.util.concurrent.{ Callable, TimeUnit } import java.util.concurrent.{ Callable, TimeUnit }
@ -641,9 +642,7 @@ object Defaults extends BuildCommon {
.map(w => (count: Int) => Some(w(WatchState.empty(globs).withCount(count)))) .map(w => (count: Int) => Some(w(WatchState.empty(globs).withCount(count))))
.getOrElse(watchStartMessage.value) .getOrElse(watchStartMessage.value)
val tm = triggeredMessage.?.value val tm = triggeredMessage.?.value
.map( .map(tm => (_: NioPath, count: Int) => Some(tm(WatchState.empty(globs).withCount(count))))
tm => (_: TypedPath, count: Int) => Some(tm(WatchState.empty(globs).withCount(count)))
)
.getOrElse(watchTriggeredMessage.value) .getOrElse(watchTriggeredMessage.value)
val logger = watchLogger.value val logger = watchLogger.value
val repo = FileManagement.toMonitoringRepository(FileManagement.repo.value) val repo = FileManagement.toMonitoringRepository(FileManagement.repo.value)

View File

@ -9,6 +9,7 @@ package sbt
import java.io.{ File, InputStream } import java.io.{ File, InputStream }
import java.net.URL import java.net.URL
import java.nio.file.Path
import org.apache.ivy.core.module.descriptor.ModuleDescriptor import org.apache.ivy.core.module.descriptor.ModuleDescriptor
import org.apache.ivy.core.module.id.ModuleRevisionId import org.apache.ivy.core.module.id.ModuleRevisionId
@ -110,7 +111,7 @@ object Keys {
val watchSources = taskKey[Seq[Watched.WatchSource]]("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 watchStartMessage = settingKey[Int => Option[String]]("The message to show when triggered execution waits for sources to change. The parameter is the current watch iteration count.").withRank(DSetting) val watchStartMessage = settingKey[Int => Option[String]]("The message to show when triggered execution waits for sources to change. The parameter is the current watch iteration count.").withRank(DSetting)
val watchTransitiveSources = taskKey[Seq[Watched.WatchSource]]("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 watchTriggeredMessage = settingKey[(TypedPath, Int) => Option[String]]("The message to show before triggered execution executes an action after sources change. The parameters are the path that triggered the build and the current watch iteration count.").withRank(DSetting) val watchTriggeredMessage = settingKey[(Path, Int) => Option[String]]("The message to show before triggered execution executes an action after sources change. The parameters are the path that triggered the build and the current watch iteration count.").withRank(DSetting)
@deprecated("Use watchStartMessage instead", "1.3.0") @deprecated("Use watchStartMessage instead", "1.3.0")
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)
@deprecated("Use watchTriggeredMessage instead", "1.3.0") @deprecated("Use watchTriggeredMessage instead", "1.3.0")