Skip to content

Commit c855f0c

Browse files
authored
Merge pull request sbt#3551 from eed3si9n/wip/autostart
`sbt.server.autostart` flag and startServer
2 parents c514acc + f21d190 commit c855f0c

File tree

7 files changed

+60
-32
lines changed

7 files changed

+60
-32
lines changed

main-command/src/main/scala/sbt/BasicCommandStrings.scala

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ $AliasCommand name=
161161
def ShellDetailed =
162162
"Provides an interactive prompt and network server from which commands can be run."
163163

164+
def StartServer = "startServer"
165+
def StartServerDetailed =
166+
s"""$StartServer
167+
Starts the server if it has not been started. This is intended to be used with
168+
-Dsbt.server.autostart=false."""
169+
164170
def OldShell = "oldshell"
165171
def OldShellDetailed = "Provides an interactive prompt from which commands can be run."
166172

main/src/main/scala/sbt/Main.scala

+7
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ object BuiltinCommands {
195195
multi,
196196
shell,
197197
oldshell,
198+
startServer,
198199
BasicCommands.client,
199200
continuous,
200201
eval,
@@ -737,6 +738,12 @@ object BuiltinCommands {
737738
else newState.clearGlobalLog
738739
}
739740

741+
def startServer: Command =
742+
Command.command(StartServer, Help.more(StartServer, StartServerDetailed)) { s0 =>
743+
val exchange = StandardMain.exchange
744+
exchange.runServer(s0)
745+
}
746+
740747
private val sbtVersionRegex = """sbt\.version\s*=.*""".r
741748
private def isSbtVersionLine(s: String) = sbtVersionRegex.pattern matcher s matches ()
742749

main/src/main/scala/sbt/internal/CommandExchange.scala

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import scala.util.{ Success, Failure }
2323
* this exchange, which could serve command request from either of the channel.
2424
*/
2525
private[sbt] final class CommandExchange {
26+
private val autoStartServer = sys.props.get("sbt.server.autostart") map {
27+
_.toLowerCase == "true"
28+
} getOrElse true
2629
private val lock = new AnyRef {}
2730
private var server: Option[ServerInstance] = None
2831
private var consoleChannel: Option[ConsoleChannel] = None
@@ -61,13 +64,17 @@ private[sbt] final class CommandExchange {
6164
consoleChannel = Some(x)
6265
subscribe(x)
6366
}
64-
runServer(s)
67+
if (autoStartServer) runServer(s)
68+
else s
6569
}
6670

6771
private def newChannelName: String = s"channel-${nextChannelId.incrementAndGet()}"
6872

69-
private def runServer(s: State): State = {
70-
val port = (s get serverPort) match {
73+
/**
74+
* Check if a server instance is running already, and start one if it isn't.
75+
*/
76+
private[sbt] def runServer(s: State): State = {
77+
def port = (s get serverPort) match {
7178
case Some(x) => x
7279
case None => 5001
7380
}

notes/1.0.2.markdown

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
This is a hotfix release for sbt 1.0.x series.
2+
3+
### Bug fixes
4+
5+
- Fixes terminal echo issue. [#3507][3507] by [@kczulko][@kczulko]
6+
- Fixes `deliver` task, and adds `makeIvyXml` as a more sensibly named task. [#3487][3487] by [@cunei][@cunei]
7+
- Replaces the deprecated use of `OkUrlFactory`, and fixes connection leaks. [lm#164][lm164] by [@dpratt][@dpratt]
8+
- Refixes false positive in DSL checker for setting keys. [#3513][3513] by [@dwijnand][@dwijnand]
9+
- Fixes `run` and `bgRun` not picking up changes to directories in the classpath. [#3517][3517] by [@dwijnand][@dwijnand]
10+
- Fixes `++` so it won't change the value of `crossScalaVersion`. [#3495][3495]/[#3526][3526] by [@dwijnand][@dwijnand]
11+
- Fixes sbt server missing some messages. [#3523][3523] by [@guillaumebort][@guillaumebort]
12+
- Refixes `consoleProject`. [zinc#386][zinc386] by [@dwijnand][@dwijnand]
13+
- 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]
14+
- 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]
15+
16+
### Internal
17+
18+
- Fixes unused import warnings. [#3533][3533] by [@razvan-panda][@razvan-panda]
19+
20+
[@dwijnand]: https://github.com/dwijnand
21+
[@cunei]: https://github.com/cunei
22+
[@eed3si9n]: https://github.com/eed3si9n
23+
[@dpratt]: https://github.com/dpratt
24+
[@kczulko]: https://github.com/kczulko
25+
[@razvan-panda]: https://github.com/razvan-panda
26+
[@guillaumebort]: https://github.com/guillaumebort
27+
[3487]: https://github.com/sbt/sbt/pull/3487
28+
[lm164]: https://github.com/sbt/librarymanagement/pull/164
29+
[3495]: https://github.com/sbt/sbt/issues/3495
30+
[3526]: https://github.com/sbt/sbt/pull/3526
31+
[3513]: https://github.com/sbt/sbt/pull/3513
32+
[3517]: https://github.com/sbt/sbt/pull/3517
33+
[3507]: https://github.com/sbt/sbt/pull/3507
34+
[3533]: https://github.com/sbt/sbt/pull/3533
35+
[3523]: https://github.com/sbt/sbt/pull/3523
36+
[zinc386]: https://github.com/sbt/zinc/pull/386
37+
[lm167]: https://github.com/sbt/librarymanagement/pull/167

notes/1.0.2/lm.markdown

-12
This file was deleted.

notes/1.0.2/plusplus-not-changing-crossScalaVersions.md

-12
This file was deleted.

notes/1.0.2/server-issue.markdown

-5
This file was deleted.

0 commit comments

Comments
 (0)