„svn list“-command improved by Groovy

Hallgrimskirkja church in Reykjavic (Iceland), own photo (by Christoph Burmeister)

Hallgrimskirkja church in Reykjavic (Iceland), own photo (by Christoph Burmeister)

When analyzing the structure of an unknown svn-repository, you might get into trouble when using the board-tools of svn-commandline-client. So lets have a look for improvements:
For example the „svn list –verbose“ command brings you sth like the following

 33 user2              Mai 07 15:12 project1/
 36 user5              Apr 04  2012 project4/
123 user9              Apr 13  2006 project9/
 54 user98             Jun 28  2007 project2/
556 admin              Mai 16 10:13 spielwiese/
 23 user42             Jan 24  2006 project3/

That’s not nice, so I better use my own script, that calls the „svn list“ with the xml-switch and parses the output to produce a nicer view:

def targetSvnUrl = "http://myserver:9083/svn/repos/spielwiese/"

def ant = new AntBuilder()   // create an antbuilder
	errorproperty: "cmdErr",
	failonerror: "true",
	executable: 'svn'
) {
	arg(line:"""list --xml ${targetSvnUrl}""")

//println "return code:  ${ant.project.properties.cmdExit}"
//println "stderr:         ${ant.project.properties.cmdErr}"
//println "stdout:        ${ ant.project.properties.cmdOut}"

xmlInput = "${ant.project.properties.cmdOut}"

Map entries = new HashMap()
def maxLength = 0

// parse the output of "svn list --xml" for entryName and Date
def lists = new XmlParser().parseText(xmlInput)
def entryCount = lists.list.entry.size()
for (int i = 0; i< entryCount; i++){
	def entry = lists.list.entry[i]
	entryName = entry.name.text()
	entryDate = entry.commit.date.text()
	entries.put(entryName, entryDate)
	if (entryName.length() > maxLength){
// reverse sort the map (youngest entries first)
entries = entries.sort {a, b -> b.value <=> a.value}

// print out the map-content in a nice way
for ( e in entries ) {
	String key = String.format("%-"+maxLength+"s", e.key);
    println key + " ${e.value}"

and that’s the output that makes it quite simple to look for the projects that weren’t changed for a long time:

project1        2013-05-16T09:43:49.247591Z
project5        2013-04-14T09:49:24.045601Z
project8        2013-04-09T03:01:04.806853Z
project2344_sam 2012-12-24T05:38:29.280216Z
project2        2012-09-01T05:28:35.099336Z
project4        2008-02-26T20:32:19.422077Z
project3        2004-11-18T20:50:15.46405
project6        2004-01-02T20:15:26.002560Z