Sanity4J Eclipse plugin user guide

Intoduction

Sanity4J has been created in order to simplify running ad-hoc static code analysis over Java projects using a standardised set of rules types and priorities.

Various tools are used to conduct the analysis, each with their own set of requirements. Both bytecode and source code are analysed, to ensure the best chance of finding potential problems. Sanity4J presents a single interface to run all the tools and produce a combined report presenting all the findings in a easily accessible manner.

Sanity4J provides an Eclipse plugin for developers to run ad-hoc QA on individual classes during development.

Installing and Configuring the Eclipse plugin

To run the Eclipse plugin, you will need the following:

  • The Sanity4J Eclipse plugin ZIP file; sanity4j-1.8.2-eclipse.zip
  • JDK/JRE 1.8.x+
  • A directory containing the tools needed by Sanity4J. These can be extracted from the Tools download ZIP file; sanity4j-1.8.2-bin-with-tools.zip

Installing the Eclipse plugin

The following steps are for Eclipse 3.4 - Ganymede. Other versions of Eclipse will vary, but essentially it is the same process.

Start from the "Help" menu and choose "Software Updates..."

Eclipse screenshot showing Software Update menu.

From the "Available Software" tab, click the "Add Site..." button.

Eclipse screenshot showing Available Software tab.

Eclipse allows you to install the plugin directly from the ZIP file without having to extract it, or from a local directory where the ZIP file can be extracted to. In this case we will simply install the plugin directly from the ZIP Archive.

Click the "Archive..." button to choose a Location.

Eclipse screenshot showing Location of the Site to add.

Choose the location of the Archive; sanity4j-1.8.2-eclipse.zip

Eclipse screenshot showing Location of the Archive.

Click OK to confirm the Location.

Eclipse screenshot showing Location of the Site to add.

You should now see the Sanity4J Feature listed in the Available Software. Tick the tickbox for the Sanity4J Feature and click "Install..."

Eclipse screenshot showing Available Software with Sanity4J chosen.

You will be presented with a confirmation dialog for the Feature to install.

Eclipse screenshot showing the confirmation before installing the plugin.

You will need to accept the license agreement.

Eclipse screenshot showing the license agreement before installing the plugin.

After the installation is complete you will be prompted to restart Eclipse. Choose Yes and restart Eclipse.

Eclipse screenshot showing the restart prompt after installing the plugin.

Configuring the Eclipse plugin

The Sanity4J plugin can be configured from the Eclipse Preferences. From the Window menu choose Preferences.

Eclipse screenshot showing the Eclipse Window Preferences.

Choose the Sanit4J Preferences from the Preferences list. You will need to configure the locations of the Tools product directory and the Java executable.

Click the "Browse" button next to the "Product directory" field.

Eclipse screenshot showing the Eclipse Preferences list.

Choose the location of the product tools, then click OK. This can be the extracted location of the sanity4j-1.8.2-bin-with-tools.zip

Eclipse screenshot showing the Product Tools Location.

Click the "Browse" button next to the "Java executable" field.

Eclipse screenshot showing the Java bin location.

Choose the location for the Java executable (e.g. java.exe on the windows platform). This should is usually in the java\bin directory.

Importing the Sanity4J properties for the Eclipse plugin.

The Sanity4J Configuration and Classpath for plugins can be configured for Eclipse by manually specifiy the values or by importing them from an existing sanity4j.properties file.

For this example we will import them.

Eclipse screenshot showing the Eclipse Preferences.

Click the "Browse" button next to the "Sanity4j properties file" field. Choose the location of your sanit4j.properties file, then click Open.

Eclipse screenshot showing the sanit4j properties location.

Click the "Load from properties" button. You will see that the Configuration and Classpath fields will be populated from the values in the sanity4j.properties file.

Eclipse screenshot showing the Sanit4J properties loaded.

Running the Sanity4J Eclipse plugin.

To run the Sanity4J Eclipse plugin you will need to have a Java Class open in the Workspace. The "QA" icon on the Menu Bar will become available.

Eclipse screenshot showing the Sanit4J button.

After clicking the button, the analysis will begin. The analysis will be made only for the currently active Java Class that is open.

Eclipse screenshot showing the analysis progress.

Upon completion of the analysis, the "Sanity4J results" pane will be visible. The pane will show the results of the analysis of the current Java Class.

Eclipse screenshot showing the Sanit4J results.