Merge pull request #3358 from sbt/wip/linereader

Keep ConsoleChannel open
This commit is contained in:
eugene yokota 2017-07-24 13:47:07 -04:00 committed by GitHub
commit 82a8ca87e1
7 changed files with 43 additions and 26 deletions

View File

@ -203,6 +203,7 @@ lazy val stdTaskProj = (project in file("tasks-standard"))
// Embedded Scala code runner
lazy val runProj = (project in file("run"))
.enablePlugins(ContrabandPlugin)
.dependsOn(collectionProj)
.settings(
testedBaseSettings,
name := "Run",
@ -335,7 +336,7 @@ lazy val mainSettingsProj = (project in file("main-settings"))
// The main integration project for sbt. It brings all of the projects together, configures them, and provides for overriding conventions.
lazy val mainProj = (project in file("main"))
.enablePlugins(ContrabandPlugin)
.dependsOn(logicProj, actionsProj, mainSettingsProj, runProj, commandProj)
.dependsOn(logicProj, actionsProj, mainSettingsProj, runProj, commandProj, collectionProj)
.settings(
testedBaseSettings,
name := "Main",

View File

@ -37,4 +37,18 @@ object Util {
Camel.replaceAllIn(s, m => m.group(1) + "-" + m.group(2).toLowerCase(Locale.ENGLISH))
def quoteIfKeyword(s: String): String = if (ScalaKeywords.values(s)) '`' + s + '`' else s
lazy val isWindows: Boolean =
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
lazy val isCygwin: Boolean = {
val os = Option(System.getenv("OSTYPE"))
os match {
case Some(x) => x.toLowerCase(Locale.ENGLISH).contains("cygwin")
case _ => false
}
}
lazy val isNonCygwinWindows: Boolean = isWindows && !isCygwin
lazy val isCygwinWindows: Boolean = isWindows && isCygwin
}

View File

@ -14,12 +14,22 @@ abstract class JLine extends LineReader {
protected[this] def handleCONT: Boolean
protected[this] def reader: ConsoleReader
protected[this] def injectThreadSleep: Boolean
protected[this] val in: InputStream = JLine.makeInputStream(injectThreadSleep)
def readLine(prompt: String, mask: Option[Char] = None) = JLine.withJLine {
unsynchronizedReadLine(prompt, mask)
protected[this] lazy val in: InputStream = {
// On Windows InputStream#available doesn't seem to return positive number.
JLine.makeInputStream(injectThreadSleep && !Util.isNonCygwinWindows)
}
def readLine(prompt: String, mask: Option[Char] = None) =
try {
JLine.withJLine {
unsynchronizedReadLine(prompt, mask)
}
} catch {
case _: InterruptedException =>
// println("readLine: InterruptedException")
Option("")
}
private[this] def unsynchronizedReadLine(prompt: String, mask: Option[Char]): Option[String] =
readLineWithHistory(prompt, mask) map { x =>
x.trim
@ -42,13 +52,9 @@ abstract class JLine extends LineReader {
private[this] def readLineDirectRaw(prompt: String, mask: Option[Char]): Option[String] = {
val newprompt = handleMultilinePrompt(prompt)
try {
mask match {
case Some(m) => Option(reader.readLine(newprompt, m))
case None => Option(reader.readLine(newprompt))
}
} catch {
case e: InterruptedException => Option("")
mask match {
case Some(m) => Option(reader.readLine(newprompt, m))
case None => Option(reader.readLine(newprompt))
}
}

View File

@ -48,7 +48,9 @@ private[sbt] final class ConsoleChannel(val name: String) extends CommandChannel
case Some(src) if src.channelName != name =>
askUserThread match {
case Some(x) =>
shutdown()
// keep listening while network-origin command is running
// make sure to test Windows and Cygwin, if you uncomment
// shutdown()
case _ =>
}
case _ =>

View File

@ -17,6 +17,7 @@ import java.util.Locale
import scala.sys.process.Process
import scala.util.control.NonFatal
import sbt.internal.util.Util
object Resolvers {
type Resolver = BuildLoader.Resolver
@ -125,20 +126,12 @@ object Resolvers {
private def normalized(uri: URI) = uri.copy(scheme = scheme)
}
private lazy val onWindows = {
val os = System.getenv("OSTYPE")
val isCygwin = (os != null) && os.toLowerCase(Locale.ENGLISH).contains("cygwin")
val isWindows =
System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).contains("windows")
isWindows && !isCygwin
}
def run(command: String*): Unit =
run(None, command: _*)
def run(cwd: Option[File], command: String*): Unit = {
val result = Process(
if (onWindows) "cmd" +: "/c" +: command
if (Util.isNonCygwinWindows) "cmd" +: "/c" +: command
else command,
cwd
) !;

View File

@ -4,9 +4,9 @@
package sbt
import java.io.File
import java.util.Locale
import scala.sys.process.Process
import OutputStrategy._
import sbt.internal.util.Util
/**
* Represents a command that can be forked.
@ -80,15 +80,13 @@ object Fork {
private[this] val MaxConcatenatedOptionLength = 5000
private def fitClasspath(options: Seq[String]): (Option[String], Seq[String]) =
if (isWindows && optionsTooLong(options))
if (Util.isWindows && optionsTooLong(options))
convertClasspathToEnv(options)
else
(None, options)
private[this] def optionsTooLong(options: Seq[String]): Boolean =
options.mkString(" ").length > MaxConcatenatedOptionLength
private[this] val isWindows: Boolean =
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
private[this] def convertClasspathToEnv(options: Seq[String]): (Option[String], Seq[String]) = {
val (preCP, cpAndPost) = options.span(opt => !isClasspathOption(opt))
val postCP = cpAndPost.drop(2)

View File

@ -6,3 +6,6 @@
{ "type": "ExecCommand", "commandLine": "compile" }
```
```json
{ "type": "ExecCommand", "commandLine": "eval Thread.sleep(10000)" }
```