From 40b65c914a435d8cb54ea64efbd7eeafd8846047 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 6 Mar 2015 19:58:38 -0500 Subject: [PATCH] Write JSON to file without String. #1763 --- .../tracking/src/main/scala/sbt/Tracked.scala | 22 ++++++------------- ivy/src/main/scala/sbt/JsonUtil.scala | 7 +++--- project/Dependencies.scala | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/cache/tracking/src/main/scala/sbt/Tracked.scala b/cache/tracking/src/main/scala/sbt/Tracked.scala index 028d385c2..13119df3a 100644 --- a/cache/tracking/src/main/scala/sbt/Tracked.scala +++ b/cache/tracking/src/main/scala/sbt/Tracked.scala @@ -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) diff --git a/ivy/src/main/scala/sbt/JsonUtil.scala b/ivy/src/main/scala/sbt/JsonUtil.scala index ddd126555..88d7e1e90 100644 --- a/ivy/src/main/scala/sbt/JsonUtil.scala +++ b/ivy/src/main/scala/sbt/JsonUtil.scala @@ -10,8 +10,7 @@ private[sbt] object JsonUtil { def parseUpdateReport(md: ModuleDescriptor, path: File, cachedDescriptor: File, log: Logger): UpdateReport = { try { - val s = IO.read(path, IO.utf8) - val lite = fromJsonString[UpdateReportLite](s).get + val lite = fromJsonFile[UpdateReportLite](path).get fromLite(lite, cachedDescriptor) } catch { case e: Throwable => @@ -21,8 +20,8 @@ private[sbt] object JsonUtil { } def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit = { - val str = toJsonString(toLite(ur)) - IO.write(graphPath, str, IO.utf8) + IO.createDirectory(graphPath.getParentFile) + toJsonFile(toLite(ur), graphPath) } def toLite(ur: UpdateReport): UpdateReportLite = UpdateReportLite(ur.configurations map { cr => diff --git a/project/Dependencies.scala b/project/Dependencies.scala index b28fa4c00..8bb961a54 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -12,7 +12,7 @@ object Dependencies { lazy val ivy = "org.scala-sbt.ivy" % "ivy" % "2.3.0-sbt-fccfbd44c9f64523b61398a0155784dcbaeae28f" lazy val jsch = "com.jcraft" % "jsch" % "0.1.46" intransitive () lazy val sbinary = "org.scala-tools.sbinary" %% "sbinary" % "0.4.2" - lazy val sbtSerialization = "org.scala-sbt" %% "serialization" % "0.1.0" + lazy val sbtSerialization = "org.scala-sbt" %% "serialization" % "0.1.1-1479903c3135da50e0442c91e707743311a4f362" lazy val scalaCompiler = Def.setting { "org.scala-lang" % "scala-compiler" % scalaVersion.value } lazy val testInterface = "org.scala-sbt" % "test-interface" % "1.0" lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.4"