The Sonar Cobol Product doesn’t have any special requirement in addition to the Sonar platform’s requirements.
Read the installation guide to deploy and configure Sonar. Extra steps specific to the Sonar Cobol Product are :
- Copy the file sonar-cobol-plugin.jar to /extensions/plugins
- Restart the Sonar server
When the Sonar server is up, login as an admin, select configuration -> settings, click on the Cobol tab and enter the evaluation key provided. You are now ready to run analysis on Cobol projects !
A specific widget is available in the plugin, showing Cobol specific metrics :

From Sonar 2.4, this widget needs to be added once manually to dashboards.
For every Cobol project, a file named pom.xml must be created at the root directory of the project. Here is a template of information to fill in the pom. Note that [ ] should be replaced with your own parameters :
If you do not see a snippet above, you download directly the file from here
Additional settings are available in the projects and global settings of Sonar such as :
- filtering source code on files extension
- specifying location of copy files
- filtering copy files on files extensions
- number of minimum identical tokens for a duplication
- skipping detection of duplication (as it can be too ressource consuming on big projects)
- specifying the number of spaces to replace a tab char (It’s a bad practice to use tabs instead of spaces but in case of use this property is mandatory to extract the program text : columns 8 through 72.)
- activating Microfocus or ACUCOBOL-GT extension

Execute the following command from the root directory of the Cobol project : “mvn sonar:sonar”.
You can browse http://localhost:9000.
ACUCOBOL-GT Source Code Control directives
The Sonar COBOL product support the ACUCOBOL-GT’s Source Code Control directives. This mechanism allows to conditionally modify the source program at compile time. This is accomplished by having lines in the source that can be excluded or included at compile time. This can be used to maintain different versions of the program, perhaps to support different machine environments.
The “-Si” (include) flag controls the actions of the source code control system. It must be followed by an argument that specifies a pattern that the compiler will search for in the Identification Area of each source line. If the pattern is found, then the line will be included in the source program, even if it is a comment line. However, if the pattern is immediately preceded by an exclamation point, then the line will be excluded from the source (i.e., commented out).
The “-Sx” (exclude) flag works in the same fashion except that its meaning is reversed (i.e., lines with the pattern will be commented out and lines with a preceding exclamation point will be included).
Here is an example. Suppose that a source program is being maintained for both the UNIX and VMS environments. The following piece of code is in the program:
This program fragment is ready to be compiled for the VMS system. If a UNIX version is desired, then the following flags will correct the source during compilation:
-Si UNX -Sx VMS
Please, have a look to the ACUCOBOL-GT documentation to get deeper understanding of the ACUCOBOL-GT mechanism.
There are two ways in Sonar to specify the list of ACUCOBOL-GT flags to be used in order to preprocess the source code. The first option is to define a list of global flags which will be used to preprocess all source files. This can be done in the Settings page :

The second option is to provide a list of relative paths (with help of the ‘sonar.cobol.acucobol.preprocessor.directives.directories’ property) which contain the list of flags to be used for each COBOL source file. Let’s take a simple example, if a file “MY_PROGRAM.CBL” is going to be processed, the Sonar ACUCOBOL-GT preprocessor, will try to find a file “MY_PROGRAM.CMD”. If this file is found, then the flags contained in this file is going to be used to preprocess the program “MY_PROGRAM.CBL”. If the file “MY_PROGRAM.CMD” doesn’t exist, then the preprocess will use the content of the file “DEFAULT.CMD” if exists.

