forked from ferredoxin/QNotified
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.gradle
34 lines (33 loc) · 1.39 KB
/
common.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
gradle.allprojects {
ext.getGitHeadRefsSuffix = {
// .git/HEAD描述当前目录所指向的分支信息,内容示例:"ref: refs/heads/master\n"
def headFile = new File(rootProject.projectDir, '.git' + File.separator + 'HEAD')
if (headFile.exists()) {
String[] strings = headFile.getText('UTF-8').split(" ");
if (strings.size() > 1) {
String refFilePath = '.git' + File.separator + strings[1];
// 根据HEAD读取当前指向的hash值,路径示例为:".git/refs/heads/master"
def refFile = new File(rootProject.projectDir, refFilePath.replace("\n", "").replace("\r", ""));
// 索引文件内容为hash值+"\n",
// 示例:"90312cd9157587d11779ed7be776e3220050b308\n"
return "." + refFile.getText('UTF-8').substring(0, 7)
} else {
return "." + strings[0].substring(0, 7)
}
} else {
println("WARN: .git/HEAD does NOT exist")
return ""
}
}
ext.getBuildIdSuffix = {
try {
String _ci_build_id;
_ci_build_id = System.getenv().get("APPCENTER_BUILD_ID");
if (_ci_build_id != null) return "." + _ci_build_id;
else return "";
} catch (Exception e) {
e.printStackTrace()
}
return ""
}
}