Grails/Griffon stats trick
Posted by: Andres Almiray on November 18, 2009
Well, you couldn't until recently. Starting with Grails 1.2M4 and Griffon 0.2 you'll be able to plug into the stats script and provide additional paths to be counted. Hows does this work you ask? let me introduce you to build events, as explained at the official Grails guide (Griffon events work exactly the same, cool huh?). The stats plugin will publish a StatsStart event, passing a list of maps as parameter. Each entry on that list defines a path to be searched, files found on that path will be counted if they match a certain criteria, mainly their filetype (actually a file suffix). To give you an example these are the default paths of the Grails stats script
You'll notice that filetype is a list (it used to be a single String). This is useful when joint-compilation is taken into account, a fact that the Griffon stats plugin relies on, as the path src/main main contains both Groovy and Java sources
Alright, so how do you plug into this feature? all you to do is add an event handler in scripts/_Events.groovy, like this one (used by Griffon's Scala plugin)
There is an additional feature, you may redefine how comments and empty lines are matched for a particular path. Provide a value for a locmatcher property. This is how the Griffon Clojure plugin does it:
Finally, the default LOC matcher should give better results when a multiline (/* */) comment is found on the source code.
Keep on Groovying!

About Andres Almiray
Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray
Why Attend the NFJS Tour?
- » Cutting-Edge Technologies
- » Agile Practices
- » Peer Exchange
Current Topics:
- Languages on the JVM: Scala, Groovy, Clojure
- Enterprise Java
- Core Java, Java 8
- Agility
- Testing: Geb, Spock, Easyb
- REST
- NoSQL: MongoDB, Cassandra
- Hadoop
- Spring 4
- Cloud
- Automation Tools: Gradle, Git, Jenkins, Sonar
- HTML5, CSS3, AngularJS, jQuery, Usability
- Mobile Apps - iPhone and Android
- More...