Skip to content

Instantly share code, notes, and snippets.

@piyo7
Created February 19, 2016 07:25
Show Gist options
  • Save piyo7/2b6708d2ef644e773d3e to your computer and use it in GitHub Desktop.
Save piyo7/2b6708d2ef644e773d3e to your computer and use it in GitHub Desktop.
バージョニングが億劫なので、Gitのコミットハッシュ値を埋めこむ ref: http://qiita.com/piyo7/items/f1b2c27276beadee98be
sbt.version=0.13.9
name := "manifest-reader"
version := "0.0.0"
scalaVersion := "2.11.7"
Seq(com.atlassian.labs.gitstamp.GitStampPlugin.gitStampSettings: _*)
object Main extends App {
val githubUrl = "https://github.com/git/git"
val text = "commit: " +
ManifestReader.gitRev.map(r =>
"[" + r.take(7) + "](" + githubUrl + "/commit/" + r + ")"
).getOrElse("?") + " " +
ManifestReader.gitClean.map {
case false => "[modified]"
case true => ""
}.getOrElse("")
println(text)
}
import java.util.jar.Manifest
import scala.collection.JavaConversions._
import scala.util.control.Exception.allCatch
/** 自身のマニフェストファイル読みこみ */
object ManifestReader {
// クラスパスにあるマニフェスト列
private[this] val manifests = getClass.getClassLoader.
getResources("META-INF/MANIFEST.MF").toSeq.
map(mu => new Manifest(mu.openStream()))
// プロジェクト名で自身のマニフェストファイルを検索
private[this] val mainAttributes = manifests.
map(_.getMainAttributes).
find(_.getValue("Implementation-Title") == "manifest-reader")
def value(key: String): Option[String] = mainAttributes.
flatMap(as => Option(as.getValue(key)))
/** sbt-git-stampが埋めこむGitのローカル状態 */
def gitClean: Option[Boolean] = value("Git-Repo-Is-Clean").
flatMap(s => allCatch.opt(s.toBoolean))
/** sbt-git-stampが埋めこむGitのハッシュ値 */
def gitRev: Option[String] = value("Git-Head-Rev")
}
addSbtPlugin("com.atlassian.labs" % "sbt-git-stamp" % "0.1.2")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment