Merge pull request #4758 from eatkins/play-run

Restore some legacy watch behavior for play run
This commit is contained in:
Ethan Atkins 2019-06-01 18:33:58 -07:00 committed by GitHub
commit 9466369211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 4 deletions

View File

@ -329,9 +329,11 @@ private[sbt] object Continuous extends DeprecatedContinuous {
try {
val stateWithRepo = state.put(globalFileTreeRepository, repo)
val fullState =
if (extracted.get(watchPersistFileStamps))
stateWithRepo.put(persistentFileStampCache, fileStampCache)
else stateWithRepo
addLegacyWatchSetting(
if (extracted.get(watchPersistFileStamps))
stateWithRepo.put(persistentFileStampCache, fileStampCache)
else stateWithRepo
)
setup(fullState, command) { (commands, s, valid, invalid) =>
EvaluateTask.withStreams(extracted.structure, s)(_.use(streams in Global) { streams =>
implicit val logger: Logger = streams.log
@ -344,6 +346,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
currentCount.getAndIncrement()
// abort as soon as one of the tasks fails
valid.takeWhile(_._3.apply())
updateLegacyWatchState(s, configs.flatMap(_.inputs().map(_.glob)), currentCount.get())
()
}
callbacks.onEnter()

View File

@ -8,8 +8,12 @@
package sbt.internal
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicReference
import sbt.internal.io.{ WatchState => WS }
import sbt.{ 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 =
@ -18,6 +22,38 @@ private[internal] trait DeprecatedContinuous {
protected type DeprecatedWatchState = WS
protected val deprecatedWatchingMessage = sbt.Keys.watchingMessage
protected val deprecatedTriggeredMessage = sbt.Keys.triggeredMessage
protected def watchState(globs: Seq[Glob], count: Int): WS = {
WS.empty(globs).withCount(count)
}
private[this] val legacyWatchState =
AttributeKey[AtomicReference[WS]]("legacy-watch-state", Int.MaxValue)
protected def addLegacyWatchSetting(state: State): State = {
val legacyState = new AtomicReference[WS](WS.empty(Nil).withCount(1))
state
.put(
Watched.ContinuousEventMonitor,
new EventMonitor {
/** Block indefinitely until the monitor receives a file event or the user stops the watch. */
override def awaitEvent(): Boolean = false
/** A snapshot of the WatchState that includes the number of build triggers and watch sources. */
override def state(): WS = legacyState.get()
override def close(): Unit = ()
}
)
.put(legacyWatchState, legacyState)
.put(Watched.Configuration, new Watched {
override def watchSources(s: State): Seq[Source] =
s.get(legacyWatchState).map(_.get.sources).getOrElse(Nil)
})
}
def updateLegacyWatchState(state: State, globs: Seq[Glob], count: Int): Unit = {
state.get(legacyWatchState).foreach { ref =>
val ws = WS.empty(globs).withCount(count)
ref.set(ws)
}
}
}
private[sbt] object DeprecatedContinuous {
private[sbt] val taskDefinitions = Seq(