diff options
author | Lex Spoon <lex@lexspoon.org> | 2007-07-24 15:22:30 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2007-07-24 15:22:30 +0000 |
commit | c2bab2c122aac19ecec78d631291526e42af0e93 (patch) | |
tree | c59d4bcd6189e4aa37b3b23b29aa674779d5d89d | |
parent | 399cfa2a089eb55b157d6a281da8ad9cb253e9c4 (diff) | |
download | scala-c2bab2c122aac19ecec78d631291526e42af0e93.tar.gz scala-c2bab2c122aac19ecec78d631291526e42af0e93.tar.bz2 scala-c2bab2c122aac19ecec78d631291526e42af0e93.zip |
delay the deletion of compiled files until the
JVM is ready to exit (bug #1218)
-rw-r--r-- | src/compiler/scala/tools/nsc/ScriptRunner.scala | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index cceed5b5c9..3266ec3799 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -284,6 +284,10 @@ class ScriptRunner { compiledPath.delete // the file is created as a file; make it a directory compiledPath.mkdirs + // delete the directory after the user code has finished + Runtime.getRuntime.addShutdownHook(new Thread { + override def run { deleteRecursively(compiledPath) }}) + settings.outdir.value = compiledPath.getPath if (settings.nocompdaemon.value) { @@ -316,31 +320,24 @@ class ScriptRunner { // The pre-compiled jar is old. Recompile the script. jarFile.delete val (compiledPath, compok) = compile - try { - if (compok) { - tryMakeJar(jarFile, compiledPath) - if (jarOK) { - deleteRecursively(compiledPath) - handler(jarFile.getAbsolutePath) - } else { - // run from the interpreter's temporary - // directory - handler(compiledPath.getPath) - } + + if (compok) { + tryMakeJar(jarFile, compiledPath) + if (jarOK) { + deleteRecursively(compiledPath) // may as well do it now + handler(jarFile.getAbsolutePath) + } else { + // jar failed; run directly from the class files + handler(compiledPath.getPath) } - } finally { - deleteRecursively(compiledPath) } } } else { - // don't use the cache; just run from the interpreter's temporary directory + // don't use a cache jar at all--just use the class files val (compiledPath, compok) = compile - try { - if (compok) - handler(compiledPath.getPath) - } finally { - deleteRecursively(compiledPath) - } + + if (compok) + handler(compiledPath.getPath) } } |