Skip to content

Instantly share code, notes, and snippets.

@d6y
Created January 19, 2012 10:31
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 d6y/1639308 to your computer and use it in GitHub Desktop.
Save d6y/1639308 to your computer and use it in GitHub Desktop.
Snipet for reading version.txt
package org.example.project.snippet
import scala.xml._
import net.liftweb.util.Helpers._
/* Access to the build number (e.g., supplied by Hudson/Jenkins)
Example usage:
<lift:App.version> Project:<v:project/> Build:<v:number/> </lift:App.version>
Kick off SBT with:
-Dbuild.number=$BUILD_NUMBER -Dbuild.vcs.number=master
(change master to pilot on pilot builds).
*/
class App {
// Wrapper Java Properties to give us Option rather than null
class Properties(path: String) {
import java.util.{Properties => JProps}
private def propsFrom(in: java.io.InputStream): JProps = {
val p = new JProps
p.load(in)
p
}
private val props: Option[JProps] = for {
stream <- Option(getClass getResourceAsStream path)
} yield propsFrom(stream)
def apply(key: String): Option[String] = for {
jp <- props
v <- Option(jp getProperty key)
} yield v
}
private lazy val props = new Properties("/version.txt")
private def get(key: String): Text = Text(props(key) getOrElse "dev")
def version(xhtml: NodeSeq) = bind("v", xhtml,
"project" -> get("Revision"), // we map this to branch in our Hudson builds
"number" -> get("Build") )
/*
The version.txt file produced by the Guardian sbt plugin:
Build: 87
Built-By: hudson
Built-On: ip-10-224-66-18
Date: Tue Nov 22 16:20:42 UTC 2011
Revision: pilot
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment