Kwdefectimport

kwdefectimport is a tool for importing third-party (non-Klocwork) defects into a Klocwork project. This functionality is used when there is a requirement to view these defects from within Klocwork but these defects were not discovered by Klocwork. See Import external defects with kwdefectimport for a complete description of how to use kwdefectimport.

Prerequisites

You must have a valid external defect listing, where each listing describes at least:
  • A defect code.
  • An absolute or relative path and file name of the source file that contains the defect. You can also specify a working directory.
  • The line number that represents where the defect is located in the source file.
  • A message explaining the defect which adds context when the defect is highlighted within our tool. This is not mandatory but is highly recommended.

Before you can import a defect, the taxonomies, categories and defect types associated with the defect must already exist. For more information about this, see Create a taxonomy.

In order to import defects, you must also write a Java class that implements the interface, com.klocwork.defectimport.IDefectParser. See Create a defect parser for more information.

Usage

  kwdefectimport [options] <defects_source> [<defects_source>...]  

where

  • <options> is any of the options listed below
  • <defects_source> is the location of the defects you want to import; you can specify multiple sources

Examples

kwdefectimport --tables-directory "C:/Klocwork/Server XY.Z/projects_root/projects/abc_main"
 --working-directory "C:/_workspaces/ABC_Main/src" --parser-class com.klocwork.defectimport.parser.TNSDLDefectParser
 --rejected-defects C:/tables/rejecteddefects.json --ext-libs "C:/Klocwork/lib/kwdefectimport.jar" 
--ext-libs "C:/Klocwork/lib/another_required_library.jar" "C:\already_analyzed_defects_in_proprietary_format\defects_01.xml" 
"C:\already_analyzed_defects_in_proprietary_format\defects_02.xml  

Options

Name (and short name) Description
--tables-directory (-T) location of your tables directory into which the defect(s) are imported
--help (-h) display help
--version print version information
--working-directory (-W) Optional The location of your working directory. If this value is specified, the file name specified in the defect list is deemed to be a relative link, based on this directory.
--ext-libs (-L) location of the external library which contains the jar file for the parser component
--parser-class (-p) location of the parser java component needed to implement the interface
--rejected-defects (-R) path and file name of a json file containing rejected defects (optional)

Validation

When you run kwdefectimport, the data in the external defect file is validated before it is appended to the defect list for import. If a problem occurs during validation, or incorrect data is encountered, you may experience one of the following errors:

Error Description
The defect type has not been registered If the defect code has not been registered as per taxonomy, category and defect type requirements, the defect will be rejected.
Duplicate defects not permitted

As each defect is processed, a record is made of the name of the type of defect it is, the file in which it exists, and the line number on which it occurs. If a subsequent defect that has the same identifying information is processed, that defect will be rejected as a duplicate.

Note that this means that a defect is considered a duplicate even though its message may be different than the prior, 'original', defect.

The source file in which the defect occurs cannot be found at the specified location

If the source file name is absolute, then the file system is checked to see if this file actually exists. If it does not exist, then the defect is rejected.

If the source file name is relative, then the value of working-directory is used as the starting point for finding the file. If the file does not reside relative to this location, then the defect is rejected.

The source file in which the defect occurs is not referenced in file.dat (and by extension, entity.dat) This will always be the case on the first run of kwdefectimport against a given external source base. For each defect that is processed, the file name in which the defect occurs is compared against all of the files referenced in file.dat. If that file has not yet been added to file.dat and entity.dat, it will be added at this time. Subsequent defects that occur in this same source file will not cause the file to be re-added. This validator will always succeed unless an exceptional circumstance, such as the inability to edit file.dat or entity.dat, occurs.

Exit codes

After running kwdefectimport and there are no critical errors and all defects were imported as expected, the exit code will be 0. If a critical error occurred (other than a defect being rejected by a validator), then the exit code will be 1. Otherwise the exit code will be a number that represents which of the validators rejected the defect. The table below shows all possible exit codes and under what conditions they occur:

Error Value 1 16 32 64 128  
Error Name Critical Defect Type Not Registered Duplicate Defect Source File Not Found Source File Not Referenced Exit Code
            0
  x         1
    x       16
      x     32
    x x     48
        x   64
    x   x   80
      x x   96
    x x x   112
          x 128
    x     x 144
      x   x 160
    x x   x 176
        x x 192
    x   x x 208
      x x x 224
    x x x x 240

x indicates that an error of the named type occurred at least once in the course of processing the source defects.