-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.groovy
220 lines (178 loc) · 6.14 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import org.freecompany.redline.Builder
import org.freecompany.redline.header.Architecture
import org.freecompany.redline.header.Os
import org.freecompany.redline.header.RpmType
import org.freecompany.redline.payload.Directive
import tablesaw.*
import tablesaw.addons.GZipRule
import tablesaw.addons.TarRule
import tablesaw.addons.ivy.IvyAddon
import tablesaw.addons.ivy.PomRule
import tablesaw.addons.ivy.PublishRule
import tablesaw.addons.java.Classpath
import tablesaw.addons.java.JarRule
import tablesaw.addons.java.JavaCRule
import tablesaw.addons.java.JavaProgram
import tablesaw.addons.junit.JUnitRule
import tablesaw.definitions.Definition
import tablesaw.rules.CopyRule
import tablesaw.rules.DirectoryRule
import tablesaw.rules.Rule
import tablesaw.rules.SimpleRule
import javax.swing.*
println("===============================================")
saw.setProperty(Tablesaw.PROP_MULTI_THREAD_OUTPUT, Tablesaw.PROP_VALUE_ON)
programName = "kairos-remote"
//Do not use '-' in version string, it breaks rpm uninstall.
version = "1.2.0"
release = saw.getProperty("KAIROS_RELEASE_NUMBER", "1") //package release number
summary = "KairosDB Remote"
description = """\
Remote plugin for KairosDB to send metrics to a remote KairosDB instance.
"""
saw = Tablesaw.getCurrentTablesaw()
saw.includeDefinitionFile("definitions.xml")
rpmDir = "build/rpm"
buildDirRule = new DirectoryRule("build")
new DirectoryRule("target")
rpmDirRule = new DirectoryRule(rpmDir)
//Read pom file to get version out
def pom = new XmlSlurper().parseText(new File("pom.xml").text)
version = pom.version.text()
mvnRule = new SimpleRule("maven-package")
.setDescription("Run maven package build")
.setMakeAction("doMavenBuild")
def doMavenBuild(Rule rule)
{
saw.exec("mvn clean package")
}
//------------------------------------------------------------------------------
//Build zip deployable application
rpmFile = "$programName-$version-${release}.rpm"
srcRpmFile = "$programName-$version-${release}.src.rpm"
libFileSets = [
new RegExFileSet("target", ".*\\.jar"),
new RegExFileSet("target/dependency", ".*\\.jar")
]
scriptsFileSet = new RegExFileSet("src/scripts", ".*").addExcludeFile("kairosdb-env.sh")
webrootFileSet = new RegExFileSet("webroot", ".*").recurse()
zipLibDir = "$programName/lib/kairos-remote"
zipConfDir = "$programName/conf"
tarRule = new TarRule("build/${programName}-${version}-${release}.tar")
.addDepend(mvnRule)
.addDepend(buildDirRule)
.addFileTo(zipConfDir, "src/main/resources", "kairos-remote.properties")
.setFilePermission(".*\\.sh", 0755)
for (AbstractFileSet fs in libFileSets)
tarRule.addFileSetTo(zipLibDir, fs)
gzipRule = new GZipRule("package").setSource(tarRule.getTarget())
.setDescription("Create deployable tar file")
.setTarget("build/${programName}-${version}-${release}.tar.gz")
.addDepend(tarRule)
//------------------------------------------------------------------------------
//Build rpm file
rpmBaseInstallDir = "/opt/kairosdb"
rpmRule = new SimpleRule("package-rpm").setDescription("Build RPM Package")
.addDepend(mvnRule)
.addDepend(rpmDirRule)
.addTarget("$rpmDir/$rpmFile")
.setMakeAction("doRPM")
.setProperty("dependency", "on")
def doRPM(Rule rule)
{
//Build rpm using redline rpm library
host = InetAddress.getLocalHost().getHostName()
rpmBuilder = new Builder()
rpmBuilder.with
{
description = description
group = "System Environment/Daemons"
license = "license"
setPackage(programName, version, release)
setPlatform(Architecture.NOARCH, Os.LINUX)
summary = summary
type = RpmType.BINARY
url = "http://kairosdb.org"
vendor = "KairosDB"
provides = programName
//prefixes = rpmBaseInstallDir
buildHost = host
sourceRpm = srcRpmFile
}
rpmBuilder.addDependencyMore("kairosdb", "1.2.0")
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kairos-remote", new RegExFileSet("target", ".*\\.jar"))
addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kairos-remote", new RegExFileSet("target/dependency", ".*\\.jar"))
rpmBuilder.addFile("$rpmBaseInstallDir/conf/kairos-remote.properties",
new File("src/main/resources/kairos-remote.properties"), 0644, new Directive(Directive.RPMFILE_CONFIG | Directive.RPMFILE_NOREPLACE))
println("Building RPM "+rule.getTarget())
outputFile = new FileOutputStream(rule.getTarget())
rpmBuilder.build(outputFile.channel)
outputFile.close()
}
def addFileSetToRPM(Builder builder, String destination, AbstractFileSet files)
{
for (AbstractFileSet.File file : files.getFiles())
{
File f = new File(file.getBaseDir(), file.getFile())
if (f.getName().endsWith(".sh"))
builder.addFile(destination + "/" +file.getFile(), f, 0755)
else
builder.addFile(destination + "/" + file.getFile(), f)
}
}
debRule = new SimpleRule("package-deb").setDescription("Build Deb Package")
.addDepend(rpmRule)
.setMakeAction("doDeb")
def doDeb(Rule rule)
{
//Prompt the user for the sudo password
//TODO: package using jdeb
def jpf = new JPasswordField()
def password = saw.getProperty("sudo")
if (password == null)
{
def resp = JOptionPane.showConfirmDialog(null,
jpf, "Enter sudo password:",
JOptionPane.OK_CANCEL_OPTION)
if (resp == 0)
password = jpf.getPassword()
}
if (password != null)
{
sudo = saw.createAsyncProcess(rpmDir, "sudo -S alien --bump=0 --to-deb $rpmFile")
sudo.run()
//pass the password to the process on stdin
sudo.sendMessage("$password\n")
sudo.waitForProcess()
if (sudo.getExitCode() != 0)
throw new TablesawException("Unable to run alien application")
}
}
//------------------------------------------------------------------------------
//Build notification
def printMessage(String title, String message) {
osName = saw.getProperty("os.name")
Definition notifyDef
if (osName.startsWith("Linux"))
{
notifyDef = saw.getDefinition("linux-notify")
}
else if (osName.startsWith("Mac"))
{
notifyDef = saw.getDefinition("mac-notify")
}
if (notifyDef != null)
{
notifyDef.set("title", title)
notifyDef.set("message", message)
saw.exec(notifyDef.getCommand())
}
}
def buildFailure(Exception e)
{
printMessage("Build Failure", e.getMessage())
}
def buildSuccess(String target)
{
printMessage("Build Success", target)
}