mirror of https://github.com/sbt/sbt.git
Fixes #1478 - Append new sLog when reloading in set command.
* Migrate weak reference into logger class so we can test clearing it. * Ensure new state.log is propoagted into settings on `set` command. * Fix set test so that it ensures the sLog is relatively stable when reloading on set command.
This commit is contained in:
parent
b393df8acf
commit
49f1529c5a
|
|
@ -105,8 +105,8 @@ object LogManager {
|
|||
// construct a Logger that delegates to the global logger, but only holds a weak reference
|
||||
// this is an approximation to the ideal that would invalidate the delegate after loading completes
|
||||
private[this] def globalWrapper(s: State): Logger = {
|
||||
val ref = new java.lang.ref.WeakReference(s.globalLogging.full)
|
||||
new Logger {
|
||||
private[this] val ref = new java.lang.ref.WeakReference(s.globalLogging.full)
|
||||
private[this] def slog: Logger = Option(ref.get) getOrElse sys.error("Settings logger used after project was loaded.")
|
||||
|
||||
override val ansiCodesSupported = slog.ansiCodesSupported
|
||||
|
|
|
|||
|
|
@ -227,7 +227,10 @@ object BuiltinCommands {
|
|||
def reapply(newSession: SessionSettings, structure: BuildStructure, s: State): State =
|
||||
{
|
||||
s.log.info("Reapplying settings...")
|
||||
val newStructure = Load.reapply(newSession.mergeSettings, structure)(Project.showContextKey(newSession, structure))
|
||||
// Here, for correct behavior, we also need to re-inject a settings logger, as we'll be re-evaluating settings.
|
||||
val loggerInject = LogManager.settingsLogger(s)
|
||||
val withLogger = newSession.appendRaw(loggerInject :: Nil)
|
||||
val newStructure = Load.reapply(withLogger.mergeSettings, structure)(Project.showContextKey(newSession, structure))
|
||||
Project.setProject(newSession, newStructure, s)
|
||||
}
|
||||
def set = Command(SetCommand, setBrief, setDetailed)(setParser) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
version := {
|
||||
sLog.value.info("Version is initializing")
|
||||
version.value
|
||||
}
|
||||
|
||||
TaskKey[Unit]("evil-clear-logger") := {
|
||||
val logger = sLog.value
|
||||
val cls = logger.getClass
|
||||
val field = cls.getDeclaredField("ref")
|
||||
field.setAccessible(true)
|
||||
val ref = field.get(logger).asInstanceOf[java.lang.ref.WeakReference[_]]
|
||||
// MUHAHAHHAHAHAHAHHAHA, I am de evil GC, I clear things.
|
||||
ref.clear()
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
# Note: We aren't actively running this test, but it checks to make sure the setting-level logger is ok across reloads.
|
||||
# > evil-clear-logger
|
||||
# > reload
|
||||
-> f
|
||||
> project sub
|
||||
> f
|
||||
|
|
@ -10,4 +13,4 @@ $ copy-file changes/Changed.scala project/TestProject.scala
|
|||
> g
|
||||
# The current URI should be kept
|
||||
> reload
|
||||
> g
|
||||
> g
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ TaskKey[Unit]("checkBuildSbtDefined", "") := {
|
|||
assert(notExistingThing.?.value == Some(5), "Failed to set a settingKey defined in build.sbt")
|
||||
}
|
||||
|
||||
TaskKey[Unit]("evil-clear-logger") := {
|
||||
val logger = sLog.value
|
||||
val cls = logger.getClass
|
||||
val field = cls.getDeclaredField("ref")
|
||||
field.setAccessible(true)
|
||||
val ref = field.get(logger).asInstanceOf[java.lang.ref.WeakReference[_]]
|
||||
// MUHAHAHHAHAHAHAHHAHA, I am de evil GC, I clear things.
|
||||
ref.clear()
|
||||
}
|
||||
|
||||
commands ++= Seq(
|
||||
Command.command("helloWorldTest") { state: State =>
|
||||
"""set name := "hello-world"""" ::
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
> helloWorldTest
|
||||
> buildSbtTest
|
||||
> buildSbtTest
|
||||
> evil-clear-logger
|
||||
> set version := { sLog.value.info("yo"); version.value }
|
||||
Loading…
Reference in New Issue