Merge pull request #5126 from eatkins/fg-run

Close classloader in fgRun/fgRunMain
This commit is contained in:
Ethan Atkins 2019-09-24 15:26:49 -07:00 committed by GitHub
commit 0e69402660
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 java.lang.reflect.Modifier.{ isPublic, isStatic }
import sbt.internal.inc.ScalaInstance 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.internal.util.MessageOnlyException
import sbt.io.Path import sbt.io.Path
import sbt.util.Logger 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.*/ /** 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] = { 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( private def invokeMain(
loader: ClassLoader, loader: ClassLoader,