「git describe」の出力を私の見解で表示したいと思います。値を更新し、それをアプリケーション全体に設定するプラグインを作成する必要がありますか?またはこれを行う簡単な方法はありますか?playフレームワークを使用してテンプレートに 'git describe'の出力を入れますか?
4
A
答えて
3
私はちょうど遊びモジュールについて読むと、私は私の問題を解決できるかどうかを確認するために1(https://github.com/killdashnine/play-git-plugin)を書くことにしました:
になりimport java.io.BufferedReader;
import java.io.InputStreamReader;
import play.Logger;
import play.Play;
import play.PlayPlugin;
public class GitPlugin extends PlayPlugin {
private static String GIT_PLUGIN_PREFIX = "GIT plugin: ";
@Override
public void onApplicationStart() {
Logger.info(GIT_PLUGIN_PREFIX + "executing 'git describe'");
final StringBuffer gitVersion = new StringBuffer();
try {
final Process p = Runtime.getRuntime().exec("git describe");
final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
// wait for process to complete
p.waitFor();
// read the output
String line = reader.readLine();
while(line != null) {
gitVersion.append(line);
line = reader.readLine();
}
}
catch(Exception e) {
Logger.error(GIT_PLUGIN_PREFIX + "unable to execute 'git describe'");
}
// set a property for this value
Play.configuration.setProperty("git.revision", gitVersion.toString());
Logger.info(GIT_PLUGIN_PREFIX + "revision is " + gitVersion.toString());
}
}
:私のコントローラで
12:14:46,508 INFO ~ GIT plugin: executing 'git describe'
12:14:46,513 INFO ~ GIT plugin: revision is V0-beta-7-gac9af80
:
@Before
static void addDefaults() {
renderArgs.put("version", Play.configuration.getProperty("git.revision"));
}
もちろん、これは移植性が低く、改善することができます。可能な改善は、構成ファイルの設定を介してカスタムコマンドを実行できるようにすることです。
1
あなたは私のような何ができるのgitリポジトリからコードを実行しない場合、私は、warファイルを生成し、このスクリプトでは、私がやるビルドスクリプトがあります。
cat > {apppath}/conf/application_version.properties << EOF
application.version=`git describe`
application.buildtime=`date`
EOF
...
そして中を@OnApplicationStartクラスIは、プロパティ
private def readApplicationVersion() {
Logger.info("Bootstrap.readApplicationVersion file")
Play.id match {
case "" | "test" => Play.configuration.put("application.version", "TEST-MODE"); Play.configuration.put("application.buildtime", "YEAH BABY YEAH REALTIME")
case _ => addFileProp(VirtualFile.open(Play.applicationPath).child("conf/application_version.properties").inputstream())
}
}
private def addFileProp(input: InputStream) {
input match {
case null => Logger.error("can't find config file, Play id: " + Play.id + ". Will exit now.")
case _ => val extendCconfiguration = IO.readUtf8Properties(input);
for (key <- extendCconfiguration.keys) {
Play.configuration.put(key, extendCconfiguration.get(key))
}
}
}
とコントローラから
object ApplicationVersion extends Controller {
def version = {
Json("{iamVersion: '"+configuration.getProperty("application.version")+"', buildTime: '"+configuration.getProperty("application.buildtime")+"'}")
}
}
を追加します