summaryrefslogtreecommitdiff
path: root/project/build/Comparator.scala
diff options
context:
space:
mode:
authormoix <moix@epfl.ch>2010-09-07 09:38:32 +0000
committermoix <moix@epfl.ch>2010-09-07 09:38:32 +0000
commit4dcc11418333491b4cb2ed8429e723c42034699d (patch)
treed8c37411a391b5045b36ad2be2ae86e0929c3551 /project/build/Comparator.scala
parent441956b5230a8e9389cdc4a78362c842ba9731ea (diff)
downloadscala-4dcc11418333491b4cb2ed8429e723c42034699d.tar.gz
scala-4dcc11418333491b4cb2ed8429e723c42034699d.tar.bz2
scala-4dcc11418333491b4cb2ed8429e723c42034699d.zip
Stability testing task added.
Diffstat (limited to 'project/build/Comparator.scala')
-rw-r--r--project/build/Comparator.scala72
1 files changed, 72 insertions, 0 deletions
diff --git a/project/build/Comparator.scala b/project/build/Comparator.scala
new file mode 100644
index 0000000000..8b5d65d157
--- /dev/null
+++ b/project/build/Comparator.scala
@@ -0,0 +1,72 @@
+import sbt._
+import java.io.{File,FileInputStream}
+
+// Based on scala.tools.ant.Same
+object Comparator {
+
+ private def getMappedPath(path:Path,baseDirectory:Path):Path= {
+ Path.fromString(baseDirectory,path.relativePath)
+ }
+
+
+ def compare(origin:Path,dest:Path,filter:Path=>PathFinder,log:Logger):Option[String] = {
+ log.info("Comparing the contents of "+origin.absolutePath+ " with "+dest.absolutePath)
+ var allEqualNow = true
+
+ def reportDiff(f1: File, f2: File) = {
+ allEqualNow = false
+ log.error("File '" + f1 + "' is different from correspondant.")
+ }
+
+ def reportMissing(f1: File) = {
+ allEqualNow = false
+ log.error("File '" + f1 + "' has no correspondant.")
+ }
+
+
+
+ val originPaths = filter(origin).get
+
+ val bufferSize = 1024
+ val originBuffer = new Array[Byte](bufferSize)
+ val destBuffer = new Array[Byte](bufferSize)
+
+ for (originPath <- originPaths.filter(! _.isDirectory)){
+ log.debug("origin :" + originPath.absolutePath)
+ val destPath = getMappedPath(originPath,dest)
+ log.debug("dest :" + destPath.absolutePath)
+ var equalNow = true
+ val originFile = originPath.asFile
+ val destFile = destPath.asFile
+
+ if (originFile.canRead && destFile.canRead) {
+
+ val originStream = new FileInputStream(originFile)
+ val destStream = new FileInputStream(destFile)
+ var originRemaining = originStream.read(originBuffer)
+ var destRemaining = destStream.read(destBuffer)
+ while (originRemaining > 0 && equalNow) {
+ if (originRemaining == destRemaining)
+ for (idx <- 0 until originRemaining) {
+ equalNow = equalNow && (originBuffer(idx) == destBuffer(idx))}
+ else
+ equalNow = false
+ originRemaining = originStream.read(originBuffer)
+ destRemaining = destStream.read(destBuffer)
+ }
+ if (destRemaining > 0) equalNow = false
+
+ if (!equalNow) reportDiff(originFile, destFile)
+
+ originStream.close
+ destStream.close
+
+ }
+ else reportMissing(originFile)
+
+ }
+ if(allEqualNow) None else Some("There were differences between "+origin.absolutePath+ " and "+ dest.absolutePath)
+ }
+
+
+}