From 875a25c929985ad671b30d723519f4c4a31327f8 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Tue, 11 Jun 2019 16:20:46 -0700 Subject: [PATCH] Use project watchStartMessage for multi commands It didn't make sense to aggregate the watch start command if it was defined in multiple sources so we previously just fell back to the default message if multiple commands were being run. This, however, meant that if you ran, say, ~compile in an aggregate project, it wasn't possible to customize the start message. There was a message in the sbt gitter channel where someone found the new message too verbose and wanted to print something shorter and I realized that this was an unfortunate restriction. Instead of giving up, we can just use the project's watchStartMessage as a default. If the watchStartMessage setting is unset for some reason, we can fall back to the default. I validated this change manually in the swoval project, which has an aggregate root project, by running set ThisBuild / watchStartMessage := { (_, _, _) => None } and indeed nothing was printed after each task evaluation in '~compile'. --- main/src/main/scala/sbt/internal/Continuous.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index 890f82a80..4b70ccd83 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -469,7 +469,8 @@ private[sbt] object Continuous extends DeprecatedContinuous { 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) + val onStart: () => Watch.Action = + getOnStart(project, commands, configs, rawLogger, count, extracted) val nextInputEvent: () => Watch.Action = parseInputEvents(configs, state, inputStream, logger) val (nextFileEvent, cleanupFileMonitor): (() => Option[(Watch.Event, Watch.Action)], () => Unit) = getFileEvents(configs, rawLogger, state, count, commands, fileStampCache) @@ -501,7 +502,8 @@ private[sbt] object Continuous extends DeprecatedContinuous { commands: Seq[String], configs: Seq[Config], logger: Logger, - count: AtomicInteger + count: AtomicInteger, + extracted: Extracted, ): () => Watch.Action = { val f: () => Seq[Watch.Action] = () => { configs.map { params => @@ -522,8 +524,11 @@ private[sbt] object Continuous extends DeprecatedContinuous { () => { val res = f().min // Print the default watch message if there are multiple tasks - if (configs.size > 1) - Watch.defaultStartWatch(count.get(), project, commands).foreach(logger.info(_)) + if (configs.size > 1) { + val onStartWatch = + extracted.getOpt(watchStartMessage in project).getOrElse(Watch.defaultStartWatch) + onStartWatch(count.get(), project, commands).foreach(logger.info(_)) + } res } }