forked from babun/babun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.groovy
executable file
·146 lines (128 loc) · 4.28 KB
/
build.groovy
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env groovy
import static java.lang.System.*
import static java.lang.System.getenv
VERSION = "1.0.0"
TEN_MINUTES = 10
TWENTY_MINUTES = 20
execute()
def execute() {
checkArguments()
String mode = this.args[0]
if (mode == "clean") {
doClean()
} else if (mode == "package") {
doPackage()
} else if (mode == "release") {
doRelease()
}
}
def checkArguments() {
if (this.args.length != 1 || !this.args[0].matches("clean|package|release")) {
err.println "Usage: build.groovy <clean|package|release>"
exit(-1)
}
}
def initEnvironment() {
File target = getTarget()
if (!target.exists()) {
target.mkdir()
}
}
def doClean() {
println "EXEC clean"
File target = getTarget()
if (target.exists()) {
if (!target.deleteDir()) {
throw new RuntimeException("Cannot delete targe folder")
}
}
}
def doPackage() {
println "EXEC package"
executeBabunPackages()
executeBabunCygwin()
executeBabunCore()
executeBabunDist()
}
def doRelease() {
println "EXEC release"
doPackage()
executeRelease()
}
def executeBabunPackages() {
String module = "babun-packages"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String conf = new File(getRoot(), "${module}/conf/").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
def command = ["groovy", "packages.groovy", conf, out]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunCygwin() {
String module = "babun-cygwin"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String input = workingDir.absolutePath
String repo = new File(getTarget(), "babun-packages").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
String pkgs = new File(getRoot(), "babun-packages/conf/cygwin.x86.packages")
def command = ["groovy", "cygwin.groovy", repo, input, out, pkgs]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunCore() {
String module = "babun-core"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String root = getRoot().absolutePath
String cygwin = new File(getTarget(), "babun-cygwin/cygwin").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
String branch = getenv("babun_branch") ? getenv("babun_branch") : "release"
println "Taking babun branch [${branch}]"
def command = ["groovy", "core.groovy", root, cygwin, out, branch]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeBabunDist() {
String module = "babun-dist"
if (shouldSkipModule(module)) return
File workingDir = new File(getRoot(), module);
String input = workingDir.absolutePath
String cygwin = new File(getTarget(), "babun-core/cygwin").absolutePath
String out = new File(getTarget(), "${module}").absolutePath
def command = ["groovy", "dist.groovy", cygwin, input, out, VERSION]
executeCmd(command, workingDir, TEN_MINUTES)
}
def executeRelease() {
assert getenv("bintray_user") != null
assert getenv("bintray_secret") != null
File artifact = new File(getTarget(), "babun-dist/babun-${VERSION}-dist.zip")
def args = ["groovy", "release.groovy", "babun", "babun-dist", VERSION,
artifact.absolutePath, getenv("bintray_user"), getenv("bintray_secret")]
executeCmd(args, getRoot(), TWENTY_MINUTES)
}
def shouldSkipModule(String module) {
File out = new File(getTarget(), module)
if (out.exists()) {
println "SKIP ${module}"
return true
}
println "EXEC ${module}"
return false
}
File getTarget() {
return new File(getRoot(), "target")
}
File getRoot() {
return new File(getClass().protectionDomain.codeSource.location.path).parentFile
}
def executeCmd(List<String> command, File workingDir, int timeout) {
ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.directory(workingDir)
Process process = processBuilder.start()
addShutdownHook { process.destroy() }
process.consumeProcessOutput(out, err)
process.waitForOrKill(timeout * 60000)
assert process.exitValue() == 0
}
def getReleaseScript() {
new File(getRoot(), "release.groovy")
}