From 9598c2638ec98b6a2e4ea5a022dff0f9bbe73039 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 10 Aug 2014 17:35:01 -0700 Subject: Correctly kill the server on unload, making the sbt `reload` command work as well as auto-importing into IntelliJ --- Plugin.scala | 24 ++++-------------------- Server.scala | 3 +++ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Plugin.scala b/Plugin.scala index 512e195..81359a5 100644 --- a/Plugin.scala +++ b/Plugin.scala @@ -1,22 +1,10 @@ package com.lihaoyi.workbench -import akka.actor.{ActorRef, Actor, ActorSystem} -import scala.concurrent.duration._ - - import sbt._ import Keys._ -import akka.actor.ActorDSL._ -import com.typesafe.config.ConfigFactory import upickle._ -import spray.http.{AllOrigins, HttpResponse} -import spray.routing.SimpleRoutingApp -import spray.http.HttpHeaders.`Access-Control-Allow-Origin` - object Plugin extends sbt.Plugin { - - val refreshBrowsers = taskKey[Unit]("Sends a message to all connected web pages asking them to refresh the page") val updateBrowsers = taskKey[Unit]("partially resets some of the stuff in the browser") val localUrl = settingKey[(String, Int)]("localUrl") @@ -83,14 +71,10 @@ object Plugin extends sbt.Plugin { } } }, - server := { - new Server(localUrl.value._1, localUrl.value._2, bootSnippet.value) - }, - onLoad := { state => - state - }, - onUnload := { state => + server := new Server(localUrl.value._1, localUrl.value._2, bootSnippet.value), + (onUnload in Global) := { (onUnload in Global).value.compose{ state => + server.value.kill() state - } + }} ) } diff --git a/Server.scala b/Server.scala index af4b6b6..b9773a7 100644 --- a/Server.scala +++ b/Server.scala @@ -74,4 +74,7 @@ class Server(url: String, port: Int, bootSnippet: String) extends SimpleRoutingA def msg[T: Writer](t: T) = { pubSub ! upickle.writeJs(t) } + def kill() = { + system.shutdown() + } } \ No newline at end of file -- cgit v1.2.3