~ don't need to reload the app for template changes to be taken into account
authorAlexandre Bertails <bertails@w3.org>
Fri, 26 Aug 2011 10:04:06 -0400
changeset 107 f69944b2a39b
parent 106 9bf0e346e795
child 108 09bfee98db20
~ don't need to reload the app for template changes to be taken into account
src/main/scala/Util.scala
--- a/src/main/scala/Util.scala	Fri Aug 26 01:13:58 2011 -0400
+++ b/src/main/scala/Util.scala	Fri Aug 26 10:04:06 2011 -0400
@@ -53,18 +53,24 @@
    * 
    *  @return the file on disk
    */
-  def fromClasspath(path:String):File = {
-    val dir = new File(System.getProperty("java.io.tmpdir"),
-                       "virtual-trainer-" + scala.util.Random.nextInt(10000).toString)
-    if (! dir.mkdir()) logger.error("Couldn't extract %s from jar to %s" format (path, dir.getAbsolutePath))
-    val entries = getResourceListing(path) foreach { entry =>
-      val url = classloader.getResource(path + entry)
-      val content = Source.fromURL(url, "UTF-8").getLines.mkString("\n")
-      val writer = new FileWriter(new File(dir, entry))
-      writer.write(content)
-      writer.close()
+  def fromClasspath(path:String, base:File = new File("src/main/resources")):File = {
+    val workingPath = new File(base, path)
+    if (workingPath isDirectory) {
+      workingPath
+    } else {
+      val dir = new File(System.getProperty("java.io.tmpdir"),
+                         "virtual-trainer-" + scala.util.Random.nextInt(10000).toString)
+      if (! dir.mkdir()) logger.error("Couldn't extract %s from jar to %s" format (path, dir.getAbsolutePath))
+      val entries = getResourceListing(path) foreach { entry => {
+        val url = classloader.getResource(path + entry)
+        val content = Source.fromURL(url, "UTF-8").getLines.mkString("\n")
+        val writer = new FileWriter(new File(dir, entry))
+        writer.write(content)
+        writer.close()
+      }
     }
     dir
+    }
   }
   
 }