Jeremy Rayner on java and other stuff.

All | AudioDrama | Chatter | Fun | Groovy | Java | Life

Turn your build.xml into a pretty picture using Groovy
Posted on 02 Dec 2004
Inspired by Sam Newman (magpiebrain), I decided to see if it was possible to do a quick XSLT style transform using groovy on an ant build.xml file, so that it could be loaded up in FreeMind.

The example diagram below is the result of running groovy antmap.g > build.mm over the build.xml for my groovy shell called grash

mindmap of grash build file

A code snippet is below, which I've added to the groovy examples bundle (which is full of cool stuff b.t.w.)

#!/bin/env groovy
# 
# convert an ant build file into a format 
#     suitable for http://sf.net/projects/freemind
#
# by Jeremy Rayner - 2 Dec 2004
# inspired by Sam Newman 
#    ( http://www.magpiebrain.com/archives/2004/12/02/antgui )
#
# usage:   groovy antmap.g > build.mm

import groovy.util.XmlParser
import java.io.File

buildFileName = "build.xml"  // default

// handle command line params
if (args.length > 0) {
buildFileName = args[0]
}

// header
println "<map version='0.7.1'>"
project = new XmlParser().parse(buildFileName)
name = project['@name']
println "<node TEXT='${name}'>"
level = 0

printChildren(project,level)



def void printChildren(node,level) {
level++
node.each {
name = huntForName(it)
if (name != null) {
if (level > 1) {
println "<node TEXT='${name}' POSITION='right'>"
} else if (it.name() == 'property' || it.name() == 'path' ) {
if (it.children().size() > 0) {
println "<node TEXT='${name}' POSITION='left' FOLDED='true'>"
} else {
println "<node TEXT='${name}' POSITION='left'>"
}
} else if (it.children().size() > 0) {
println "<node TEXT='${name}' POSITION='right' FOLDED='true'>"
} else {
println "<node TEXT='${name}' POSITION='right'>"
}
}
if (it.children().size() > 0) printChildren(it,level)
if (name!=null)println "</node>"
}
}

// footer
println "</node></map>"


def String huntForName(node) {
preferNodeNames = ["junitreport"]
if (node == null) return null
if (preferNodeNames.contains(node.name())) return node.name()
if (node['@name'] != null) return node['@name']
if (node['@todir'] != null) return node['@todir']
if (node['@dir'] != null) return node['@dir']
if (node['@refid'] != null) return node['@refid']
return node.name()
}

02 Dec 2004 |

 

 
December 2004
SunMonTueWedThuFriSat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Prev | Today | Next

rss:subscribe (All)



What I'm reading
my feed aggregator ->box

My websites
London Java Meetups
Programming Projects
Elite in Java
megg
Blogmento
Jez's Photos
Fantasy Stock Market
Cool Saxophonist
Doctor Who Audios
Pisces Audios

Other Blogs
Mike Cannon-Brookes
James Strachan
Joe Walnes
Sam Dalton
Simon Brown
Cameron Purdy
Mike Roberts
Erik C. Thauvin
John Martin
Manfred Riem

B5 d++ t++ k s+ u- f
i+ o+ x-- e+ l- c--

powered by blogmento