From 1ab666daf4d6faf456922a2920126c8ff607287c Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Mon, 3 Jun 2019 17:41:07 -0700 Subject: [PATCH] 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. --- main/src/main/scala/sbt/internal/Continuous.scala | 7 ++++--- .../main/scala/sbt/internal/DeprecatedContinuous.scala | 4 ++-- main/src/main/scala/sbt/nio/Keys.scala | 6 +++--- main/src/main/scala/sbt/nio/Watch.scala | 8 ++++---- sbt/src/sbt-test/watch/input-parser/project/Build.scala | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index 94fe88a4a..f212e5b64 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -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) diff --git a/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala b/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala index 1db908859..2bffd0801 100644 --- a/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala +++ b/main/src/main/scala/sbt/internal/DeprecatedContinuous.scala @@ -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 diff --git a/main/src/main/scala/sbt/nio/Keys.scala b/main/src/main/scala/sbt/nio/Keys.scala index b85271515..a0c452777 100644 --- a/main/src/main/scala/sbt/nio/Keys.scala +++ b/main/src/main/scala/sbt/nio/Keys.scala @@ -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. diff --git a/main/src/main/scala/sbt/nio/Watch.scala b/main/src/main/scala/sbt/nio/Watch.scala index 5fd1f11a6..82bae33f8 100644 --- a/main/src/main/scala/sbt/nio/Watch.scala +++ b/main/src/main/scala/sbt/nio/Watch.scala @@ -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") diff --git a/sbt/src/sbt-test/watch/input-parser/project/Build.scala b/sbt/src/sbt-test/watch/input-parser/project/Build.scala index 8f61bb413..eb30bc8d8 100644 --- a/sbt/src/sbt-test/watch/input-parser/project/Build.scala +++ b/sbt/src/sbt-test/watch/input-parser/project/Build.scala @@ -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")