forked from duckduckgo/Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioning.gradle
100 lines (87 loc) · 3.15 KB
/
versioning.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
98
99
100
ext {
buildVersionCode = {
def versionName = getVersionName()
def (major, minor, patch) = versionName.toLowerCase().tokenize('.')
(major, minor, patch) = [major, minor, patch].collect { it.toInteger() }
(major * 10_000_000) + (minor * 10_000) + (patch * 1_000) + buildNumberCode()
}
getVersionName = {
def props = new Properties()
file("$rootDir/app/version/version.properties").withInputStream { props.load(it) }
return props.getProperty("VERSION")
}
getVersionNameSuffix = {
if (project.hasProperty("versionNameSuffix")) {
return project["versionNameSuffix"]
} else {
return ""
}
}
buildVersionName = {
def suffix = getVersionNameSuffix()
if (suffix?.trim()) {
return getVersionName() + "." + buildNumberCode() + getVersionNameSuffix()
} else {
return getVersionName()
}
}
buildNumberCode = {
filePath = "${CI_HOME_DIR}/build_number.properties"
if(!new File(filePath).exists()) return 0
def suffix = getVersionNameSuffix()
if (suffix?.trim()) {
def props = new Properties()
props.load(new FileInputStream(filePath))
String buildNumber = props["build"]
if (buildNumber == null) return 0 else return Integer.valueOf(buildNumber)
} else {
return 0
}
}
}
tasks.register("setBuildNumber") {
doLast {
if(!project.hasProperty("number")) {
throw new IllegalArgumentException("Missing argument: 'number' must be provided")
}
filePath = "${CI_HOME_DIR}/build_number.properties"
if(!new File(filePath).exists()) {
throw new IllegalStateException("build number file could not be found at: $filePath")
}
String buildNumberString = project["number"]
Integer buildNumberInt = Integer.parseInt(buildNumberString)
if(buildNumberInt >= 1000) {
throw new IllegalStateException("Build number limited to 3 digits; cannot exceed 1,000")
}
println("Setting build number to: $buildNumberInt")
def props = new Properties()
props.load(new FileInputStream(filePath))
props["build"] = buildNumberInt.toString()
def os = new FileOutputStream(filePath)
props.store(os, null)
}
}
tasks.register('incrementBuildNumber') {
doLast {
filePath = "${CI_HOME_DIR}/build_number.properties"
if(!new File(filePath).exists()) {
return
}
def props = new Properties()
props.load(new FileInputStream(filePath))
String currentBuildNumber = props["build"]
Integer buildNumber = Integer.parseInt(currentBuildNumber)
buildNumber++
if(buildNumber >= 1000) {
throw new IllegalStateException("Build number limited to 3 digits; cannot exceed 1,000")
}
props["build"] = buildNumber.toString()
def os = new FileOutputStream(filePath)
props.store(os, null)
}
}
tasks.register('getBuildVersionName') {
doLast {
print buildVersionName()
}
}