Getting started with Klocwork Desktop Java Plug-in for IntelliJ IDEA

From current

Desktop analysis > IntelliJ IDEA > Getting started with Klocwork Desktop Java Plug-in for IntelliJ IDEA

Contents

Prerequisites and setup considerations

Installation

Before you can analyze your source code, you need to install the Klocwork User package.

An integration project to connect to

Connected desktop is a key step in harnessing the power of Insight. Before you can connect, an integration project must be set up and analyzed on the Klocwork Server. For more information about integration projects, see Integration build analysis.

If you don't connect to an integration project, this is referred to as standalone desktop.

Connect to a project on the Klocwork Server

Note: If you see a login dialog, enter the credentials provided by your Klocwork administrator, or your LDAP or NIS user name and password.

You can connect to a server project to share analysis results, issue-status updates, and comments with the integration build analysis and among team members.

Contact your Klocwork administrator for more information about available server projects.

  1. In IntelliJ IDEA, click File > Settings.
  2. Under Project Settings, double-click Klocwork for Java.
  3. In Klocwork project, select the Klocwork Server project you want to connect to.
  4. Enable the Use secure connection checkbox if a secure connection to the Klocwork Server has been set up.
  5. Click OK.

Tip: You only have to do this step once, before your first analysis for a project.

Run Klocwork

  1. In IDEA, open the project you want to analyze.
  2. Click the analysis button Klocwork check icon.jpg in the toolbar.
    Tip: The analysis button in the toolbar Klocwork check icon.jpg always analyzes modules that you've selected on the Project Settings page. By contrast, using the right-click Run Klocwork for Java analysis menu option analyzes modules that are currently selected in the Project Explorer (whether or not they are selected on the Project Settings page).

When the analysis is complete, the Klocwork for Java view shows the analysis results.

Review and investigate

In the Klocwork for Java view, you can:

  • Group issues, for example by severity, to narrow your focus.
  • Click an issue in the list to view the source code where the issue appears.
    The corresponding line in the source code is highlighted in the source viewer. If traceback is available for the detected issue, the traceback displays to the right of the list of detected issues.
    Traceback identifies and describes statements in the source code that contribute to issues. Traceback lines link directly to the source code and follow execution order.
    Click the traceback statements to find problems that led to the issue you are viewing in the list. Key statements that contribute to issues are marked with red rectangles and include a description of the problem.
    Tip: Traceback may not be available for all issues. If you don’t see any traceback for the error selected from the list of issues, it means that the problem associated with the issue is confined to one line of code.
  • Get help on an issue by right-clicking the issue and selecting Show help.

Locate and fix "Local" issues

If you have a connected desktop project, you may want to focus on only the issues you’ve injected into your project, so that you can fix them before checking in your code.

By default, Klocwork Insight shows all detected issues whether their origin is Local or System. Local issues are those you’ve introduced since the last integration build analysis; System issues are those that exist in the integration build.

Simply change your filter settings to "Show Local issues only":

  1. In the Klocwork for Java view, select the "Show Local issues only" filter Show local issues only icon.png.
  2. Fix the issue and re-run the analysis.

When the issue disappears from the list, it's fixed.

Cite the remaining issues

Citing refers to changing the status for detected issues and/or adding comments. You can cite issues one at a time or in batches.

Issue statuses are a way of notifying others that you have reviewed the issue and made a recommendation about how it should be handled. It’s a good idea to add a comment to provide more detail.

For instance, if there’s an issue that you just don’t care about, you can change its status to Ignore.

  1. Right-click an issue in the list and select Change Status.
    The Change Status dialog displays.
  2. Select a status from the list.
  3. Enter a comment in the Comments field.
  4. Click OK.
    Tip: Default filter settings mean that only issues with the status of Analyze and Fix are shown in the Klocwork Issues view. To narrow your focus or add issues to the view that are currently hidden by the filters, click Filter icon.jpg.
    The list of Klocwork issues updates to reflect the changes you made.
    If you're connected to a project on the Klocwork Server, your changes are now visible to other developers, and in Klocwork Review. Your desktop project is also updated with any changes made by other developers. This happens even before another build analysis has been run.

Before you check in

Now that your desktop analysis and issue citing is up to date, you may want to set up a pre-checkin code review from your IDE. For instructions, see Setting up a pre-checkin code review.

What’s next?

Now that you've run your first Klocwork desktop analysis, you may want to check out additional help resources: