Getting started with the Klocwork Desktop C/C++ plugin for EclipseGetting started with the Klocwork Desktop C/C++ plugin for EclipseThe Klocwork plug-in for Eclipse helps you detect and fix issues before check-in. Information and instructions below also apply to the following C/C++ Eclipse-based IDEs:
If you are a C/C++ developer, you will need to do a bit of tweaking to ensure Klocwork has the build information it needs to run an accurate analysis (more details about this are included in the sections below). The plug-in is equipped with several popular C/C++ refactorings, such as renaming of inlining functions, which can be performed within your IDE. You can also customize project settings, issue filters and analysis settings to your own preferences. For more information about these features, see the topics below. Set up a local projectFor each coherent, buildable component that you work on, create a local project -- a repository for your analysis results and settings. You need to set up a project only once for each component you work on. Capture your build settingsKlocwork requires a build specification to perform an analysis. The build specification contains a list of the project's source files and their compiler options (includes and defines). Klocwork creates the build specification by monitoring the IDE build process or by monitoring an external (command-line) build process. The former is recommended as it automatically updates the build specification when files are added or removed from the project. Important: Do not rely on the Eclipse CDT indexer to generate the build specification, because this method has proven inaccurate. Note: If you use QNX Momentics, see Capturing your build settings for QNX Momentics instead.
Option 1: If you build outside Eclipse or Wind River WorkbenchRun kwinject directly to create a build specification. See Creating a C/C++ build specification. After you generate your build specification, you need to Specify your build settings.
Option 2: If you build inside Eclipse or Wind River WorkbenchThe steps vary depending on whether you are using Eclipse, QNX Momentics or Wind River Workbench. If you are using QNX Momentics, see Capturing your build settings for QNX Momentics. If you are using Wind River Workbench, see Integrating Klocwork with Wind River Workbench. Eclipse
Specify your build settings
The properties are saved for the selected project and used when you run your next analysis. You only have to specify build settings once for your project, as long as your updated build specification file remains in the same location. Connect to a project on the Klocwork ServerYou get the most from static code analysis when you connect a small local project to a larger project on the Klocwork Server. The small local project is analyzed quickly while incorporating Klocwork knowledge bases generated on the server where additional source files were analyzed (for example, shared libraries). Connecting to a server project also allows you to share issue status information with the integration build analysis and among team members. You can run a standalone desktop analysis, but the analysis only derives knowledge from the local project's source files. You perform this step only once for each project.
Import or export your local project synchronization settingsRather than modify the settings for each project in your workspace, you can perform a batch import/export of all local project synchronization settings for an entire workspace. When exported, the settings are stored in a simple XML file which can be shared with other developers or re-imported to rebuild a workspace. When imported into a new workspace, all project synchronization settings in the new workspace will be overridden. This is true for all projects, regardless of whether or not the Enable project specific settings checkbox is enabled. If project MyProj in Workspace A has Enable project specific settings disabled, and project MyProj in Workspace B has Enable project specific settings enabled, the configuration settings for project MyProj in Workspace B will be overwritten and local project settings will be disabled. The configuration settings include:
To export your project synchronization settings
Click View Map to view the configuration mapping file in your default XML viewer. The following listing shows the format of a typical output file with two projects:
<SyncMapping> <ProjectSettings EclipseProjectName="myProj"/> <ProjectSettings EclipseProjectName="HelloWorld3"> <ProjectSyncInfo KwProjectName="HelloWorld3" KwServerHost="server11" KwServerPort="8080" KwSslEnabled="true"/> </ProjectSettings> </SyncMapping> To import a configuration mapping file
Note: The list of projects specified in the map file can be a subset or superset of the list of projects in your current workspace. At import time, only projects found in the workspace will have their local configuration settings modified. When the import operation completes, a status message is displayed.
Continuous analysis when you open and save filesContinuous analysis is enabled by default and runs when you open or save a file. If Klocwork issues are detected, an orange square Issues are marked by a lighter orange rectangle To see a list of detected issues, go to Window > Show View > Other > Klocwork > Klocwork Issues. In connected desktop projects, local issues are those you've introduced since the last integration build analysis; system issues are those that also exist in the integration build. Investigate detected issues
Fix defects and ignore the restFor a real defect:
For an issue that doesn't need to be fixed:
If you're connected to a project on the Klocwork Server, your changes are now visible to other developers, and in Klocwork Static Code Analysis. Your desktop project is also updated with any changes made by other developers. This happens even before another integration build analysis has been run. Discarding issues (CI builds only)If you configure Continuous Integration (CI) builds and open an issue in Eclipse using the 'open in IDE' button from one of the supported CI plug-ins, this imports the issue into your open project. If you have fixed this issue or simply want to remove it from your issue list, you can right-click on the issue and click Discard imported issue. Note that this functionality does not apply to issues found from a full analysis; these issues cannot be discarded. Keep your build specification up to dateIf you build outside Eclipse, whenever you add files or change build settings, update your build specification with the --update option of kwinject and save it to the same location. If your build specification is out of date, the analysis will not be accurate. |