|
| 1 | +import org.freecompany.redline.Builder |
| 2 | +import org.freecompany.redline.header.Architecture |
| 3 | +import org.freecompany.redline.header.Os |
| 4 | +import org.freecompany.redline.header.RpmType |
| 5 | +import org.freecompany.redline.payload.Directive |
| 6 | +import tablesaw.* |
| 7 | +import tablesaw.addons.GZipRule |
| 8 | +import tablesaw.addons.TarRule |
| 9 | +import tablesaw.addons.ivy.IvyAddon |
| 10 | +import tablesaw.addons.ivy.PomRule |
| 11 | +import tablesaw.addons.ivy.PublishRule |
| 12 | +import tablesaw.addons.java.Classpath |
| 13 | +import tablesaw.addons.java.JarRule |
| 14 | +import tablesaw.addons.java.JavaCRule |
| 15 | +import tablesaw.addons.java.JavaProgram |
| 16 | +import tablesaw.addons.junit.JUnitRule |
| 17 | +import tablesaw.definitions.Definition |
| 18 | +import tablesaw.rules.CopyRule |
| 19 | +import tablesaw.rules.DirectoryRule |
| 20 | +import tablesaw.rules.Rule |
| 21 | +import tablesaw.rules.SimpleRule |
| 22 | + |
| 23 | +import javax.swing.* |
| 24 | + |
| 25 | +println("===============================================") |
| 26 | + |
| 27 | +saw.setProperty(Tablesaw.PROP_MULTI_THREAD_OUTPUT, Tablesaw.PROP_VALUE_ON) |
| 28 | + |
| 29 | +programName = "kairos-kafka-monitor" |
| 30 | +//Do not use '-' in version string, it breaks rpm uninstall. |
| 31 | +version = "1.3.0" |
| 32 | +release = saw.getProperty("KAIROS_RELEASE_NUMBER", "0.1beta") //package release number |
| 33 | +summary = "KairosDB" |
| 34 | +description = """\ |
| 35 | +KairosDB is a time series database that stores numeric values along |
| 36 | +with key/value tags to a nosql data store. Currently supported |
| 37 | +backends are Cassandra and H2. An H2 implementation is provided |
| 38 | +for development work. |
| 39 | +""" |
| 40 | + |
| 41 | + |
| 42 | +saw = Tablesaw.getCurrentTablesaw() |
| 43 | +saw.includeDefinitionFile("definitions.xml") |
| 44 | + |
| 45 | + |
| 46 | +rpmDir = "build/rpm" |
| 47 | +new DirectoryRule("build") |
| 48 | +rpmDirRule = new DirectoryRule(rpmDir) |
| 49 | + |
| 50 | +//Read pom file to get version out |
| 51 | +def pom = new XmlSlurper().parseText(new File("pom.xml").text) |
| 52 | +version = pom.version.text() |
| 53 | + |
| 54 | +mvnRule = new SimpleRule("maven-package") |
| 55 | + .setDescription("Run maven package build") |
| 56 | + .setMakeAction("doMavenBuild") |
| 57 | + |
| 58 | +def doMavenBuild(Rule rule) |
| 59 | +{ |
| 60 | + saw.exec("mvn clean package") |
| 61 | +} |
| 62 | + |
| 63 | +//------------------------------------------------------------------------------ |
| 64 | +//Build zip deployable application |
| 65 | +rpmFile = "$programName-$version-${release}.rpm" |
| 66 | +srcRpmFile = "$programName-$version-${release}.src.rpm" |
| 67 | +ivyFileSet = new SimpleFileSet() |
| 68 | + |
| 69 | + |
| 70 | +libFileSets = [ |
| 71 | + new RegExFileSet("build/jar", ".*\\.jar"), |
| 72 | + new RegExFileSet("lib", ".*\\.jar"), |
| 73 | + ivyFileSet |
| 74 | +] |
| 75 | + |
| 76 | +scriptsFileSet = new RegExFileSet("src/scripts", ".*").addExcludeFile("kairosdb-env.sh") |
| 77 | +webrootFileSet = new RegExFileSet("webroot", ".*").recurse() |
| 78 | + |
| 79 | +zipLibDir = "$programName/lib" |
| 80 | +zipBinDir = "$programName/bin" |
| 81 | +zipConfDir = "$programName/conf" |
| 82 | +zipConfLoggingDir = "$zipConfDir/logging" |
| 83 | +zipWebRootDir = "$programName/webroot" |
| 84 | +tarRule = new TarRule("build/${programName}-${version}-${release}.tar") |
| 85 | + .addDepend(mvnRule) |
| 86 | + .addFileSetTo(zipBinDir, scriptsFileSet) |
| 87 | + .addFileSetTo(zipWebRootDir, webrootFileSet) |
| 88 | + .addFileTo(zipConfDir, "src/main/resources", "kairosdb.conf") |
| 89 | + .addFileTo(zipConfLoggingDir, "src/main/resources", "logback.xml") |
| 90 | + .setFilePermission(".*\\.sh", 0755) |
| 91 | + |
| 92 | +for (AbstractFileSet fs in libFileSets) |
| 93 | + tarRule.addFileSetTo(zipLibDir, fs) |
| 94 | + |
| 95 | + |
| 96 | +gzipRule = new GZipRule("package").setSource(tarRule.getTarget()) |
| 97 | + .setDescription("Create deployable tar file") |
| 98 | + .setTarget("build/${programName}-${version}-${release}.tar.gz") |
| 99 | + .addDepend(tarRule) |
| 100 | + |
| 101 | +//------------------------------------------------------------------------------ |
| 102 | +//Build rpm file |
| 103 | +rpmBaseInstallDir = "/opt/kairosdb" |
| 104 | +rpmRule = new SimpleRule("package-rpm").setDescription("Build RPM Package") |
| 105 | + .addDepend(mvnRule) |
| 106 | + .addDepend(rpmDirRule) |
| 107 | + .addTarget("$rpmDir/$rpmFile") |
| 108 | + .setMakeAction("doRPM") |
| 109 | + .setProperty("dependency", "on") |
| 110 | + |
| 111 | + |
| 112 | +def doRPM(Rule rule) |
| 113 | +{ |
| 114 | + //Build rpm using redline rpm library |
| 115 | + host = InetAddress.getLocalHost().getHostName() |
| 116 | + rpmBuilder = new Builder() |
| 117 | + rpmBuilder.with |
| 118 | + { |
| 119 | + description = description |
| 120 | + group = "System Environment/Daemons" |
| 121 | + license = "license" |
| 122 | + setPackage(programName, version, release) |
| 123 | + setPlatform(Architecture.NOARCH, Os.LINUX) |
| 124 | + summary = summary |
| 125 | + type = RpmType.BINARY |
| 126 | + url = "http://kairosdb.org" |
| 127 | + vendor = "KairosDB" |
| 128 | + provides = programName |
| 129 | + //prefixes = rpmBaseInstallDir |
| 130 | + buildHost = host |
| 131 | + sourceRpm = srcRpmFile |
| 132 | + } |
| 133 | + |
| 134 | + rpmBuilder.addDependencyMore("kairosdb", "1.2.0") |
| 135 | + |
| 136 | + addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target", ".*\\.jar")) |
| 137 | + addFileSetToRPM(rpmBuilder, "$rpmBaseInstallDir/lib/kafka-monitor", new RegExFileSet("target/dependency", ".*\\.jar")) |
| 138 | + |
| 139 | + |
| 140 | + rpmBuilder.addFile("$rpmBaseInstallDir/conf/kafka-monitor.properties", |
| 141 | + new File("src/main/resources/kafka-monitor.properties"), 0644, new Directive(Directive.RPMFILE_CONFIG | Directive.RPMFILE_NOREPLACE)) |
| 142 | + |
| 143 | + |
| 144 | + println("Building RPM "+rule.getTarget()) |
| 145 | + outputFile = new FileOutputStream(rule.getTarget()) |
| 146 | + rpmBuilder.build(outputFile.channel) |
| 147 | + outputFile.close() |
| 148 | +} |
| 149 | + |
| 150 | +def addFileSetToRPM(Builder builder, String destination, AbstractFileSet files) |
| 151 | +{ |
| 152 | + |
| 153 | + for (AbstractFileSet.File file : files.getFiles()) |
| 154 | + { |
| 155 | + File f = new File(file.getBaseDir(), file.getFile()) |
| 156 | + if (f.getName().endsWith(".sh")) |
| 157 | + builder.addFile(destination + "/" +file.getFile(), f, 0755) |
| 158 | + else |
| 159 | + builder.addFile(destination + "/" + file.getFile(), f) |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +debRule = new SimpleRule("package-deb").setDescription("Build Deb Package") |
| 164 | + .addDepend(rpmRule) |
| 165 | + .setMakeAction("doDeb") |
| 166 | + |
| 167 | +def doDeb(Rule rule) |
| 168 | +{ |
| 169 | + //Prompt the user for the sudo password |
| 170 | + //TODO: package using jdeb |
| 171 | + def jpf = new JPasswordField() |
| 172 | + def password = saw.getProperty("sudo") |
| 173 | + |
| 174 | + if (password == null) |
| 175 | + { |
| 176 | + def resp = JOptionPane.showConfirmDialog(null, |
| 177 | + jpf, "Enter sudo password:", |
| 178 | + JOptionPane.OK_CANCEL_OPTION) |
| 179 | + |
| 180 | + if (resp == 0) |
| 181 | + password = jpf.getPassword() |
| 182 | + } |
| 183 | + |
| 184 | + if (password != null) |
| 185 | + { |
| 186 | + sudo = saw.createAsyncProcess(rpmDir, "sudo -S alien --bump=0 --to-deb $rpmFile") |
| 187 | + sudo.run() |
| 188 | + //pass the password to the process on stdin |
| 189 | + sudo.sendMessage("$password\n") |
| 190 | + sudo.waitForProcess() |
| 191 | + if (sudo.getExitCode() != 0) |
| 192 | + throw new TablesawException("Unable to run alien application") |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +//------------------------------------------------------------------------------ |
| 199 | +//Build notification |
| 200 | +def printMessage(String title, String message) { |
| 201 | + osName = saw.getProperty("os.name") |
| 202 | + |
| 203 | + Definition notifyDef |
| 204 | + if (osName.startsWith("Linux")) |
| 205 | + { |
| 206 | + notifyDef = saw.getDefinition("linux-notify") |
| 207 | + } |
| 208 | + else if (osName.startsWith("Mac")) |
| 209 | + { |
| 210 | + notifyDef = saw.getDefinition("mac-notify") |
| 211 | + } |
| 212 | + |
| 213 | + if (notifyDef != null) |
| 214 | + { |
| 215 | + notifyDef.set("title", title) |
| 216 | + notifyDef.set("message", message) |
| 217 | + saw.exec(notifyDef.getCommand()) |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +def buildFailure(Exception e) |
| 222 | +{ |
| 223 | + printMessage("Build Failure", e.getMessage()) |
| 224 | +} |
| 225 | + |
| 226 | +def buildSuccess(String target) |
| 227 | +{ |
| 228 | + printMessage("Build Success", target) |
| 229 | +} |
0 commit comments