我很少被XML困住。 XML中sqlfile
中的路径必须从使用dir
和dir1
加载SQL文件的文件夹中获取,我有问题构建XML:
<databaseChangeLog
<changeSet author="John" id="JRIA" failOnError="true" runAlways="false">
<sqlFile path="path.sql" relativeToChangelogFile="true" encoding="utf8" />
<rollback>
<sqlFile path="rollback/path.sql" relativeToChangelogFile="true" encoding="utf8" />
</rollback>
</changeSet>
我的例子:
import groovy.io.FileType
import groovy.xml.*
def dir = new File("C:\\Users\\John\\git\\changelogs\\version1\\db")
def dir1 = new File("C:\\Users\\John\\git\\changelogs\\version1\\rollback")
def sw = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(sw)
xml.changeSet(author:"John", ID:"JIRA", failOnError: "True", runAlways: "false"){
sqlFile(path:"From DIR", relativeToChangelogFile="true")
rollback(){
sqlFile(path:"From DIR1", relativeToChangelogFile="true")}
}
如何以良好的方式使用dir
和dir1
生成该XML?以及如何获取特定的扩展文件(sql)
答案 0 :(得分:0)
这很简单,只需使用.each
xml.dataBaseChangeLog(){
dir.eachFileRecurse(FileType.FILES) { file ->
changeSet(author:"John", ID:"JIRA", failOnError: "True", runAlways: "false")
sqlFile(path:file, relativeToChangelogFile="true")
rollback(){
sqlFile(path:file, relativeToChangelogFile="true")
}}}