mirror of https://github.com/sbt/sbt.git
Use State to pick the port file
This commit is contained in:
parent
bd0e44c292
commit
5ab122c3cf
|
|
@ -131,34 +131,31 @@ private[sbt] final class CommandExchange {
|
||||||
new NetworkChannel(name, socket, Project structure s, auth, instance, logger)
|
new NetworkChannel(name, socket, Project structure s, auth, instance, logger)
|
||||||
subscribe(channel)
|
subscribe(channel)
|
||||||
}
|
}
|
||||||
server match {
|
if (server.isEmpty && firstInstance.get) {
|
||||||
case Some(_) => // do nothing
|
val portfile = s.baseDir / "project" / "target" / "active.json"
|
||||||
case None if !firstInstance.get => // there's another server
|
|
||||||
case _ =>
|
|
||||||
val portfile = (new File(".")).getAbsoluteFile / "project" / "target" / "active.json"
|
|
||||||
val h = Hash.halfHashString(IO.toURI(portfile).toString)
|
val h = Hash.halfHashString(IO.toURI(portfile).toString)
|
||||||
val tokenfile = BuildPaths.getGlobalBase(s) / "server" / h / "token.json"
|
val tokenfile = BuildPaths.getGlobalBase(s) / "server" / h / "token.json"
|
||||||
val socketfile = BuildPaths.getGlobalBase(s) / "server" / h / "sock"
|
val socketfile = BuildPaths.getGlobalBase(s) / "server" / h / "sock"
|
||||||
val pipeName = "sbt-server-" + h
|
val pipeName = "sbt-server-" + h
|
||||||
val connection =
|
val connection = ServerConnection(
|
||||||
ServerConnection(connectionType,
|
connectionType,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
auth,
|
auth,
|
||||||
portfile,
|
portfile,
|
||||||
tokenfile,
|
tokenfile,
|
||||||
socketfile,
|
socketfile,
|
||||||
pipeName)
|
pipeName,
|
||||||
val x = Server.start(connection, onIncomingSocket, s.log)
|
)
|
||||||
|
val serverInstance = Server.start(connection, onIncomingSocket, s.log)
|
||||||
// don't throw exception when it times out
|
// don't throw exception when it times out
|
||||||
val d = "10s"
|
val d = "10s"
|
||||||
Try(Await.ready(x.ready, Duration(d)))
|
Try(Await.ready(serverInstance.ready, Duration(d)))
|
||||||
x.ready.value match {
|
serverInstance.ready.value match {
|
||||||
case Some(Success(_)) =>
|
case Some(Success(())) =>
|
||||||
// rememeber to shutdown only when the server comes up
|
// remember to shutdown only when the server comes up
|
||||||
server = Some(x)
|
server = Some(serverInstance)
|
||||||
case Some(Failure(e: AlreadyRunningException)) =>
|
case Some(Failure(_: AlreadyRunningException)) =>
|
||||||
s.log.warn(
|
s.log.warn(
|
||||||
"sbt server could not start because there's another instance of sbt running on this build.")
|
"sbt server could not start because there's another instance of sbt running on this build.")
|
||||||
s.log.warn("Running multiple instances is unsupported")
|
s.log.warn("Running multiple instances is unsupported")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue