Following on from my last post about using hbm2java to generate a @Entity bean DAO layer for our application, Findbugs, the great automatic bug finding tool, will find a lot of issues with Hibernate’s auto-generated code (primarily around exposing internal Date objects to callers). So long as this is something we are aware of and don’t have a problem with, we don’t want find bugs to tell us about this stuff. It’s possible to filter out an entire package or class tree with the use of Findbugs’ filters.
For example, say we wanted to filter out the classes in the package com.mycom.dbautodao, we could create a findbugs_filter.xml which contains:
<FindBugsFilter>
<Match>
<Package name="~com\.mycom\.dbautodao\..*"/>
</Match>
</FindBugsFilter>
This uses a regular expression to filter out checks against all contents and sub-packages of the com.mycom.dbautodao package.
Similarly it’s possible to do the same with a <class name=”myregex”/> element rather than a <package/> element for finer control.
To enable the filtering we just need modify the
<findbugs home="${findbugs.home}" output="xml" outputFile="${basedir}/dist/findbugs/findbugs.xml" excludefilter="findbugs_filter.xml">
While on the topic of regular expressions, I often find myself using this online regex checker tool which uses Java’s regex syntax – http://www.fileformat.info/tool/regex.htm. It’s a really quick and handy way of writing and testing a regular expression, since you can enter test string which provide both positive and negative test cases to develop against.
Related posts:
- Automatically Updating Your Source File Headers With Ant’s ReplaceRegExp Task
- Using Bottom-Up Iterative Object/Database Layer With hbm2java and warp-persist
- Simple Guide To Sub-reports in JasperReports / iReport
- Automatic Javascript and CSS Compression For Java Webapps
- HTML Sanitizer added to visural-common…