Using SQE for improved code quality

Definition from the Software Quality Environment (SQE) home page:

"SQE attempts to provide first-class NetBeans IDE integration for different software quality tools".

http://kenai.com/projects/sqe/pages/Home

The different tools contained in the package are:

  • FindBugs
  • PMD
  • CheckStyle
  • Dependency Finder

This enables the developers to have code defect analysis, metrics, and dependency analysis.

Please be aware that this is an unstable module. Use at your own risk.

Getting ready

In order to use SQE we will first need to install the plugins.

  1. Navigate to Tools and then Plugins.
  2. On the Plugins dialog click on the Settings tab.
  3. There, on the right side you will find an Add button, click on it.
  4. Fill the Update Center Customizer Name with SQE and URL with http://deadlock.netbeans.org/hudson/job/sqe/lastStableBuild/artifact/build/full-sqe-updatecenter/updates.xml then click OK.
Getting ready

Note that SQE is added to the list of Configuration of Update Centers.

  1. Now click on the Available Plugins tab and click on the Reload Catalog button.
  2. Organize the Packages by Category and look for Quality on the category column.
  3. Right-click in one of the four packages under Category name, (PMD, FindBugs, Checkstyle, Depedency Finder) and select Check Category Quality.
  4. And click the Install button.
Getting ready
  1. Follow the installation steps by accepting the License Agreement and on Validation Warning, click continue.
  2. On the dialog where NetBeans informs the user that the plugins were successfully installed click Finish.
  3. Then close the Plugin Manager.

The Toolbar is updated with both icons and another entry named Quality, as seen in the following screenshot:

Getting ready

SQE can be used with your current project or any valid NetBeans project, but for this recipe we will use one of the projects that come bundled with NetBeans itself.

  1. Create a New Project, by either clicking File and then New Project or pressing Ctrl+Shift+N.
  2. On New Project window on categories side choose Samples and Java Web and on Projects side select Servlet Examples (J2EE 1.4) and click Next >.
  3. Under Name and Location: Leave all the default values and click Finish.

How to do it...

Select the ServletExamples project and on the toolbar click on Quality then Code Defects and finally Run All Quality Tools.

How to do it...

Let SQE perform the code checks.

How it works...

SQE controls and views are displayed under the Java editor in the main view of NetBeans.

In our example PMD and FindBugs are shown with separate windows each.

Inside of each of those views, PMD or FindBugs, there are controls for how the visualization of the collected data is presented.

Controls such as:

  • Bug instances by class/package
  • Expand/Collapse All nodes in the tree
How it works...

The PMD view presents a list of rule sets, for example AppendCharacterWithChar that were triggered in the project when code checks were performed. Opening one of these rule sets will present the developer with a list of classes, organized by packages, and the location of the code that is not in accordance with the rules.

How it works...

Double-clicking one of these results will take the developer to the class itself, specifically to the line where the problem is.

The right-hand pane of the PMD view also gives advice on how to eliminate this inconsistency.

FindBugs is the same:

How it works...

Possible bugs that were introduced in the code are listed. On the left-hand side the location and code snippet, and on the right-hand side the explanation of the problem.

The organization of FindBugs is a little different from PMD view but the principle of showing a guiding text on the right-hand side of the pane, and where to find the defect, is unaltered.

There's more...

The quality control center displays a nice graphical snapshot of current problems with the project. Multiple projects can also be selected on this view. To access it, please click on Window, then Quality, and QCC.

It is a nice way to compare previous iterations of the project, to see how many issues are left and how many were corrected.

Complete with a code defect dashboard where a bar graph shows the issues by method and a code defect timeline.

There's more...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.172.50