What would be the best way to update a specific xml file in a zip archive during a Copy type task?
What I have so far:
copy {
def zipFile = configurations.tomcat.singleFile
from zipTree(zipFile)
into ‘dir’
eachFile { fileCopyDetails ->
file = fileCopyDetails.file
if ( file.getAbsolutePath().endsWith(‘conf’ + File.separator + ‘context.xml’) ) {
def contextXml = new XmlSlurper().parse(file)
String contextStr = groovy.xml.XmlUtil.serialize(contextXml)
println ‘xml before:\n’ + contextStr
contextXml.appendNode {
a(‘value’)
}
contextStr = groovy.xml.XmlUtil.serialize(contextXml)
println ‘xml after:\n’ + contextStr
file.withWriter { outWriter ->
XmlUtil.serialize( new StreamingMarkupBuilder().bind{ mkp.yield contextXml }, outWriter )
}
}
}
} }
The problem with this code is that it only updates the xml file in the ‘tmp’ folder and not the xml file in the final ‘dir’ folder.
Thanks in advance, PM