alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (SVN.scala)

This example Scala source code file (SVN.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

exception, gitsvnregex, gitsvnregex, gitsvnrevtool, int, none, none, option, option, path, revision:\s*, revision:\s*, svn

The Scala SVN.scala source code

import sbt._

/**
 * @param root the root of an svn repository
 * @author Moix Grégory
 */
class SVN(root: Path) {
  /** Location of tool which parses svn revision in git-svn repository. */
  val GitSvnRevTool = root / "tools" / "get-scala-revision"
  val GitSvnRegex   = """^Revision:\s*(\d+).*""".r

  /**
   * Gets the revision number of the repository given through the constructor of the class
   * It assumes that svn or git is installed on the running computer. Return 0 if it was not
   * able to found the revision number
   */
  def getRevisionNumber: Int = getSvn orElse getGit getOrElse 0  
  def getSvn: Option[Int] = {
    /** 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
    
    Process(pb).lines_! foreach {
      case GitSvnRegex(rev) => return Some(rev.toInt)
      case _                => ()
    }
    None
  }
   
  def getGit: Option[Int] =    
    try   { Some(Process(GitSvnRevTool.toString, root).!!.trim.toInt) }
    catch { case _: Exception => None }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala SVN.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.