From fdf9be166f2cff7a8eaddab76ca018d3b86eb982 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Mon, 7 May 2012 11:49:53 +1200 Subject: [PATCH] Add helper methods to IC for reading analysis cache files --- compile/integration/IncrementalCompiler.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compile/integration/IncrementalCompiler.scala b/compile/integration/IncrementalCompiler.scala index c3a3ff322..71cda4b79 100644 --- a/compile/integration/IncrementalCompiler.scala +++ b/compile/integration/IncrementalCompiler.scala @@ -1,5 +1,6 @@ package sbt.compiler + import sbt.CompileSetup import sbt.inc.Analysis import xsbti.{Logger, Maybe} import xsbti.compile._ @@ -29,4 +30,17 @@ object IC extends IncrementalCompiler[Analysis, AnalyzingCompiler] val raw = new RawCompiler(instance, sbt.ClasspathOptions.auto, log) AnalyzingCompiler.compileSources(sourceJar :: Nil, targetJar, interfaceJar :: Nil, label, raw, log) } + + def readCache(file: File): Option[(Analysis, CompileSetup)] = + try { Some(readCacheUncaught(file)) } catch { case _: Exception => None } + + def readAnalysis(file: File): Analysis = + try { readCacheUncaught(file)._1 } catch { case _: Exception => Analysis.Empty } + + def readCacheUncaught(file: File): (Analysis, CompileSetup) = + { + import sbinary.DefaultProtocol.{immutableMapFormat, immutableSetFormat, StringFormat, tuple2Format} + import sbt.inc.AnalysisFormats._ + sbt.IO.gzipFileIn(file)( in => sbinary.Operations.read[(Analysis, CompileSetup)](in) ) + } }