From 69be8796847dc1fa42434ab4a111aeeb60a94c75 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sat, 24 Oct 2020 10:07:13 -0700 Subject: [PATCH] Reinstate watchBeforeCommand callback A user reported that the watchBeforeCommand callback was not being invoked in sbt 1.4.{0, 1}. This was an oversight that occurred when refactoring watch for the thin client and there previously had been no regression test for that callback. --- main/src/main/scala/sbt/internal/Continuous.scala | 5 ++++- sbt/src/sbt-test/watch/before-command/build.sbt | 5 +++++ sbt/src/sbt-test/watch/before-command/test | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 sbt/src/sbt-test/watch/before-command/build.sbt create mode 100644 sbt/src/sbt-test/watch/before-command/test diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index bd8c4de9e..1a6790c76 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -1327,7 +1327,10 @@ private[sbt] object ContinuousCommands { } private[sbt] val preWatchCommand = watchCommand(preWatch) { (channel, state) => - watchState(state, channel).beforeCommand(state) + val ws = watchState(state, channel) + val newState = ws.beforeCommand(state) + ws.callbacks.beforeCommand() + newState } private[sbt] val postWatchCommand = watchCommand(postWatch) { (channel, state) => val cs = watchState(state, channel) diff --git a/sbt/src/sbt-test/watch/before-command/build.sbt b/sbt/src/sbt-test/watch/before-command/build.sbt new file mode 100644 index 000000000..34d88a1f9 --- /dev/null +++ b/sbt/src/sbt-test/watch/before-command/build.sbt @@ -0,0 +1,5 @@ +import java.nio.file.{ Files, Paths } + +watchBeforeCommand := { () => Files.write(Paths.get("foo"), "foo".getBytes) } + +watchOnIteration := { (_, _, _) => sbt.nio.Watch.CancelWatch } diff --git a/sbt/src/sbt-test/watch/before-command/test b/sbt/src/sbt-test/watch/before-command/test new file mode 100644 index 000000000..5bfcff311 --- /dev/null +++ b/sbt/src/sbt-test/watch/before-command/test @@ -0,0 +1,3 @@ +> ~compile + +$ exists foo