Groovy


Well, ok. I’m just a bit of a stick-in-the-mud, and I dislike not being an expert, so new things always intimidate me a little. Groovy is pretty ok.

But it doesn’t help when example code in the documentation is wrong.

The HTML example HERE does not execute, as explained HERE. FFFFFFFFUUUUUUUU!

But that aside, behold my first Groovy: “What jar files contain the GroovyTestCase class?”

[
   new File('/Users/ibis/Software/grails-2.0.3'),
   new File('/Users/ibis/Software/groovy'),
   new File('/Users/ibis/SpringsourceWS')
].each { File root ->
   root.eachFileRecurse(FileType.FILES) { File f ->
      if(f.name.endsWith('.jar')) {
         JarFile j = null;
         try {
            j = new JarFile(f);
            j.entries().each {ZipEntry it ->
               if(it.name.contains('GroovyTestCase'))
                 println(f.toString() + '\t' + it.name)
            }
         }
         finally {
            j?.close();
         }
      }
   }
}

And I have to admit it’s nicer than explicitly working with iterators or implementing inner classes to do the job. I still explicitly type things and put in the semicolons because, dammit, I’m a java programmer and it makes me feel safer.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: