-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
97 lines (75 loc) · 2.23 KB
/
build.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.text.SimpleDateFormat
//region Build Script
buildscript {
repositories {
apply from: "versions.gradle"
addRepos(repositories)
}
dependencies {
classpath deps.build.android_gradle_plugin
classpath deps.build.butterknife_plugin
}
}
//endregion
//region All Projects
allprojects {
repositories {
addRepos(repositories)
}
}
//endregion
//region Tasks
task clean(type: Delete) {
delete rootProject.buildDir
}
//endregion
//region Naming
@SuppressWarnings("GroovyUnusedDeclaration")
static def getProjectName() {
return "RabbitMQ Management"
}
//endregion
//region Versioning
@SuppressWarnings("GroovyUnusedDeclaration")
static def getAutoVersionName() {
def (major, minor, patch, build, sha) = getLastMasterGitTagVersion()
def code = getAutoVersionCode()
def date = getBuildDate()
return (getCurrentBranch() == "master") ? "${major}.${minor}.${patch}" : "${sha}-${date} ($code)"
}
@SuppressWarnings("GroovyUnusedDeclaration")
static def getDevelopVersionCode() {
def count = getGitCommitsCount()
return (count == null || count.empty) ? 0 : count.toInteger()
}
@SuppressWarnings("GroovyUnusedDeclaration")
static def getProductionVersionCode() {
def (major, minor, patch, build, sha) = getLastMasterGitTagVersion()
return major.toInteger() * 1_000_000 + minor.toInteger() * 1_000 + patch.toInteger()
}
@SuppressWarnings("GroovyUnusedDeclaration")
static def getAutoVersionCode() {
def branch = getCurrentBranch()
if (branch == "master") {
return getProductionVersionCode()
}
return getDevelopVersionCode()
}
static def getCurrentBranch() {
return "git rev-parse --abbrev-ref HEAD".execute().text.trim()
}
static def getBuildDate() {
def df = new SimpleDateFormat("dd.MM.yyyy")
df.setTimeZone(TimeZone.getDefault())
return df.format(new Date())
}
static def getGitCommitsCount() {
return ("git rev-list ${getCurrentBranch()} --count").execute().text.trim()
}
static def getLastMasterGitTagVersion() {
def name = "git describe --tags ${getCurrentBranch()} --long".execute().text.replace("v", "").trim()
def (tag, build, sha) = name.tokenize('-')
def (major, minor, patch) = (tag != null) ? tag.tokenize('.') : [0, 0, 0]
return [major, minor, patch, build, sha]
}
//endregion