0
給一個LinkedHashMap,我試圖在groovy中構建一個完整的xml樹。Groovy中的樹排序
1)圖:
def trees = [:]
trees.put(1,[id:'1',path:'ROOT/folder1',name:'folder1',isFolder:'true'])
trees.put(2,[id:'2',path:'ROOT/folder1/folder1.1',name:'folder1.1',isFolder:'true'])
trees.put(3,[id:'3',path:'ROOT/folder1/folder1.1/folder1.1.1',name:'folder1.1.1',isFolder:'true'])
trees.put(4,[id:'4',path:'ROOT/folder2',name:'folder2',isFolder:'true'])
trees.put(5,[id:'5',path:'ROOT/folder3',name:'folder3',isFolder:'true'])
trees.put(6,[id:'6',path:'ROOT/folder3/folder3.1',name:'folder3.1',isFolder:'true'])
2)分類樹閉合:
//def rslt = { [:].withDefault{ owner.call() } }
def a = []
def rslt = { [:].withDefault{ owner.call() } }().with { t ->
trees.each { k, v ->
v.path.tokenize('/').inject(t) { tr, i -> tr[ i ] }
}
return t
}
3)如何建立一個XML文檔,使用XML slurper例如
一個模型會是這樣的:
<ROOT>
<folder1 name="folder1" id="1" parent="ROOT" depth="1" path="ROOT/folder1">
<folder1.1 name="folder1.1" id="2" parent="folder1" depth="2" path="ROOT/folder1/folder1.1">
<folder1.1.1 name="folder1.1.1" id="3" parent="folder1.1" depth="3" path="ROOT/folder1.1/folder1.1.1"/>
</folder1.1>
</folder1>
...
</ROOT>
尋找像使用sthg像封閉groovy.xml.MarkupBuilder(sw).with {
任何想法或建議?
BR。
任何人詹金斯管道腳本嘗試此應該知道[JENKINS-32766(HTTPS的://issues.jenkins-ci。組織/瀏覽/ JENKINS-32766) – Roman 2017-12-01 11:10:26