Enterprise Integration Zone is brought to you in partnership with:

Mitch Pronschinske is the Lead Research Analyst at DZone. Researching and compiling content for DZone's research guides is his primary job. He likes to make his own ringtones, watches cartoons/anime, enjoys card and board games, and plays the accordion. Mitch is a DZone Zone Leader and has posted 2577 posts at DZone. You can read more from them at their website. View Full User Profile

The Best Groovy Modules You Might Not Know About

01.26.2010
| 24060 views |
  • submit to reddit
It's no secret that Groovy and its many related goodies are quite popular, especially at DZone where the announcement of Groovy 1.7 got 137 up votes, making it the highest rated DZone link ever!  Plenty of people have heard about the Groovy-based frameworks like Griffon and Grails, and the Gradle build system, which uses Groovy build scripts.  If you've looked at the Groovy Modules page lately, you'll see that there are a lot of other Groovy-based modules out there.  Listed below are five Groovy modules that are really great, but they haven't gotten the attention that they deserve.

GroovyWS

There is some killer Groovy support for Web Services in the Groovy WS module.  GroovyWS incorporates Apache CXF to help you quickly consume, publish, and test WS-I compliant web services.  GroovyWS can even use secured web-services.  To invoke a web service using a complex type, simply write the method's signature and its parameters, and GroovyWS will construct the proper SOAP message and invoke the remote web service during runtime.  The complex types are automatically generated from the WSDL, compiled, and made available through your classloader.  The client API provides a method to easily instantiate a complex object from its class name.  GroovyWS makes life easier by logging the names of classes that are generated on the fly.  The client-side of GroovyWS integrates seamlessly with Grails and Griffon applications.

Scriptom

This module combines the "syntactical sugar" of Groovy with the Jacob (Java COM Bridge) library to use ActiveX or COM Windows components from Groovy.  It takes advantage of Groovy's dynamic (late-bound) principles to map COM objects into Groovy objects at runtime, therefore, you don't need to know a lot about COM in order to use Scriptom.  You also don't need to deal with type-libraries and there are no wrappers to maintain.  Just code it and run it.  Scriptom got its name because it is script-like in the sense that it resembles writing code using VBScript (but with the more advanced Groovy language).  Among other things, Scriptom can be used to automate Word or Excel documents, control Internet Explorer, make your PC talk using the Microsoft Speech API, monitor processes with WMI (Windows Management Instrumentation), or browse the Windows Registry using WShell.  Talking to custom VB6 or Microsoft.NET libraries is also much easier with Scriptom.

Groovy Monkey

If you are working on automating tasks in Eclipse or doing plugin development in general, this is the tool for you!  Groovy Monkey is a branch of the Eclipse Monkey software based on the Eclipse Jobs API.  It lets users quickly try parts of the Eclipse API without the overhead of a plugin or a separate runtime instance.  It is a dynamic scripting tool for writing quick and reusable functionality (i.e. task automation) to make life easier with Eclipse.  Groovy Monkey can even be used to translate the quick and dirty work into a plugin.  Because Groovy Monkey is based on the Eclipse API, you can seamlessly monitor the progress in the platform and write scripts that users can cancel midway through.  Groovy Monkey is also based on the Apache Bean Scripting Framework (BSF) and OSGi.  BSF lets you write scripts in several languages (Beanshell, Ruby, Python), not just Groovy! (But why wouldn't you want to write in Groovy? ;-) )  The OSGI framework lets Groovy Monkey add the classloader of any bundle on the workbench to a script's classloader.  It also allows Groovy Monkey to do a white box introspection of running bundles/plugins.

Groosh

Groosh is a Unix-like shell that is written in Groovy and can be used with Grapes.  Grape is the infrastructure that enables the grab() calls in Groovy that leverage Apache Ivy, allowing a repository driven module system for Groovy.  With Grapes (@Grab), Groosh can be a powerful alternative to regular shell scripts.  Here is a simple example of Groosh in action:
//Read a text file and write it to stdout
@Grapes([
@Grab(group='org.codehaus.groovy.modules',module='groosh',version='[0.3.6,)'),
@GrabConfig(systemClassLoader=true)
])

import groosh.Groosh
Groosh.withGroosh(this)

cat('test_scripts/blah.txt') >> stdout

GroovySWT

For GUI building, Groovy has a wrapper for the Eclipse Standard Widget Toolkit (SWT).  GroovySWT let's you easily write Eclipse SWT applications right in Groovy's builder mechanism.  Using Groovy instead of Java for SWT applications can significantly reduce the amount of code needed.  Here is some SWT code using native Groovy:
import org.eclipse.swt.SWT
import org.eclipse.swt.widgets.*
import org.eclipse.swt.layout.RowLayout as Layout

def display = new Display()
def shell = new Shell(display)

shell.layout = new Layout(SWT.VERTICAL)

shell.text = 'Groovy / SWT Test'

def label = new Label(shell, SWT.NONE)
label.text = 'Simple demo of Groovy and SWT'
shell.defaultButton = new Button(shell, SWT.PUSH)
shell.defaultButton.text = ' Push Me '

shell.pack()
shell.open()

while (!shell.disposed) {
if (!shell.display.readAndDispatch()) shell.display.sleep()
}

When you run the script, this is the result:



Griffon will allow the use of GroovySWT in the very near future.
_________

Many thanks to Andres Almiray for helping me with this list.

Have you tried any of these tools yet?  Think there's another Groovy module that's more deserving of attention?  Tell us what you think, Groovy-lover.