Skip to content

Instantly share code, notes, and snippets.

@olim7t
Created February 7, 2012 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olim7t/1758858 to your computer and use it in GitHub Desktop.
Save olim7t/1758858 to your computer and use it in GitHub Desktop.
/* 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