Groovy Environment Scripting
July 17th, 2008 | by jeff |Problem: You want to use groovy all the time, but ignorant (but paying) forces keep you writing verbose tedious Java code instead.
Solution: Use groovy instead of shell scripts! In large Java development projects, developing in a local environment comes with a maddening list of pulling levers, pushing buttons, and spinning wheels. Many of these can be automated with scripts, and those that can can be Groovy scripts.
I wrote this script to clean up after liferay portal kruft:
#!/usr/bin/env groovy
class Build{
def ant = new AntBuilder()
def localhostDir = "C:/dev/liferay/tomcat/work/Catalina/localhost"
def portraitDir = localhostDir + "/portrait"
def liferayDir = "C:/Documents and Settings/ujxh744/liferay"
def luceneDir = liferayDir + "/lucene"
def classpath = ant.path {
dirset(dir: liferayDir){
include(name: "*")
}
dirset(dir: localhostDir) {
include(name: "*")
}
}
void cleanUpLiferayShit() {
ant.delete(dir: portraitDir)
ant.delete(dir: luceneDir)
}
void echoDirectories(dirPath) {
def pathList = dirPath.list()
println "There are " + dirPath.size() + " remaining directories"
dirPath.list().each{ arg ->
println arg
}
}
}
def b = new Build()
b.cleanUpLiferayShit()
b.echoDirectories( b.getClasspath())
Reference Links:
Javaworld
Groovy Ant site
3 Responses to “Groovy Environment Scripting”
By Bark on Jul 19, 2008 | Reply
give me one good reason that should be a class or a groovy script.
How did this make you feel better by writing it in groovy.
Whats the point actually?
I could have written this script in 4 lines of script code after the declarations.
By Richard on Jul 20, 2008 | Reply
One good reason would be that its cross platform. I have experience where even a bash script would not work the same on two different linux distros, and clearly it wouldn’t work natively on windows, groovy is an ideal solution for this sort of thing.
By jeff on Jul 22, 2008 | Reply
http://www.merriam-webster.com/dictionary/options