Quickie: how to make Clover ignore private constructors in Ant
PDFLast week we took a quick look on how to make clover ignore private constructors in Eclipse. This week, we’ll quickly cover Ant
First, let’s look at the regular expression again:
1 | (.* )?private +[a-zA-Z0-9_$]+ *( *).* |
Clover uses the concept of coverage contexts, which you can include/exclude during the report phase. A Coverage Context is a filter that matches on method or statement level. Assuming you’ve got Clover setup with your Ant scripts, here’s how you define a method context for your private constructors. Look up your clover-setup call:
1 2 3 | <clover-setup initString="${build.dir}/clovercoverage.db" enabled="true"> <methodContext name="private_constructors" regexp="(.* )?private +[a-zA-Z0-9_$]+ *( *).*"/> </clover-setup> |
So we’ve added a Method Context to match our constructors and gave it the name private_constructors, which we’ll need in a second. Note that all contexts you add define exclusions only. Everything else is assumed to be included by Clover.
Next to make use of this context, here’s a tricky bit: it’s not entirely clear in the Clover manual, but to make this Coverage Context active, you need to include it in the format element in your clover-report task, as follows:
1 2 3 4 5 | <clover-report> <current outfile="${reports.dir}/clover"> <format type="html" filter="private_constructors"/> </current> </clover-report> |
For this to work you need to re-instrument your code. Have fun!
Tags: ant • atlassian • clover • java