A basic Checkstyle AuditListener implementation to output checkstyle results in EDN.
EDN (Extensible Data Notation) is a superset of the format of the Clojure language.
This code was written to provide EDN formatted Checkstyle output to feed into another project of mine: aeolian which consumes Checkstyle data.
There are two main classes you can use:
- EdnListener - produces a single EDN map for each checkstyle error observed.
- BatchingEdnListener - produces a single EDN map for each set of errors for the same source file and line number.
EdnListener
was my first take on this functionality before I realised I needed to
collapse all errors for the same file/line key into a single output EDN line - hence
the creation of BatchingEdnListener
.
EdnListener
also has the ability to limit the set of fields produced by
specifying a list of fields to retain in the output EDN.
The following instructions assume you have Apache Ant installed and configured.
ant dist
The dist
target will compile the source and package it into a JAR file (edn-listener.jar
)
in the dist
directory.
When using custom audit listeners in Checkstyle, they need to be referenced as a module
in your Checkstyle configuration (usually stored in checkstyle.xml
) as a child
module of Checker
(see below).
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="BatchingEdnListener">
<property name="file" value="output.edn"/>
</module>
...
<module name="TreeWalker">
...
</module>
</module>
See the Aeolian Checkstyle config file for an example of how the BatchingEdnListener
is used.
The EdnListener
output looks like:
{:source-file "file" :line 23 :column 45 :severity "error" :message "Hello" :source "org.corvine.checkstyle.EdnListener"}
where the keys are derived as follows:
source-file
- the source file containing the Errorline
- the line number containing the Errorcolumn
- the column containing the Errorseverity
- the string "error" as warnings are not capturedmessage
- the message describing the errorsource
- the class name of the Checkstyle checker producing the error
From the above configuration, the BatchingEdnListener
output would be stored in output.edn
, and would
contain a number of lines looking like:
{ :key "file1#24" :source-file "file1" :line 24 :org.corvine.checkstyle.EdnListener "Hello" }
where the keys are derived as follows:
key
- the source file and line number concatenatedsource-file
- the source file containing the Errorline
- the line number containing the Error[source-name]
- 1-n uniquely named entries with the class name of the Checkstyle checker producing the error and the error message itself as the value associated with the key