Skip to content

Instantly share code, notes, and snippets.

@monzou
Created December 12, 2012 02:07
Show Gist options
  • Save monzou/4264257 to your computer and use it in GitHub Desktop.
Save monzou/4264257 to your computer and use it in GitHub Desktop.
tiny script
package xls;
import org.apache.poi.hssf.usermodel.HSSFWorkbook
class UpdateVersion {
static void main(args) {
def versionList = []
new HSSFWorkbook(new File(UpdateVersion.class.getResource("version.xls").toURI()).newInputStream()).sheets.each { sheet ->
def value = { rowIndex, colIndex -> sheet.getRow(rowIndex).getCell(colIndex) }
def newVersion = { rowIndex ->
def params = [:]
[ 3: 'major', 4: 'minor', 5: 'tiny' ].each { k, v -> params.put(v, value(rowIndex, k).toString()) }
new Version(params)
}
def rowIndex = 1
while (sheet.getRow(++rowIndex)) {
if (value(rowIndex, 2).toString() == "○") {
versionList.add([
'project' : value(rowIndex, 1),
'version' : newVersion(rowIndex)
])
}
}
}
for (v in versionList) {
new File("../${v.project}/version.properties").withWriter("MS932") { w ->
w.write("version.major = ${v.version.major}\n")
w.write("version.minor = ${v.version.minor}\n")
w.write("version.tiny = ${v.version.tiny}")
}
println("[ ${v.project} ] updated version to ${v.version.getName()}")
}
}
static class Version {
def major
def minor
def tiny
def getName() {
"${major}.${minor}.${tiny}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment