Write JSON to file without String. #1763

This commit is contained in:
Eugene Yokota 2015-03-06 19:58:38 -05:00
parent e6cc43123a
commit 3952bd8e14
1 changed files with 7 additions and 15 deletions

View File

@ -39,24 +39,16 @@ object Tracked {
}
private[sbt] def lastOuputWithJson[I, O: Pickler: Unpickler](cacheFile: File)(f: (I, Option[O]) => O): I => O = in =>
{
val previous: Option[O] = fromJsonFile[O](cacheFile)
val previous: Option[O] = try {
fromJsonFile[O](cacheFile).toOption
} catch {
case e: Throwable => None
}
val next = f(in, previous)
toJsonFile(next)(cacheFile)
IO.createDirectory(cacheFile.getParentFile)
toJsonFile(next, cacheFile)
next
}
private[sbt] def fromJsonFile[A: Unpickler](file: File): Option[A] =
try {
val s = IO.read(file, IO.utf8)
fromJsonString[A](s).toOption
} catch {
case e: Throwable => None
}
private[sbt] def toJsonFile[A: Pickler](a: A)(file: File): Unit =
{
val str = toJsonString(a)
IO.write(file, str, IO.utf8)
}
def inputChanged[I, O](cacheFile: File)(f: (Boolean, I) => O)(implicit ic: InputCache[I]): I => O = in =>
{
val help = new CacheHelp(ic)