From 41c33ba92f08cdc37b46b14914a9774c4a16373a Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 23 Aug 2020 08:52:47 -0700 Subject: [PATCH] Fix intellij import with 1.4.x The intellij import currentlly works by forking an sbt process and writing command input through the process input stream. To make this work, we need the SimpleTerminal (which is used when sbt is run with -Dsbt.log.noformat=true) to be able to read input. Attaching the input to the simple terminal caused watch tests to fail on windows. This can be fixed by checking if the byte read from the input stream is -1 and ignoring it if so. --- .../src/main/scala/sbt/internal/util/Terminal.scala | 1 + main/src/main/scala/sbt/internal/Continuous.scala | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/util-logging/src/main/scala/sbt/internal/util/Terminal.scala b/internal/util-logging/src/main/scala/sbt/internal/util/Terminal.scala index 1e77bf328..d44b7b91d 100644 --- a/internal/util-logging/src/main/scala/sbt/internal/util/Terminal.scala +++ b/internal/util-logging/src/main/scala/sbt/internal/util/Terminal.scala @@ -993,6 +993,7 @@ object Terminal { } private[sbt] object NullTerminal extends DefaultTerminal private[sbt] object SimpleTerminal extends DefaultTerminal { + override lazy val inputStream: InputStream = nonBlockingIn override lazy val outputStream: OutputStream = originalOut override lazy val errorStream: OutputStream = originalErr } diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index e7ec8c644..c97cbfe16 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -729,7 +729,6 @@ private[sbt] object Continuous extends DeprecatedContinuous { * to a state where it does not parse an action, we can wait until we receive new input * to attempt to parse again. */ - type ActionParser = String => Watch.Action // Transform the Config.watchSettings.inputParser instances to functions of type // String => Watch.Action. The String that is provided will contain any characters that // have been read from stdin. If there are any characters available, then it calls the @@ -766,9 +765,10 @@ private[sbt] object Continuous extends DeprecatedContinuous { val action = try { interrupted.set(false) - val byte = terminal.inputStream.read - val parse: ActionParser => Watch.Action = parser => parser(byte.toChar.toString) - parse(inputHandler) + terminal.inputStream.read match { + case -1 => Watch.Ignore + case byte => inputHandler(byte.toChar.toString) + } } catch { case _: InterruptedException => interrupted.set(true)