A software developer's public collection of tips and tricks, real-world solutions, and industry commentary related to Java programming.
My last post (NetBeans 7 and Software Quality Environment) focused on using the NetBeans 7 Plugins Manager to acquire Software Quality Environment (SQE) and install its four plugins for four software quality tools (Dependency Finder, PMD, FindBugsTM, and Checkstyle). That post also briefly covered how to use each of these in NetBeans. In this post, the focus shifts to configuring and customizing the quality tools plugins in NetBeans.
Code analysis tools such as PMD, Checkstyle, and FindBugsTM tend to provide methods for configuring and tailoring the types of code issues identified by the tool. This is a welcome feature because not all findings are created equal and some matter more than others. Indeed, some findings are very subjective and a particular individual, team, or project may decide to NOT apply certain recommendations provided by these tools. In these tools' traditional uses, this configuration enables fewer "findings" to be reported and increases the probability that any reported finding is one worth the time to investigate and fix.
When running these code analysis tools in NetBeans, this desire to only see warnings and findings of significance is just as beneficial as it is when running the tools standalone as part of build scripts or when manually run against the source code. I like to have my source code free of any of the yellow or red findings NetBeans produces for hints, warnings, and errors. Similarly, I like my code to be free of the findings identified by the code analysis tools. In most cases, this means fixing the finding, but sometimes I don't agree with the finding. The ability to configure what the tools report is useful for removing reporting of findings that I don't consider to be findings at all.
It is easy to configure the code analysis tools on a per-project basic. To do so, right click on the project of interest in the "Projects" window (accessible using CTRL+1). Right-clicking on the project of interest in the "Projects" window leads to a drop-down menu like that shown in the next screen snapshot. One clicks on the "Properties" at the bottom to configure various project properties, including code analysis tools properties.
The result of clicking on the "Properties" selection after right-clicking on the project of interest is shown in the next screen snapshot. Note that in this case, the "Project Properties" window has "Sources" highlighted under "Categories."
To configure the code analysis tools plugins provided by SQE, the apropos tool name must be selected in the "Project Properties" window's "Categories" area. Selecting the higher-level "Quality" is not very exciting. Instead, one of the specific tools' names should be selected. The next screen snapshot indicates what the Project Properties window looks like when PMD is selected.
As this screen snapshot indicates, disabling any type of finding ("rule") in the PMD plugin is as simple as unchecking the box under "Enabled" for that particular rule. For someone with great familiarity with the PMD tool, it is likely that the names of the rules will make it obvious what rules are represented. For those who lack that familiarity, clicking on the particular rule of interest leads to more details on that rule being displayed. The next screen snapshot demonstrates an example of this for the "SystemPrintln" rule.
As the screen snapshot demonstrates, the two previously empty fields are filled with more details on the PMD rule selected. The middle field provides a brief textual description of the rule and the bottom field shows a code sample of the particular code situation the rule is intended to identify. As with the NetBeans hints, one could learn a lot about what are generally good ideas and generally bad ideas in Java by simply clicking on each rule one-by-one and reading the descriptions and seeing the code examples of those issues.
Configuring the FindBugsTM plugin for the project is similar. The next screen snapshot demonstrates how this appears in NetBeans 7 when "FindBugs" is selected in the "Project Properties" window. Notice that the default tab opened for this is "Configure Detectors" and that, like the PMD "rules," no particular "Bug Detector" is selected initially. Clicking on any rule leads to a description of the detector being placed in the previously empty field. This is shown in the next screen snapshot. Hovering over the description leads to the extra information in the yellow highlighted area shown in the snapshot.
Descriptions and associated Categories for various findings that FindBugsTM identifies are listed in FindBugs Bug Descriptions. Also note that the "Speed" of the various detectors is listed.
Clicking on "Checkstyle" under "Quality" in the NetBeans Project Properties window leads to the screen shown in the next snapshot.
Whether using Checkstyle from the command line or from Ant, a configuration file and a properties file can be provided to customize the applied Checkstyle modules. Given this, it's not surprising that the NetBeans SQE-provided Checkstyle plugin accepts specification of a "Config File" and a "Properties File."
Although some coding practices are almost universally accepted as "good" or "bad," there are some findings identified by code analysis tools that may be unimportant or even disagreeable to a software development organization. Therefore, it is advantageous that these tools allow the findings that are searched for and reported to be customized. Fortunately, the NetBeans SQE plugin passes along this configuration ability to the NetBeans user. The most significant configurations that can be performed with these tools in a command line or Ant environment can be performed similarly in NetBeans 7 thanks to SQE.