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,10 +77,7 @@ 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) =>
|
||||||
{
|
|
||||||
(settings: Settings) =>
|
|
||||||
{
|
|
||||||
Control.trapUnit("Error during run: ", log)
|
Control.trapUnit("Error during run: ", log)
|
||||||
{
|
{
|
||||||
val classpathURLs = classpath.map(_.asURL).toList
|
val classpathURLs = classpath.map(_.asURL).toList
|
||||||
|
|
@ -97,7 +94,6 @@ object Run extends ScalaRun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/** If mainClassOption is None, then the interactive scala interpreter is started with the given classpath.
|
/** If mainClassOption is None, then the interactive scala interpreter is started with the given classpath.
|
||||||
* Otherwise, the class wrapped by Some is run using the scala runner with the given classpath and
|
* Otherwise, the class wrapped by Some is run using the scala runner with the given classpath and
|
||||||
* options. */
|
* options. */
|
||||||
|
|
|
||||||
|
|
@ -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