`sbt.server.autostart` flag and startServer

Adds JVM flag `sbt.server.autostart` to enable/disable the automatic starting of sbt server with the sbt shell.

This also adds a new command `startServer` to manually start the server.
This commit is contained in:
Eugene Yokota 2017-09-16 03:24:30 -04:00
parent 8dbb00f3b1
commit f21d190a65
4 changed files with 26 additions and 4 deletions

View File

@ -161,6 +161,12 @@ $AliasCommand name=
def ShellDetailed =
"Provides an interactive prompt and network server from which commands can be run."
def StartServer = "startServer"
def StartServerDetailed =
s"""$StartServer
Starts the server if it has not been started. This is intended to be used with
-Dsbt.server.autostart=false."""
def OldShell = "oldshell"
def OldShellDetailed = "Provides an interactive prompt from which commands can be run."

View File

@ -195,6 +195,7 @@ object BuiltinCommands {
multi,
shell,
oldshell,
startServer,
BasicCommands.client,
continuous,
eval,
@ -737,6 +738,12 @@ object BuiltinCommands {
else newState.clearGlobalLog
}
def startServer: Command =
Command.command(StartServer, Help.more(StartServer, StartServerDetailed)) { s0 =>
val exchange = StandardMain.exchange
exchange.runServer(s0)
}
private val sbtVersionRegex = """sbt\.version\s*=.*""".r
private def isSbtVersionLine(s: String) = sbtVersionRegex.pattern matcher s matches ()

View File

@ -23,6 +23,9 @@ import scala.util.{ Success, Failure }
* this exchange, which could serve command request from either of the channel.
*/
private[sbt] final class CommandExchange {
private val autoStartServer = sys.props.get("sbt.server.autostart") map {
_.toLowerCase == "true"
} getOrElse true
private val lock = new AnyRef {}
private var server: Option[ServerInstance] = None
private var consoleChannel: Option[ConsoleChannel] = None
@ -61,13 +64,17 @@ private[sbt] final class CommandExchange {
consoleChannel = Some(x)
subscribe(x)
}
runServer(s)
if (autoStartServer) runServer(s)
else s
}
private def newChannelName: String = s"channel-${nextChannelId.incrementAndGet()}"
private def runServer(s: State): State = {
val port = (s get serverPort) match {
/**
* Check if a server instance is running already, and start one if it isn't.
*/
private[sbt] def runServer(s: State): State = {
def port = (s get serverPort) match {
case Some(x) => x
case None => 5001
}

View File

@ -11,14 +11,16 @@ This is a hotfix release for sbt 1.0.x series.
- Fixes sbt server missing some messages. [#3523][3523] by [@guillaumebort][@guillaumebort]
- Refixes `consoleProject`. [zinc#386][zinc386] by [@dwijnand][@dwijnand]
- Adds JVM flag `sbt.gigahorse` to enable/disable the internal use of Gigahorse to workaround NPE in `JavaNetAuthenticator` when used in conjunction with `repositories` override. [lm#167][lm167] by [@cunei][@cunei]
- Adds JVM flag `sbt.server.autostart` to enable/disable the automatic starting of sbt server with the sbt shell. This also adds new `startServer` command to manually start the server. by [@eed3si9n][@eed3si9n]
### Internal
- Fixes unused import warnings. [#3533][3533] by [@razvan-panda][@razvan-panda]
[@dpratt]: https://github.com/dpratt
[@dwijnand]: https://github.com/dwijnand
[@cunei]: https://github.com/cunei
[@eed3si9n]: https://github.com/eed3si9n
[@dpratt]: https://github.com/dpratt
[@kczulko]: https://github.com/kczulko
[@razvan-panda]: https://github.com/razvan-panda
[@guillaumebort]: https://github.com/guillaumebort