Skip to content

Instantly share code, notes, and snippets.

@lcorneliussen
Created April 23, 2010 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcorneliussen/376421 to your computer and use it in GitHub Desktop.
Save lcorneliussen/376421 to your computer and use it in GitHub Desktop.
def mixinAntExec() {
String.metaClass.antExec = {failOnError=true -> antExec([delegate], failOnError)}
ArrayList.metaClass.antExec << {failOnError=true -> antExec(delegate, failOnError)}
}
def antExec(command, failOnError=true) {
def commandLiteral = command.collect{it.contains(' ') ? '"' + it + '"' : it}.join(' ')
println "ant exec with: ${commandLiteral}"
def ant = new AntBuilder()
ant.exec(outputproperty:"text",
errorproperty: "error",
resultproperty: "exitValue",
failonerror: false,
executable: command[0]) {
if (command.size()>1)
arg(line:command[1..-1].collect{it.contains(' ') ? '"' + it + '"' : it}.join(' '))
}
def result = new Expando(
text: ant.project.properties.text,
error: ant.project.properties.error,
exitValue: ant.project.properties.exitValue as Integer,
toString: {text}
)
if (failOnError && result.exitValue != 0){
throw new Exception("""command failed with ${result.exitValue}
executed: ${commandLiteral}
error: ${result.error}
text: ${result.text}""")
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment