diff --git a/main-command/src/main/scala/sbt/Watched.scala b/main-command/src/main/scala/sbt/Watched.scala index e6b851d14..082f4374d 100644 --- a/main-command/src/main/scala/sbt/Watched.scala +++ b/main-command/src/main/scala/sbt/Watched.scala @@ -21,7 +21,7 @@ import sbt.internal.LegacyWatched import sbt.internal.inc.Stamper import sbt.internal.io.{ EventMonitor, Source, WatchState } import sbt.internal.util.Types.const -import sbt.internal.util.complete.DefaultParsers +import sbt.internal.util.complete.{ DefaultParsers, Parser } import sbt.internal.util.{ AttributeKey, JLine } import sbt.io.FileEventMonitor.{ Creation, Deletion, Event, Update } import sbt.io._ @@ -279,9 +279,9 @@ object Watched { onFailure = Some(Exec(failureCommandName, None)), definedCommands = s0.definedCommands :+ onFail ) - val commands = command.split(";") match { - case Array("", rest @ _*) => rest - case Array(cmd) => Seq(cmd) + val commands = Parser.parse(command, BasicCommands.multiParserImpl(Some(s))) match { + case Left(_) => command :: Nil + case Right(c) => c } val parser = Command.combine(s.definedCommands)(s) val tasks = commands.foldLeft(Nil: Seq[Either[String, () => Either[Exception, Boolean]]]) { diff --git a/sbt/src/sbt-test/watch/watch-parser/build.sbt b/sbt/src/sbt-test/watch/watch-parser/build.sbt new file mode 100644 index 000000000..c29f61af0 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-parser/build.sbt @@ -0,0 +1,13 @@ +import Build._ + +organization := "sbt" + +name := "scripted-watch-parser" + +setStringValue := setStringValueImpl.evaluated + +checkStringValue := checkStringValueImpl.evaluated + +watchSources += file("string.txt") + +watchOnEvent := { _ => Watched.CancelWatch } diff --git a/sbt/src/sbt-test/watch/watch-parser/project/Build.scala b/sbt/src/sbt-test/watch/watch-parser/project/Build.scala new file mode 100644 index 000000000..19380e885 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-parser/project/Build.scala @@ -0,0 +1,16 @@ +import sbt._ + +object Build { + private[this] var string: String = "" + private[this] val stringFile = file("string.txt") + val setStringValue = inputKey[Unit]("set a global string to a value") + val checkStringValue = inputKey[Unit]("check the value of a global") + def setStringValueImpl: Def.Initialize[InputTask[Unit]] = Def.inputTask { + string = Def.spaceDelimited().parsed.mkString(" ").trim + IO.write(stringFile, string) + } + def checkStringValueImpl: Def.Initialize[InputTask[Unit]] = Def.inputTask { + assert(string == Def.spaceDelimited().parsed.mkString(" ").trim) + assert(IO.read(stringFile) == string) + } +} \ No newline at end of file diff --git a/sbt/src/sbt-test/watch/watch-parser/test b/sbt/src/sbt-test/watch/watch-parser/test new file mode 100644 index 000000000..f14bef5e1 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-parser/test @@ -0,0 +1,18 @@ +> ~; setStringValue foo; setStringValue bar + +> checkStringValue bar + +> ~;setStringValue foo;setStringValue bar; checkStringValue bar + +> ~; setStringValue foo;setStringValue bar; checkStringValue bar + +> ~; setStringValue foo; setStringValue bar; checkStringValue bar + +> ~ setStringValue foo + +> checkStringValue foo + +# All of the other tests have involved input tasks, so include commands with regular tasks as well. +> ~; compile; setStringValue baz; checkStringValue baz +# No trailing semicolons are allowed +-> ~; compile; setStringValue baz; checkStringValue baz;