Skip to content

Instantly share code, notes, and snippets.

@alex-1q84
Created April 10, 2015 02:57
Show Gist options
  • Save alex-1q84/811116c67471b0191dd9 to your computer and use it in GitHub Desktop.
Save alex-1q84/811116c67471b0191dd9 to your computer and use it in GitHub Desktop.
解析maven pom.xml并生成指定profile的配置详情表格
def htmlHead(){
println("""<html lang="en">""")
println("<body>")
}
def htmlTail(){
println("</body>")
println("</html>")
}
def tableBegin(){
println("<table>")
}
def tableEnd(){
println("</table>")
}
def _cell(String tagName, String value, int colspan=1, int rowspan=1){
def colspanStr = ""
if (colspan > 1){
colspanStr = " colspan=\"${colspan}\""
}
def rowspanStr = ""
if (rowspan > 1){
rowspanStr = " rowspan=\"${rowspan}\""
}
print("<${tagName}${colspanStr}${rowspanStr}>")
print(value)
println("</${tagName}>")
}
def th(String value, int colspan=1, int rowspan=1){
_cell("th", value, colspan, rowspan)
}
def td(String value, int colspan=1, int rowspan=1){
_cell("td", value, colspan, rowspan)
}
def pom = new XmlSlurper().parse("pom.xml")
def profileList = pom.profiles.profile
// println(profileList.size())
htmlHead()
profileList.each{ profile ->
if (profile.id.text()?.contains("prod")){
tableBegin()
println("<tr>")
th(profile.id.text(), 2)
println("</tr>")
// println(profile.properties.children().size())
profile.properties.children().each { child ->
println("<tr>")
td(child.name())
td(child.text())
println("</tr>")
}
tableEnd()
}
}
htmlTail()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment