mirror of https://github.com/sbt/sbt.git
Merge pull request #8234 from eed3si9n/wip/client-improvement
[1.x] Improve sbtn a bit
This commit is contained in:
commit
e135576ec9
|
|
@ -11,7 +11,7 @@ import scala.util.Try
|
||||||
// ThisBuild settings take lower precedence,
|
// ThisBuild settings take lower precedence,
|
||||||
// but can be shared across the multi projects.
|
// but can be shared across the multi projects.
|
||||||
ThisBuild / version := {
|
ThisBuild / version := {
|
||||||
val v = "1.11.1-SNAPSHOT"
|
val v = "1.11.5-SNAPSHOT"
|
||||||
nightlyVersion.getOrElse(v)
|
nightlyVersion.getOrElse(v)
|
||||||
}
|
}
|
||||||
ThisBuild / version2_13 := "2.0.0-SNAPSHOT"
|
ThisBuild / version2_13 := "2.0.0-SNAPSHOT"
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,8 @@ lazy val integrationTest = (project in file("integration-test"))
|
||||||
},
|
},
|
||||||
testOnly in Test := {
|
testOnly in Test := {
|
||||||
(testOnly in Test).dependsOn(((packageBin in Universal) in LocalRootProject).dependsOn(((stage in (Universal) in LocalRootProject)))).evaluated
|
(testOnly in Test).dependsOn(((packageBin in Universal) in LocalRootProject).dependsOn(((stage in (Universal) in LocalRootProject)))).evaluated
|
||||||
}
|
},
|
||||||
|
parallelExecution in Test := false
|
||||||
)
|
)
|
||||||
|
|
||||||
def downloadUrlForVersion(v: String) = (v split "[^\\d]" flatMap (i => catching(classOf[Exception]) opt (i.toInt))) match {
|
def downloadUrlForVersion(v: String) = (v split "[^\\d]" flatMap (i => catching(classOf[Exception]) opt (i.toInt))) match {
|
||||||
|
|
|
||||||
|
|
@ -432,6 +432,7 @@ class NetworkClient(
|
||||||
start()
|
start()
|
||||||
override def run(): Unit = {
|
override def run(): Unit = {
|
||||||
try {
|
try {
|
||||||
|
val buffer = mutable.ArrayBuffer.empty[Byte]
|
||||||
while (readThreadAlive.get) {
|
while (readThreadAlive.get) {
|
||||||
if (socket.isEmpty) {
|
if (socket.isEmpty) {
|
||||||
socket = Try(ClientSocket.localSocket(bootSocketName, useJNI)).toOption
|
socket = Try(ClientSocket.localSocket(bootSocketName, useJNI)).toOption
|
||||||
|
|
@ -447,7 +448,12 @@ class NetworkClient(
|
||||||
case 3 if gotInputBack => // ETX: end of text
|
case 3 if gotInputBack => // ETX: end of text
|
||||||
readThreadAlive.set(false)
|
readThreadAlive.set(false)
|
||||||
case i if gotInputBack => stdinBytes.offer(i)
|
case i if gotInputBack => stdinBytes.offer(i)
|
||||||
case i => printStream.write(i)
|
case 10 => // CR
|
||||||
|
buffer.append(10)
|
||||||
|
printStream.write(buffer.toArray[Byte])
|
||||||
|
buffer.clear()
|
||||||
|
case i =>
|
||||||
|
buffer.append(i.toByte)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e @ (_: IOException | _: InterruptedException) =>
|
case e @ (_: IOException | _: InterruptedException) =>
|
||||||
|
|
@ -572,7 +578,7 @@ class NetworkClient(
|
||||||
case null => ()
|
case null => ()
|
||||||
case (q, startTime, name) =>
|
case (q, startTime, name) =>
|
||||||
val now = System.currentTimeMillis
|
val now = System.currentTimeMillis
|
||||||
val message = NetworkClient.timing(startTime, now)
|
val message = NetworkClient.elapsedString(startTime, now)
|
||||||
if (batchMode.get || !attached.get) {
|
if (batchMode.get || !attached.get) {
|
||||||
if (exitCode == 0) console.success(message)
|
if (exitCode == 0) console.success(message)
|
||||||
else console.appendLog(Level.Error, message)
|
else console.appendLog(Level.Error, message)
|
||||||
|
|
@ -862,8 +868,7 @@ class NetworkClient(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def connect(log: Boolean, promptCompleteUsers: Boolean): Boolean = {
|
def connect(promptCompleteUsers: Boolean): Boolean =
|
||||||
if (log) console.appendLog(Level.Info, "entering *experimental* thin client - BEEP WHIRR")
|
|
||||||
try {
|
try {
|
||||||
init(promptCompleteUsers, retry = true)
|
init(promptCompleteUsers, retry = true)
|
||||||
true
|
true
|
||||||
|
|
@ -872,7 +877,6 @@ class NetworkClient(
|
||||||
console.appendLog(Level.Error, "failed to connect to server")
|
console.appendLog(Level.Error, "failed to connect to server")
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private[this] val contHandler: () => Unit = () => {
|
private[this] val contHandler: () => Unit = () => {
|
||||||
if (Terminal.console.getLastLine.nonEmpty)
|
if (Terminal.console.getLastLine.nonEmpty)
|
||||||
|
|
@ -913,9 +917,8 @@ class NetworkClient(
|
||||||
catch { case _: InterruptedException => }
|
catch { case _: InterruptedException => }
|
||||||
if (exitClean.get) 0 else 1
|
if (exitClean.get) 0 else 1
|
||||||
}
|
}
|
||||||
console.appendLog(Level.Info, "terminate the server with `shutdown`")
|
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
console.appendLog(Level.Info, "disconnect from the server with `exit`")
|
console.appendLog(Level.Info, "terminate the server with `shutdown`")
|
||||||
block()
|
block()
|
||||||
} else if (exit) 0
|
} else if (exit) 0
|
||||||
else {
|
else {
|
||||||
|
|
@ -927,8 +930,7 @@ class NetworkClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
def batchExecute(userCommands: List[String]): Int = {
|
def batchExecute(userCommands: List[String]): Int = {
|
||||||
val cmd = userCommands mkString " "
|
val cmd = userCommands.mkString(" ")
|
||||||
printStream.println("> " + cmd)
|
|
||||||
sendAndWait(cmd, None)
|
sendAndWait(cmd, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1230,8 +1232,16 @@ object NetworkClient {
|
||||||
// Which sometimes becomes garbled in standard output
|
// Which sometimes becomes garbled in standard output
|
||||||
// Therefore we replace NNBSP (u202f) with standard space (u0020)
|
// Therefore we replace NNBSP (u202f) with standard space (u0020)
|
||||||
val nowString = format.format(new Date(endTime)).replace("\u202F", "\u0020")
|
val nowString = format.format(new Date(endTime)).replace("\u202F", "\u0020")
|
||||||
|
val totalString = elapsedStr(startTime, endTime)
|
||||||
|
s"Total time: $totalString, completed $nowString"
|
||||||
|
}
|
||||||
|
|
||||||
|
def elapsedString(startTime: Long, endTime: Long): String =
|
||||||
|
s"elapsed: ${elapsedStr(startTime, endTime)}"
|
||||||
|
|
||||||
|
private def elapsedStr(startTime: Long, endTime: Long): String = {
|
||||||
val total = (endTime - startTime + 500) / 1000
|
val total = (endTime - startTime + 500) / 1000
|
||||||
val totalString = s"$total s" +
|
s"$total s" +
|
||||||
(if (total <= 60) ""
|
(if (total <= 60) ""
|
||||||
else {
|
else {
|
||||||
val hours = total / 3600 match {
|
val hours = total / 3600 match {
|
||||||
|
|
@ -1242,7 +1252,6 @@ object NetworkClient {
|
||||||
val secs = f"${total % 60}%02d"
|
val secs = f"${total % 60}%02d"
|
||||||
s" ($hours:$mins:$secs.0)"
|
s" ($hours:$mins:$secs.0)"
|
||||||
})
|
})
|
||||||
s"Total time: $totalString, completed $nowString"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def timing(startTime: Long, endTime: Long): String = {
|
private[sbt] def timing(startTime: Long, endTime: Long): String = {
|
||||||
|
|
@ -1267,7 +1276,7 @@ object NetworkClient {
|
||||||
useJNI,
|
useJNI,
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
if (client.connect(log = true, promptCompleteUsers = false)) client.run()
|
if (client.connect(promptCompleteUsers = false)) client.run()
|
||||||
else 1
|
else 1
|
||||||
} catch { case _: Exception => 1 } finally client.close()
|
} catch { case _: Exception => 1 } finally client.close()
|
||||||
}
|
}
|
||||||
|
|
@ -1297,7 +1306,7 @@ object NetworkClient {
|
||||||
client.connectOrStartServerAndConnect(promptCompleteUsers = false, retry = true)
|
client.connectOrStartServerAndConnect(promptCompleteUsers = false, retry = true)
|
||||||
BspClient.bspRun(socket)
|
BspClient.bspRun(socket)
|
||||||
} else {
|
} else {
|
||||||
if (client.connect(log = true, promptCompleteUsers = false)) client.run()
|
if (client.connect(promptCompleteUsers = false)) client.run()
|
||||||
else 1
|
else 1
|
||||||
}
|
}
|
||||||
} catch { case _: Exception => 1 } finally client.close()
|
} catch { case _: Exception => 1 } finally client.close()
|
||||||
|
|
@ -1394,7 +1403,7 @@ object NetworkClient {
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
val results =
|
val results =
|
||||||
if (client.connect(log = false, promptCompleteUsers = true)) client.getCompletions(cmd)
|
if (client.connect(promptCompleteUsers = true)) client.getCompletions(cmd)
|
||||||
else Nil
|
else Nil
|
||||||
out.println(results.sorted.distinct mkString "\n")
|
out.println(results.sorted.distinct mkString "\n")
|
||||||
0
|
0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue