From 964cceed6db7b028d694521d251f236ca0c0ccb5 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 14 Sep 2010 00:39:59 +0000 Subject: Tweaking sbt so it will stop jabbering about sv... Tweaking sbt so it will stop jabbering about svn info failing when there's a perfectly fine git repo yet to be tried. No review. --- project/build/SVN.scala | 23 +++++++++++------------ project/build/ScalaSBTBuilder.scala | 19 ++++--------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/project/build/SVN.scala b/project/build/SVN.scala index 2d9fb9259b..6a4f845cbc 100644 --- a/project/build/SVN.scala +++ b/project/build/SVN.scala @@ -1,6 +1,4 @@ import sbt._ -import java.io.{ByteArrayOutputStream} -import scala.util.matching.{Regex} /** * @param root the root of an svn repository @@ -9,6 +7,7 @@ import scala.util.matching.{Regex} class SVN(root: Path) { /** Location of tool which parses svn revision in git-svn repository. */ val GitSvnRevTool = root / "tools" / "get-git-svn-rev" + val GitSvnRegex = """^Revision:\s*(\d+).*""".r /** * Gets the revision number of the repository given through the constructor of the class @@ -17,18 +16,18 @@ class SVN(root: Path) { */ def getRevisionNumber: Int = getSvn orElse getGit getOrElse 0 def getSvn: Option[Int] = { - val svnInfo = Process("svn info", root) - val out = new ByteArrayOutputStream - val code:Int = svnInfo.#>(out).! + /** Doing this the hard way trying to suppress the svn error message + * on stderr. Could not figure out how to do it simply in sbt. + */ + val pb = new java.lang.ProcessBuilder("svn", "info") + pb directory root.asFile + pb redirectErrorStream true - if (code == 0) { - val r = out.toString - val Pattern = new Regex("""Revision: (\d+)""", "version") - val version = Pattern.findFirstMatchIn(r) - - version map (_.group("version").toInt) + Process(pb).lines_! foreach { + case GitSvnRegex(rev) => return Some(rev.toInt) + case _ => () } - else None + None } def getGit: Option[Int] = diff --git a/project/build/ScalaSBTBuilder.scala b/project/build/ScalaSBTBuilder.scala index 530a1ca538..80b79f778d 100644 --- a/project/build/ScalaSBTBuilder.scala +++ b/project/build/ScalaSBTBuilder.scala @@ -37,25 +37,14 @@ class ScalaSBTBuilder(val info: ProjectInfo) extends Project with ReflectivePro * until sbt quit. */ lazy val versionNumber:String ={ - def getTimeString:String ={ + def getTimeString: String = { import java.util.Calendar; import java.text.SimpleDateFormat; val formatString = "yyyyMMddHHmmss" - new SimpleDateFormat(formatString) format(Calendar.getInstance.getTime) - } - - def getVersion:String ={ - val version:String = projectVersion.value.toString - val stopIndex = version.lastIndexOf('-') - stopIndex match{ - case -1 => version - case i => version substring(0,i) - } - } - - def getRevision:Int = { - new SVN(info.projectPath).getRevisionNumber + new SimpleDateFormat(formatString) format Calendar.getInstance.getTime } + def getVersion: String = projectVersion.value.toString takeWhile (_ != '-') mkString + def getRevision: Int = new SVN(info.projectPath) getRevisionNumber getVersion+".r"+getRevision+"-b"+getTimeString } -- cgit v1.2.3