summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authoraosagie <osagie@gmail.com>2018-09-02 02:21:35 -0400
committerLi Haoyi <haoyi.sg@gmail.com>2018-09-02 14:21:35 +0800
commita6efead6bafd34a7c55a58e3dc5d6267345672f1 (patch)
treeb8b2c9fbc62a2e6378a258f32544ae5aba36962f /main/src
parented95f2dd558a82f6b84f7f0dc3d80b3038683950 (diff)
downloadmill-a6efead6bafd34a7c55a58e3dc5d6267345672f1.tar.gz
mill-a6efead6bafd34a7c55a58e3dc5d6267345672f1.tar.bz2
mill-a6efead6bafd34a7c55a58e3dc5d6267345672f1.zip
Fix shutdown hook failures in tests (#422)
* Remove duplication from ClassLoader.create * Prevent closing of context class loader in tests so that shutdown hooks can run
Diffstat (limited to 'main/src')
-rw-r--r--main/src/mill/modules/Jvm.scala17
1 files changed, 10 insertions, 7 deletions
diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala
index 96992d20..f0c0d8a9 100644
--- a/main/src/mill/modules/Jvm.scala
+++ b/main/src/mill/modules/Jvm.scala
@@ -89,7 +89,7 @@ object Jvm {
classPath: Agg[Path],
mainArgs: Seq[String] = Seq.empty)
(implicit ctx: Ctx): Unit = {
- inprocess(classPath, classLoaderOverrideSbtTesting = false, isolated = true, cl => {
+ inprocess(classPath, classLoaderOverrideSbtTesting = false, isolated = true, closeContextClassLoaderWhenDone = true, cl => {
getMainMethod(mainClass, cl).invoke(null, mainArgs.toArray)
})
}
@@ -113,6 +113,7 @@ object Jvm {
def inprocess[T](classPath: Agg[Path],
classLoaderOverrideSbtTesting: Boolean,
isolated: Boolean,
+ closeContextClassLoaderWhenDone: Boolean,
body: ClassLoader => T)
(implicit ctx: Ctx.Home): T = {
val urls = classPath.map(_.toIO.toURI.toURL)
@@ -123,19 +124,21 @@ object Jvm {
Some(outerClassLoader.loadClass(name))
else None
})
- } else if (isolated){
-
+ } else if (isolated) {
mill.util.ClassLoader.create(urls.toVector, null)
- }else{
+ } else {
mill.util.ClassLoader.create(urls.toVector, getClass.getClassLoader)
}
+
val oldCl = Thread.currentThread().getContextClassLoader
Thread.currentThread().setContextClassLoader(cl)
try {
body(cl)
- }finally{
- Thread.currentThread().setContextClassLoader(oldCl)
- cl.close()
+ } finally {
+ if (closeContextClassLoaderWhenDone) {
+ Thread.currentThread().setContextClassLoader(oldCl)
+ cl.close()
+ }
}
}