Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
}
@lcorneliussen

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.