Skip to content

Commit

Permalink
Merge pull request #3551 from eed3si9n/wip/autostart
Browse files Browse the repository at this point in the history
`sbt.server.autostart` flag and startServer
  • Loading branch information
eed3si9n committed Sep 16, 2017
2 parents c514acc + f21d190 commit c855f0c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 32 deletions.
6 changes: 6 additions & 0 deletions main-command/src/main/scala/sbt/BasicCommandStrings.scala
Expand Up @@ -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."

Expand Down
7 changes: 7 additions & 0 deletions main/src/main/scala/sbt/Main.scala
Expand Up @@ -195,6 +195,7 @@ object BuiltinCommands {
multi,
shell,
oldshell,
startServer,
BasicCommands.client,
continuous,
eval,
Expand Down Expand Up @@ -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 ()

Expand Down
13 changes: 10 additions & 3 deletions main/src/main/scala/sbt/internal/CommandExchange.scala
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
37 changes: 37 additions & 0 deletions notes/1.0.2.markdown
@@ -0,0 +1,37 @@
This is a hotfix release for sbt 1.0.x series.

### Bug fixes

- Fixes terminal echo issue. [#3507][3507] by [@kczulko][@kczulko]
- Fixes `deliver` task, and adds `makeIvyXml` as a more sensibly named task. [#3487][3487] by [@cunei][@cunei]
- Replaces the deprecated use of `OkUrlFactory`, and fixes connection leaks. [lm#164][lm164] by [@dpratt][@dpratt]
- Refixes false positive in DSL checker for setting keys. [#3513][3513] by [@dwijnand][@dwijnand]
- Fixes `run` and `bgRun` not picking up changes to directories in the classpath. [#3517][3517] by [@dwijnand][@dwijnand]
- Fixes `++` so it won't change the value of `crossScalaVersion`. [#3495][3495]/[#3526][3526] by [@dwijnand][@dwijnand]
- 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]

[@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
[3487]: https://github.com/sbt/sbt/pull/3487
[lm164]: https://github.com/sbt/librarymanagement/pull/164
[3495]: https://github.com/sbt/sbt/issues/3495
[3526]: https://github.com/sbt/sbt/pull/3526
[3513]: https://github.com/sbt/sbt/pull/3513
[3517]: https://github.com/sbt/sbt/pull/3517
[3507]: https://github.com/sbt/sbt/pull/3507
[3533]: https://github.com/sbt/sbt/pull/3533
[3523]: https://github.com/sbt/sbt/pull/3523
[zinc386]: https://github.com/sbt/zinc/pull/386
[lm167]: https://github.com/sbt/librarymanagement/pull/167
12 changes: 0 additions & 12 deletions notes/1.0.2/lm.markdown

This file was deleted.

12 changes: 0 additions & 12 deletions notes/1.0.2/plusplus-not-changing-crossScalaVersions.md

This file was deleted.

5 changes: 0 additions & 5 deletions notes/1.0.2/server-issue.markdown

This file was deleted.

0 comments on commit c855f0c

Please sign in to comment.