Created
February 7, 2012 09:56
-
-
Save olim7t/1758858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Finds the version history of a POM in a Subversion repository */ | |
import scala.sys.process.Process | |
object Conf { | |
val url = "put the url of your POM here" | |
val svn = "svn --username xxx" | |
} | |
case class Revision(number: Int, date: String, version: String) { | |
override def toString = productIterator.mkString("; ") | |
} | |
def removeConsecutiveDuplicates[A](s: Stream[A], same: (A, A) => Boolean): Stream[A] = | |
if (s.isEmpty) s else | |
Stream.cons(s.head, removeConsecutiveDuplicates(s.dropWhile(same(s.head, _)), same)) | |
def pomVersions(start: String, end: String) = { | |
val runSvnLog = Conf.svn + " log " + Conf.url + " -r" + start + ":" + end | |
val svnLogPattern = """^r(\d+) \| \w+ \| (.*) \+""".r | |
val pomVersionPattern = "<version>(.*)</version>".r | |
def pomVersionAt(revision: Int) = { | |
val runSvnCat = Conf.svn + " cat " + Conf.url + " -r" + revision | |
val pomContents = Process(runSvnCat).!! | |
pomVersionPattern.findFirstMatchIn(pomContents).map(_.group(1)).getOrElse("no version found") | |
} | |
val revisions = for { | |
line <- Process(runSvnLog).lines | |
m <- svnLogPattern.findFirstMatchIn(line) | |
number = m.group(1).toInt | |
date = m.group(2) | |
version = pomVersionAt(number) | |
} yield Revision(number, date, version) | |
def sameVersion(r1: Revision, r2: Revision) = r1.version == r2.version | |
removeConsecutiveDuplicates(revisions, sameVersion) | |
} | |
println(pomVersions("12000", "HEAD").mkString("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment