diff --git a/main-command/src/main/scala/sbt/Watched.scala b/main-command/src/main/scala/sbt/Watched.scala index d697bb56c..e6b851d14 100644 --- a/main-command/src/main/scala/sbt/Watched.scala +++ b/main-command/src/main/scala/sbt/Watched.scala @@ -23,7 +23,7 @@ import sbt.internal.io.{ EventMonitor, Source, WatchState } import sbt.internal.util.Types.const import sbt.internal.util.complete.DefaultParsers import sbt.internal.util.{ AttributeKey, JLine } -import sbt.io.FileEventMonitor.Event +import sbt.io.FileEventMonitor.{ Creation, Deletion, Event, Update } import sbt.io._ import sbt.util.{ Level, Logger } import xsbti.compile.analysis.Stamp @@ -144,6 +144,18 @@ object Watched { } scanInput() } + private[sbt] def onEvent( + sources: Seq[WatchSource], + projectSources: Seq[WatchSource] + ): Event[StampedFile] => Watched.Action = + event => + if (sources.exists(_.accept(event.entry.typedPath.getPath))) Watched.Trigger + else if (projectSources.exists(_.accept(event.entry.typedPath.getPath))) event match { + case Update(prev, cur, _) if prev.value.map(_.stamp) != cur.value.map(_.stamp) => Reload + case _: Creation[_] | _: Deletion[_] => Reload + case _ => Ignore + } else Ignore + private[this] val reRun = if (isWin) "" else " or 'r' to re-run the command" private def waitMessage(project: String): String = s"Waiting for source changes$project... (press enter to interrupt$reRun)" diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 3c54cadf2..f4d329710 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -621,14 +621,8 @@ object Defaults extends BuildCommon { consoleProject := consoleProjectTask.value, watchTransitiveSources := watchTransitiveSourcesTask.value, watchProjectTransitiveSources := watchTransitiveSourcesTaskImpl(watchProjectSources).value, - watchOnEvent := { - val sources = watchTransitiveSources.value - val projectSources = watchProjectTransitiveSources.value - e => - if (sources.exists(_.accept(e.entry.typedPath.getPath))) Watched.Trigger - else if (projectSources.exists(_.accept(e.entry.typedPath.getPath))) Watched.Reload - else Watched.Ignore - }, + watchOnEvent := Watched + .onEvent(watchTransitiveSources.value, watchProjectTransitiveSources.value), watchHandleInput := Watched.handleInput, watchPreWatch := { (_, _) => Watched.Ignore