Change signature of pre watch methods

It makes the method parameters more clear if we pass in the ProjectRef
rather than the project name. We also don't lose information.
This commit is contained in:
Ethan Atkins 2019-06-03 17:41:07 -07:00
parent 05aab1035a
commit 1ab666daf4
5 changed files with 15 additions and 14 deletions

View File

@ -466,7 +466,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
)(
implicit extracted: Extracted
): Callbacks = {
val project = extracted.currentRef.project
val project = extracted.currentRef
val logger = setLevel(rawLogger, configs.map(_.watchSettings.logLevel).min, state)
val beforeCommand = () => configs.foreach(_.watchSettings.beforeCommand())
val onStart: () => Watch.Action = getOnStart(project, commands, configs, rawLogger, count)
@ -497,7 +497,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
}
private def getOnStart(
project: String,
project: ProjectRef,
commands: Seq[String],
configs: Seq[Config],
logger: Logger,
@ -900,7 +900,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
val beforeCommand: () => Unit = key.get(watchBeforeCommand).getOrElse(() => {})
val onFileInputEvent: WatchOnEvent =
key.get(watchOnFileInputEvent).getOrElse(Watch.trigger)
val onIteration: Option[(Int, String, Seq[String]) => Watch.Action] = key.get(watchOnIteration)
val onIteration: Option[(Int, ProjectRef, Seq[String]) => Watch.Action] =
key.get(watchOnIteration)
val onTermination: Option[(Watch.Action, String, Int, State) => State] =
key.get(watchOnTermination)
val startMessage: StartMessage = getStartMessage(key)

View File

@ -10,14 +10,14 @@ package sbt.internal
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicReference
import sbt.{ State, Watched }
import sbt.{ ProjectRef, State, Watched }
import sbt.internal.io.{ EventMonitor, Source, WatchState => WS }
import sbt.internal.util.AttributeKey
import sbt.nio.file.Glob
private[internal] trait DeprecatedContinuous {
protected type StartMessage =
Option[Either[WS => String, (Int, String, Seq[String]) => Option[String]]]
Option[Either[WS => String, (Int, ProjectRef, Seq[String]) => Option[String]]]
protected type TriggerMessage = Either[WS => String, (Int, Path, Seq[String]) => Option[String]]
protected type DeprecatedWatchState = WS
protected val deprecatedWatchingMessage = sbt.Keys.watchingMessage

View File

@ -18,7 +18,7 @@ import sbt.internal.nio.FileTreeRepository
import sbt.internal.util.AttributeKey
import sbt.internal.util.complete.Parser
import sbt.nio.file.{ ChangedFiles, FileAttributes, FileTreeView, Glob }
import sbt.{ Def, InputKey, State, StateTransform }
import sbt.{ Def, InputKey, ProjectRef, State, StateTransform }
import scala.concurrent.duration.FiniteDuration
@ -88,7 +88,7 @@ object Keys {
val watchOnFileInputEvent = settingKey[(Int, Watch.Event) => Watch.Action](
"Callback to invoke if an event is triggered in a continuous build by one of the files matching an fileInput glob for the task and its transitive dependencies"
).withRank(DSetting)
val watchOnIteration = settingKey[(Int, String, Seq[String]) => Watch.Action](
val watchOnIteration = settingKey[(Int, ProjectRef, Seq[String]) => Watch.Action](
"Function that is invoked before waiting for file system events or user input events."
).withRank(DSetting)
val watchOnTermination = settingKey[(Watch.Action, String, Int, State) => State](
@ -97,7 +97,7 @@ object Keys {
val watchPersistFileStamps = settingKey[Boolean](
"Toggles whether or not the continuous build will reuse the file stamps computed in previous runs. Setting this to true decrease watch startup latency but could cause inconsistent results if many source files are concurrently modified."
).withRank(DSetting)
val watchStartMessage = settingKey[(Int, String, Seq[String]) => Option[String]](
val watchStartMessage = settingKey[(Int, ProjectRef, Seq[String]) => Option[String]](
"The message to show when triggered execution waits for sources to change. The parameters are the current watch iteration count, the current project name and the tasks that are being run with each build."
).withRank(DSetting)
// The watchTasks key should really be named watch, but that is already taken by the deprecated watch key. I'd be surprised if there are any plugins that use it so I think we should consider breaking binary compatibility to rename this task.

View File

@ -401,19 +401,19 @@ object Watch {
)
s"Options:\n${opts.mkString(" ", "\n ", "")}"
}
private def waitMessage(project: String, commands: Seq[String]): String = {
private def waitMessage(project: ProjectRef, commands: Seq[String]): String = {
val plural = if (commands.size > 1) "s" else ""
val cmds = commands.mkString("; ")
s"Monitoring source files for updates...\n" +
s"Project: $project\nCommand$plural: $cmds\n$options"
s"Project: ${project.project}\nCommand$plural: $cmds\n$options"
}
/**
* A function that prints out the current iteration count and gives instructions for exiting
* or triggering the build.
*/
val defaultStartWatch: (Int, String, Seq[String]) => Option[String] = {
(count: Int, project: String, commands: Seq[String]) =>
val defaultStartWatch: (Int, ProjectRef, Seq[String]) => Option[String] = {
(count: Int, project: ProjectRef, commands: Seq[String]) =>
Some(s"$count. ${waitMessage(project, commands)}")
}.label("Watched.defaultStartWatch")

View File

@ -25,12 +25,12 @@ object Build {
// Note that the order is byeParser | helloParser. In general, we want the higher priority
// action to come first because otherwise we would potentially scan past it.
val helloOrByeParser: Parser[Watch.Action] = byeParser | helloParser
val alternativeStartMessage: (Int, String, Seq[String]) => Option[String] = { (_, _, _) =>
val alternativeStartMessage: (Int, ProjectRef, Seq[String]) => Option[String] = { (_, _, _) =>
outputStream.write("xybyexyblahxyhelloxy".getBytes)
outputStream.flush()
Some("alternative start message")
}
val otherAlternativeStartMessage: (Int, String, Seq[String]) => Option[String] = { (_, _, _) =>
val otherAlternativeStartMessage: (Int, ProjectRef, Seq[String]) => Option[String] = { (_, _, _) =>
outputStream.write("xyhellobyexyblahx".getBytes)
outputStream.flush()
Some("other alternative start message")