mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-21 05:05:31 +00:00
Gradle: preBuild taks generates git.xml in res - usable with getString(R.string.git_hash)
This commit is contained in:
@@ -31,3 +31,4 @@ gen/
|
||||
out/
|
||||
.gradle
|
||||
local.properties
|
||||
git.xml
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
apply plugin: "com.android.application"
|
||||
apply from: "../git.gradle"
|
||||
|
||||
def packageName = "com.sap.sailing.android.tracking.app"
|
||||
def verCode = 1
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
apply plugin: "com.android.application"
|
||||
apply from: "../git.gradle"
|
||||
|
||||
def packageName = "com.sap.sailing.racecommittee.app"
|
||||
def verCode = 6
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* returns current git hash
|
||||
*/
|
||||
def getGitHash = { ->
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine "git", "log", "-n", "1", "--format='%h'"
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim().replace("'", "")
|
||||
}
|
||||
|
||||
/**
|
||||
* set git hash into git.xml
|
||||
*/
|
||||
preBuild.doLast {
|
||||
copy {
|
||||
from ("../git.template.xml")
|
||||
|
||||
into ("res/values")
|
||||
|
||||
rename {
|
||||
String fileName -> fileName.replace(".template", "")
|
||||
}
|
||||
|
||||
filter {
|
||||
String line -> line.replaceAll("#GITHASH#", getGitHash())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="git_hash" translatable="false">#GITHASH#</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user