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
|
// 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
|
// this is an approximation to the ideal that would invalidate the delegate after loading completes
|
||||||
private[this] def globalWrapper(s: State): Logger = {
|
private[this] def globalWrapper(s: State): Logger = {
|
||||||
val ref = new java.lang.ref.WeakReference(s.globalLogging.full)
|
|
||||||
new Logger {
|
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.")
|
private[this] def slog: Logger = Option(ref.get) getOrElse sys.error("Settings logger used after project was loaded.")
|
||||||
|
|
||||||
override val ansiCodesSupported = slog.ansiCodesSupported
|
override val ansiCodesSupported = slog.ansiCodesSupported
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,10 @@ object BuiltinCommands {
|
||||||
def reapply(newSession: SessionSettings, structure: BuildStructure, s: State): State =
|
def reapply(newSession: SessionSettings, structure: BuildStructure, s: State): State =
|
||||||
{
|
{
|
||||||
s.log.info("Reapplying settings...")
|
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)
|
Project.setProject(newSession, newStructure, s)
|
||||||
}
|
}
|
||||||
def set = Command(SetCommand, setBrief, setDetailed)(setParser) {
|
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
|
-> f
|
||||||
> project sub
|
> project sub
|
||||||
> f
|
> f
|
||||||
|
|
@ -10,4 +13,4 @@ $ copy-file changes/Changed.scala project/TestProject.scala
|
||||||
> g
|
> g
|
||||||
# The current URI should be kept
|
# The current URI should be kept
|
||||||
> reload
|
> reload
|
||||||
> g
|
> g
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@ TaskKey[Unit]("checkBuildSbtDefined", "") := {
|
||||||
assert(notExistingThing.?.value == Some(5), "Failed to set a settingKey defined in build.sbt")
|
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(
|
commands ++= Seq(
|
||||||
Command.command("helloWorldTest") { state: State =>
|
Command.command("helloWorldTest") { state: State =>
|
||||||
"""set name := "hello-world"""" ::
|
"""set name := "hello-world"""" ::
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
> helloWorldTest
|
> helloWorldTest
|
||||||
> buildSbtTest
|
> buildSbtTest
|
||||||
|
> evil-clear-logger
|
||||||
|
> set version := { sLog.value.info("yo"); version.value }
|
||||||
Loading…
Reference in New Issue