aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authoreaceaser <eac@twitter.com>2010-10-24 17:37:51 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-07 02:08:37 -0500
commit9cdad3866cb2d1ee2ef4566972bc62fc30c42547 (patch)
treef0b4e6769f41003c8e978b227b6d63484ff2303b /libraries
parent854e3f8c865e0b00bca571df07b71d369d8fbfba (diff)
downloadcbt-9cdad3866cb2d1ee2ef4566972bc62fc30c42547.tar.gz
cbt-9cdad3866cb2d1ee2ef4566972bc62fc30c42547.tar.bz2
cbt-9cdad3866cb2d1ee2ef4566972bc62fc30c42547.zip
Place compiled files in their own temporary subdir and clear when jvm
closes.
Diffstat (limited to 'libraries')
-rw-r--r--libraries/eval/Eval.scala19
1 files changed, 12 insertions, 7 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala
index 702c974..3d8be88 100644
--- a/libraries/eval/Eval.scala
+++ b/libraries/eval/Eval.scala
@@ -68,7 +68,7 @@ import scala.tools.nsc.{Global, Settings}
object Eval {
private val compilerPath = jarPathOfClass("scala.tools.nsc.Interpreter")
private val libPath = jarPathOfClass("scala.ScalaObject")
- private val jvmId = Math.abs(new Random().nextInt())
+ private val jvmId = java.lang.Math.abs(new Random().nextInt())
private val md = MessageDigest.getInstance("SHA")
/**
@@ -79,8 +79,9 @@ object Eval {
val digest = md.digest(stringToEval.getBytes())
val sha = new BigInteger(digest).toString(16)
- val className = "Evaluator" + sha + "_" + jvmId
- val targetDir = new File(System.getProperty("java.io.tmpdir"))
+ val uniqueId = sha + "_" + jvmId
+ val className = "Evaluator" + uniqueId
+ val targetDir = new File(System.getProperty("java.io.tmpdir") + "evaluator_" + uniqueId)
ifUncompiled(targetDir, className) { targetFile =>
wrapInClassAndOutput(stringToEval, className, targetFile)
compile(targetFile, targetDir)
@@ -99,18 +100,22 @@ object Eval {
apply(stringToEval)
}
- private def ifUncompiled(targetDir: File, className: String)(work: File => Unit) {
+ private def ifUncompiled(targetDir: File, className: String)(f: File => Unit) {
+ targetDir.mkdirs()
+ targetDir.deleteOnExit()
+
val targetFile = new File(targetDir, className + ".scala")
if (!targetFile.exists) {
val created = targetFile.createNewFile()
if (!created) {
- // FIXME: this indicates that either another jvm randomly generated the same
+ // FIXME: this indicates that another jvm randomly generated the same
// integer and compiled this file. Or, more likely, this method was called
// simultaneously from two threads.
}
- targetFile.deleteOnExit()
- work(targetFile)
+ f(targetFile)
}
+
+ targetDir.listFiles().foreach { _.deleteOnExit() }
}
/**