I am finding myself grabbing Groovy rather than Perl for some of those small scripting tasks that you run into.
One I ran into recently revolved around my maven repository.
We setup our own Maven repo (we don’t want to keep hitting the poor ibiblio site!), and whenever we add dependencies, we grab the files from ibiblio and put them in our own repo.
However, it is easy to forget, so I whipped up a script that will check the dependencies in our project.xml and make sure those files exist in the repo, else it will shout at me to do the move.
It would also be cool to have it automatically do the copy itself!
I really like how you can whip through XML
Groovy Maven Script
#!/bin/env groovy # ----------------------------------------------------------------------------- # mavenTestRepository.g: Take a given project.xml and a Maven repo, shout out # which files are there, and which are not # ----------------------------------------------------------------------------- import groovy.util.XmlParser import java.io.File # -- Enforce the project.xml and dir if (args.length < 2) { println """ Usage: mavenTestRepository.g project.xml mavenRepoDir e.g. mavenTestRepository.g /foo/project.xml /www/adigio/maven """ System.exit(1) } # -- Variables projectxml = args[0] mavenRepoDir = args[1] badFiles = [] # -- Open up the file and do the work project = new XmlParser().parse(projectxml) project.dependencies.dependency.each { groupId = it.groupId[0].text() artifactId = it.artifactId[0].text() version = it.version[0].text() println "-----------------------------------------------------------------------" println " Group ID : ${groupId}" println " Artifact ID: ${artifactId}" println " Version : ${version}" boolean fileExists = true try { new File("${mavenRepoDir}/${groupId}/jars/${artifactId}-${version}.jar").eachLine { } } catch (Exception e) { fileExists = false } if (fileExists) { println "Good: File exists in repo" } else { badFiles += ["${groupId}: ${artifactId}-${version}"] println "Bad: File DOES NOT exist in repo" } } # -- Print out the bad ones if (badFiles.size() > 0) { println "\n-----------------------------------------------------------------------" println "Dependencies not in the repository:\n" badFiles.each { println it } }