mirror of https://github.com/sbt/sbt.git
Use custom classloader for scripted tests
We had previously used reflection to load the bridge class, but continued using sbt's default classloader. This was problematic because the metabuild could have a different classpath from that required by the scripted tests. Bonus: scalafmt Fixes: #4514
This commit is contained in:
parent
dc870e19b1
commit
b2c9d3e2cf
|
|
@ -17,8 +17,10 @@ object LocalScriptedPlugin extends AutoPlugin {
|
|||
trait ScriptedKeys {
|
||||
val publishAll = taskKey[Unit]("")
|
||||
val publishLocalBinAll = taskKey[Unit]("")
|
||||
val scriptedUnpublished = inputKey[Unit]("Execute scripted without publishing sbt first. " +
|
||||
"Saves you some time when only your test has changed")
|
||||
val scriptedUnpublished = inputKey[Unit](
|
||||
"Execute scripted without publishing sbt first. " +
|
||||
"Saves you some time when only your test has changed"
|
||||
)
|
||||
val scriptedSource = settingKey[File]("")
|
||||
val scriptedPrescripted = taskKey[File => Unit]("")
|
||||
}
|
||||
|
|
@ -116,7 +118,11 @@ object Scripted {
|
|||
): Unit
|
||||
}
|
||||
|
||||
val bridge = bridgeClass.getDeclaredConstructor().newInstance().asInstanceOf[SbtScriptedRunner]
|
||||
val initLoader = Thread.currentThread.getContextClassLoader
|
||||
try {
|
||||
Thread.currentThread.setContextClassLoader(loader)
|
||||
val bridge =
|
||||
bridgeClass.getDeclaredConstructor().newInstance().asInstanceOf[SbtScriptedRunner]
|
||||
|
||||
try {
|
||||
// Using java.util.List to encode File => Unit.
|
||||
|
|
@ -135,5 +141,8 @@ object Scripted {
|
|||
callback,
|
||||
)
|
||||
} catch { case ite: InvocationTargetException => throw ite.getCause }
|
||||
} finally {
|
||||
Thread.currentThread.setContextClassLoader(initLoader)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue