0

在复制类型任务期间更新 zip 存档中特定 xml 文件的最佳方法是什么?

到目前为止我所拥有的:

def unzip() {

    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 )
                }
            }
        }
    }
}

这段代码的问题在于它只更新了 'tmp' 文件夹中的 xml 文件,而不是最终的 'dir' 文件夹中的 xml 文件。

提前谢谢,PM

4

0 回答 0