Merge pull request #5130 from eatkins/1.3.x-scalarun-classloader-close-backport

[1.3.x] Close classloader in ScalaRun.run
This commit is contained in:
eugene yokota 2019-09-24 21:04:33 -04:00 committed by GitHub
commit f6991357f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import java.lang.reflect.Method
import java.lang.reflect.Modifier.{ isPublic, isStatic }
import sbt.internal.inc.ScalaInstance
import sbt.internal.inc.classpath.ClasspathUtilities
import sbt.internal.inc.classpath.{ ClasspathFilter, ClasspathUtilities }
import sbt.internal.util.MessageOnlyException
import sbt.io.Path
import sbt.util.Logger
@ -95,7 +95,13 @@ class Run(private[sbt] val newLoader: Seq[File] => ClassLoader, trapExit: Boolea
/** Runs the class 'mainClass' using the given classpath and options using the scala runner.*/
def run(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger): Try[Unit] = {
runWithLoader(newLoader(classpath), classpath, mainClass, options, log)
val loader = newLoader(classpath)
try runWithLoader(loader, classpath, mainClass, options, log)
finally loader match {
case ac: AutoCloseable => ac.close()
case c: ClasspathFilter => c.close()
case _ =>
}
}
private def invokeMain(
loader: ClassLoader,