mirror of https://github.com/sbt/sbt.git
Run method properly fails when executed code throws an exception in the main thread
git-svn-id: https://simple-build-tool.googlecode.com/svn/trunk@919 d89573ee-9141-11dd-94d4-bdf5e562f29c
This commit is contained in:
parent
fa29b38b38
commit
d58d29c7d9
|
|
@ -77,24 +77,20 @@ object Run extends ScalaRun
|
||||||
/** 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: Iterable[Path], options: Seq[String], log: Logger) =
|
def run(mainClass: String, classpath: Iterable[Path], options: Seq[String], log: Logger) =
|
||||||
{
|
{
|
||||||
createSettings(log)
|
createSettings(log) { (settings: Settings) =>
|
||||||
{
|
Control.trapUnit("Error during run: ", log)
|
||||||
(settings: Settings) =>
|
|
||||||
{
|
{
|
||||||
Control.trapUnit("Error during run: ", log)
|
val classpathURLs = classpath.map(_.asURL).toList
|
||||||
{
|
val bootClasspath = FileUtilities.pathSplit(settings.bootclasspath.value)
|
||||||
val classpathURLs = classpath.map(_.asURL).toList
|
val extraURLs =
|
||||||
val bootClasspath = FileUtilities.pathSplit(settings.bootclasspath.value)
|
for(pathString <- bootClasspath if pathString.length > 0) yield
|
||||||
val extraURLs =
|
(new java.io.File(pathString)).toURI.toURL
|
||||||
for(pathString <- bootClasspath if pathString.length > 0) yield
|
log.info("Running " + mainClass + " ...")
|
||||||
(new java.io.File(pathString)).toURI.toURL
|
log.debug(" Classpath:" + (classpathURLs ++ extraURLs).mkString("\n\t", "\n\t",""))
|
||||||
log.info("Running " + mainClass + " ...")
|
def execute =
|
||||||
log.debug(" Classpath:" + (classpathURLs ++ extraURLs).mkString("\n\t", "\n\t",""))
|
try { ObjectRunner.run(classpathURLs ++ extraURLs, mainClass, options.toList) }
|
||||||
def execute =
|
catch { case e: java.lang.reflect.InvocationTargetException => throw e.getCause }
|
||||||
try { ObjectRunner.run(classpathURLs ++ extraURLs, mainClass, options.toList) }
|
executeTrapExit( execute, log )
|
||||||
catch { case e: java.lang.reflect.InvocationTargetException => throw e.getCause }
|
|
||||||
executeTrapExit( execute, log )
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,9 @@ object TrapExit
|
||||||
* the threads that were created by 'execute'.*/
|
* the threads that were created by 'execute'.*/
|
||||||
val originalThreads = allThreads
|
val originalThreads = allThreads
|
||||||
val code = new ExitCode
|
val code = new ExitCode
|
||||||
|
def executeMain = try { execute } catch { case x => code.set(1); throw x }
|
||||||
val customThreadGroup = new ExitThreadGroup(new ExitHandler(Thread.getDefaultUncaughtExceptionHandler, originalThreads, code, log))
|
val customThreadGroup = new ExitThreadGroup(new ExitHandler(Thread.getDefaultUncaughtExceptionHandler, originalThreads, code, log))
|
||||||
val executionThread = new Thread(customThreadGroup, "run-main") { override def run() { execute } }
|
val executionThread = new Thread(customThreadGroup, "run-main") { override def run() { executeMain } }
|
||||||
|
|
||||||
val originalSecurityManager = System.getSecurityManager
|
val originalSecurityManager = System.getSecurityManager
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
object Spawn
|
||||||
|
{
|
||||||
|
def main(args: Array[String])
|
||||||
|
{
|
||||||
|
error("Test error main")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
object Spawn
|
||||||
|
{
|
||||||
|
def main(args: Array[String]) {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
object Spawn
|
||||||
|
{
|
||||||
|
def main(args: Array[String])
|
||||||
|
{
|
||||||
|
(new ThreadA).start
|
||||||
|
}
|
||||||
|
class ThreadA extends Thread
|
||||||
|
{
|
||||||
|
override def run(): Unit = error("Test error thread")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
project.name=Test Run Errors
|
||||||
|
project.version=10.0
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
$ copy-file changes/RunSuccess.scala src/main/scala/Run.scala
|
||||||
|
[success]
|
||||||
|
> run
|
||||||
|
[success]
|
||||||
|
|
||||||
|
$ copy-file changes/RunFailureMain.scala src/main/scala/Run.scala
|
||||||
|
[success]
|
||||||
|
> run
|
||||||
|
[failure]
|
||||||
|
|
||||||
|
# an exception in a non-main thread should still be exit code 0
|
||||||
|
$ copy-file changes/ThreadRunError.scala src/main/scala/Run.scala
|
||||||
|
[success]
|
||||||
|
> run
|
||||||
|
[success]
|
||||||
Loading…
Reference in New Issue