Dashboard > Groovy > ... > Modules > Gram
Gram Log In | Sign Up   View a printable version of the current page.

Added by James Strachan , last edited by Paul King on Sep 25, 2006  (view change)
Labels: 
(None)

Gram is a simple xdoclet-like tool for processing doclet tags or Java 5 annotations in source code or bytecode and auto-generating files, data or resources.

Gram = Groovy + JAM. JAM does all the hard work of abstracting away the details between annotations and doclet tags and handling Java 1.4 and 5 compliance. Groovy takes care of the scripting, code generation & templating. Gram is the little tidy bit of code in between.

The sources can be found here : Gram

Using Gram

You can use the Gram class as a main() and run it from your IDE if you wish. There is a GramTask as well for using it inside Ant.

Often since JAM depends on Sun's doclet stuff, you can have issues running the GramTask inside Maven and sometimes Ant. So I tend to run the Gram command line tool from inside an Ant build. e.g.

<java classname="org.codehaus.gram.Gram" fork="true">
      <classpath refid="tool.classpath"/>

      <!-- the directory where the source code lives -->
      <arg value="src/java"/>

      <!-- the groovy script to run to generate stuff -->
      <arg value="src/script/MyGram.groovy"/>
    </java>

Example script

Here's a simple example which just lists all the hibernate peristent classes in your source code

def persistentClasses = classes.findAll { it.getAnnotation("hibernate.class") != null }

println "Found ${persistentClasses.size()} instances out of ${classes.size()}"

persistentClasses.each { c ->
    println c.simpleName

    for (p in c.properties) {
        println "  property: ${p.simpleName}"
    }
}

Jar Dependencies

Gram depends on:

  • The Groovy 'all' jar (groovy-all-*.jar)
  • JAM from the Annogen project
  • and potentially: xml-apis.1.02b.jar and Sun's tools.jar

Articles

You might find some more documentation in the form of blog posts by Andres Almiray:

Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators