Tuesday, April 23, 2013

Merging JaCoCo coverage reports across several modules in a Maven multi-module project.

I tried to follow the instructions in this article: http://java.dzone.com/articles/jacoco-maven-multi-module. However, what I don’t like, is your “coverage” module has to hardcode references to all the modules in your multi-module project. That means, that when you need to add a new module, you must now update two places – both the parent pom.xml, and the coverage pom.xml. People are likely to forget to do the later, especially if a new developer is working on your project.

My solution is here. Basically, rather than hard-coding references to the  other modules, we load the parent pom.xml and extract the list from the <modules> tag. Two provisos: (1) this will not work for multi-level multi-module projects; (2) this assumes you stick to Maven standard directory structures. With some code changes, you could overcome those provisos.

Yet another ANTDOC tool

I wanted a tool to generating documentation from ANT projects. I had a look at AntDoc (http://antdoc.free.fr) and was not entirely happy with it, so I decided to write my own. It is far simpler, but it does exactly what I want. See attached antdoc.zip.

Mystery: Why does java.lang.Class.forName(“java.security.AccessController”) return null in jrunscript?

Solution: Mozilla Rhino supports a concept called “class shutters” which enable you to block scripts from accessing any class. The JS implementation that comes with the JDK installs one called com.sun.script.javascript.RhinoClassShutter, which blocks access to java.security.AccessController. If you need to call it from JavaScript, you will need to write a class in Java to call it on your behalf. Be aware, that this is done for security reasons, so you need to ensure you understand the security implications before you do so.