Skip to content

Commit

Permalink
Upgrade to sbt-1.3.0-RC2 (#510)
Browse files Browse the repository at this point in the history
* Upgrade to sbt-1.3.0-RC2

* Do not register shutdown hooks for sbt test

* Fix test name

* Properly unregister shutdown hooks

* Disable log buffer

* sbt-1.3.0-RC2 cannot find classes defined in other projects
  • Loading branch information
xerial committed Jun 12, 2019
1 parent 522c7cb commit 3583430
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Expand Up @@ -104,7 +104,7 @@ object JMXUtil extends LogSupport {
private[jmx] def startAndGetAgentURL(config: JMXConfig): String = {
Try(startAgent(config)) match {
case Success(x) =>
info(s"Started JMX agent at localhost:${x.port}")
debug(s"Started JMX agent at localhost:${x.port}")
s"service:jmx:rmi:///jndi/rmi://localhost:${x.port}/jmxrmi"
case Failure(e) =>
warn(e)
Expand Down
4 changes: 2 additions & 2 deletions airframe-log/jvm/src/test/scala/wvlet/log/LoggerJMXTest.scala
Expand Up @@ -14,13 +14,13 @@
package wvlet.log
import java.lang.management.ManagementFactory

import javax.management.{Attribute, JMX, ObjectName}
import javax.management.{Attribute, ObjectName}

/**
*
*/
class LoggerJMXTest extends Spec {
"LoggerJXM" should {
"LoggerJMX" should {
"be registered" in {
// Initialize a logger
val l = Logger.rootLogger
Expand Down
36 changes: 30 additions & 6 deletions airframe/.jvm/src/main/scala/wvlet/airframe/AddShutdownHook.scala
Expand Up @@ -13,26 +13,50 @@
*/
package wvlet.airframe

import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger}

import wvlet.log.AirframeLogManager

import scala.collection.mutable
import scala.sys.ShutdownHookThread

/**
*
*/
object AddShutdownHook extends LifeCycleEventHandler {

private val registered = new AtomicInteger(0)
private val shutdownHooks = new mutable.WeakHashMap[LifeCycleManager, ShutdownHookThread]()

private def removeShutdownHooksFor(lifeCycleManager: LifeCycleManager): Unit = {
synchronized {
shutdownHooks.get(lifeCycleManager).map { h =>
// Properly unregister shutdown hooks
// This will be a workaround for sbt-1.3.0-RC2 https://github.com/sbt/sbt/issues/4794 (user class will not be visible at sbt shutdown)
if (h != null) {
h.remove()
}
shutdownHooks.remove(lifeCycleManager)
}
}
}

override def beforeStart(lifeCycleManager: LifeCycleManager): Unit = {
registered.incrementAndGet()
sys.addShutdownHook {
val shutdownHookThread = sys.addShutdownHook {
lifeCycleManager.shutdown

if (registered.decrementAndGet() <= 0) {
removeShutdownHooksFor(lifeCycleManager)
if (shutdownHooks.isEmpty) {
// Resetting the logger when all lifecycle have terminated
AirframeLogManager.resetFinally
}
}

// Remember the shutdown hooks registered
synchronized {
shutdownHooks.put(lifeCycleManager, shutdownHookThread)
}
}

override def afterShutdown(lifeCycleManager: LifeCycleManager): Unit = {
// Unregister shutdown hooks
removeShutdownHooksFor(lifeCycleManager)
}
}
6 changes: 3 additions & 3 deletions build.sbt
Expand Up @@ -52,7 +52,6 @@ val buildSettings = Seq[Setting[_]](
crossScalaVersions := targetScalaVersions,
crossPaths := true,
publishMavenStyle := true,
logBuffered in Test := false,
scalacOptions ++= Seq("-feature", "-deprecation"), // ,"-Ytyper-debug"),
sonatypeProfileName := "org.wvlet",
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")),
Expand Down Expand Up @@ -310,8 +309,9 @@ lazy val airframe =
)
)
.jvmSettings(
// Workaround for https://github.com/scala/scala/pull/7624
fork in Test := (scalaVersion.value.startsWith("2.13.")),
// Workaround for https://github.com/scala/scala/pull/7624 in Scala 2.13, and also
// testing shtudown hooks requires consistent application lifecycle between sbt and JVM https://github.com/sbt/sbt/issues/4794
fork in Test := scalaBinaryVersion.value == "2.13",
// include the macro classes and resources in the main jar
mappings in (Compile, packageBin) ++= mappings.in(airframeMacrosJVM, Compile, packageBin).value,
// include the macro sources in the main source jar
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Expand Up @@ -12,4 +12,4 @@
# limitations under the License.
#

sbt.version=1.3.0-RC1
sbt.version=1.3.0-RC2

0 comments on commit 3583430

Please sign in to comment.