Created
February 19, 2016 07:25
-
-
Save piyo7/2b6708d2ef644e773d3e to your computer and use it in GitHub Desktop.
バージョニングが億劫なので、Gitのコミットハッシュ値を埋めこむ ref: http://qiita.com/piyo7/items/f1b2c27276beadee98be
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbt.version=0.13.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "manifest-reader" | |
version := "0.0.0" | |
scalaVersion := "2.11.7" | |
Seq(com.atlassian.labs.gitstamp.GitStampPlugin.gitStampSettings: _*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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