Fix console with -Dsbt.ci=true

If a user runs sbt -Dsbt.ci=true with the latest code, sbt immediately
exits. This was because we were passing the SimpleTerminal into jline3
and jline 3 would end up exiting immediately. Instead we can still make
a console terminal if there is a console available. An alternative
approach would have been to use a dumb terminal with -Dsbt.ci=true, but
the dumb terminal experience is not great (tab completions don't work
for example), so I thought this was a better fix.
This commit is contained in:
Ethan Atkins 2020-11-05 09:55:15 -08:00
parent e5164cdf43
commit c1fcf5c531
1 changed files with 4 additions and 12 deletions

View File

@ -334,11 +334,11 @@ object Terminal {
* @tparam T the result type of the thunk
* @return the result of the thunk
*/
private[sbt] def withStreams[T](isServer: Boolean)(f: => T): T =
private[sbt] def withStreams[T](isServer: Boolean)(f: => T): T = {
// In ci environments, don't touch the io streams unless run with -Dsbt.io.virtual=true
if (hasConsole && !isDumbTerminal) consoleTerminalHolder.set(newConsoleTerminal())
if (System.getProperty("sbt.io.virtual", "") == "true" || !isCI) {
hasProgress.set(isServer && isAnsiSupported)
if (hasConsole && !isDumbTerminal) consoleTerminalHolder.set(newConsoleTerminal())
activeTerminal.set(consoleTerminalHolder.get)
try withOut(withIn(f))
finally {
@ -372,6 +372,7 @@ object Terminal {
}
}
} else f
}
private[this] object ProxyTerminal extends Terminal {
private def t: Terminal = activeTerminal.get
@ -1006,17 +1007,8 @@ object Terminal {
}
private[sbt] object NullTerminal extends DefaultTerminal
private[sbt] object SimpleTerminal extends DefaultTerminal {
override lazy val inputStream: InputStream =
if (isCI) BlockingInputStream
else originalIn
override lazy val inputStream: InputStream = originalIn
override lazy val outputStream: OutputStream = originalOut
override lazy val errorStream: OutputStream = originalErr
}
private[this] object BlockingInputStream extends SimpleInputStream {
override def read(): Int = {
try this.synchronized(this.wait)
catch { case _: InterruptedException => }
-1
}
}
}