mirror of https://github.com/sbt/sbt.git
Write JSON to file without String. #1763
This commit is contained in:
parent
0cad84b4bb
commit
40b65c914a
|
|
@ -39,24 +39,16 @@ object Tracked {
|
||||||
}
|
}
|
||||||
private[sbt] def lastOuputWithJson[I, O: Pickler: Unpickler](cacheFile: File)(f: (I, Option[O]) => O): I => O = in =>
|
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)
|
val next = f(in, previous)
|
||||||
toJsonFile(next)(cacheFile)
|
IO.createDirectory(cacheFile.getParentFile)
|
||||||
|
toJsonFile(next, cacheFile)
|
||||||
next
|
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 =>
|
def inputChanged[I, O](cacheFile: File)(f: (Boolean, I) => O)(implicit ic: InputCache[I]): I => O = in =>
|
||||||
{
|
{
|
||||||
val help = new CacheHelp(ic)
|
val help = new CacheHelp(ic)
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ private[sbt] object JsonUtil {
|
||||||
def parseUpdateReport(md: ModuleDescriptor, path: File, cachedDescriptor: File, log: Logger): UpdateReport =
|
def parseUpdateReport(md: ModuleDescriptor, path: File, cachedDescriptor: File, log: Logger): UpdateReport =
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
val s = IO.read(path, IO.utf8)
|
val lite = fromJsonFile[UpdateReportLite](path).get
|
||||||
val lite = fromJsonString[UpdateReportLite](s).get
|
|
||||||
fromLite(lite, cachedDescriptor)
|
fromLite(lite, cachedDescriptor)
|
||||||
} catch {
|
} catch {
|
||||||
case e: Throwable =>
|
case e: Throwable =>
|
||||||
|
|
@ -21,8 +20,8 @@ private[sbt] object JsonUtil {
|
||||||
}
|
}
|
||||||
def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit =
|
def writeUpdateReport(ur: UpdateReport, graphPath: File): Unit =
|
||||||
{
|
{
|
||||||
val str = toJsonString(toLite(ur))
|
IO.createDirectory(graphPath.getParentFile)
|
||||||
IO.write(graphPath, str, IO.utf8)
|
toJsonFile(toLite(ur), graphPath)
|
||||||
}
|
}
|
||||||
def toLite(ur: UpdateReport): UpdateReportLite =
|
def toLite(ur: UpdateReport): UpdateReportLite =
|
||||||
UpdateReportLite(ur.configurations map { cr =>
|
UpdateReportLite(ur.configurations map { cr =>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ object Dependencies {
|
||||||
lazy val ivy = "org.scala-sbt.ivy" % "ivy" % "2.3.0-sbt-fccfbd44c9f64523b61398a0155784dcbaeae28f"
|
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 jsch = "com.jcraft" % "jsch" % "0.1.46" intransitive ()
|
||||||
lazy val sbinary = "org.scala-tools.sbinary" %% "sbinary" % "0.4.2"
|
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 scalaCompiler = Def.setting { "org.scala-lang" % "scala-compiler" % scalaVersion.value }
|
||||||
lazy val testInterface = "org.scala-sbt" % "test-interface" % "1.0"
|
lazy val testInterface = "org.scala-sbt" % "test-interface" % "1.0"
|
||||||
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.4"
|
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.4"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue