Visual COBOL uses the information stored in an Apache Ant script, .cobolBuild, to build COBOL projects.
.cobolBuild is part of your project. It is stored in the project's directory alongside the .cobolProj file and, in Eclipse, you can access it if you explore the project in the Navigator view.
The script is automatically regenerated when when you change the project's properties or rebuild the project file, .cobolProj.
Enabling code analysis for a project adds the following elements to the .cobolBuild script:
The task requires the FailOnError attribute that specifies whether the build fails or continues when code analysis returns any results.
This also requires the ruleList type with rule nested elements which specify the rules to execute. If you have enabled rules that are imported into the IDE from a non-default location, the details about these rules are added to the ruleList.custom type.
The mffilelist type specifies the COBOL files to run code analysis on.
You must specify one of these targets when performing code analysis at the command line:
If you have imported additional rules into the IDE from a different folder, that folder is stored in the rulesDir.custom tag.
You can explore these parameters if you create a native COBOL project, enable code analysis for it from the project's properties, and open the .cobolBuild file in the editor.
You can perform code analysis of your source files at the command line using Apache Ant and the .cobolBuild script. The following is an overview of the process:
CLASSPATH=product-install-dir\bin\mfant.jar;%CLASSPATH%
For example, if Visual COBOL is installed in the default location:
CLASSPATH=%ProgramFiles(x86)%\Micro Focus\Visual COBOL\bin\mfant.jar;%CLASSPATH%
Ant-install-dir\bin\ant -f .cobolBuild Ant-target -DanalysisFailOnError=value
Where:
For example:
c:\tools\antdir\bin\ant -f .cobolBuild build.and.analyze -DanalysisFailOnError=true
When you change the settings for code analysis in the project's properties, this changes the .cobolBuild script file. Alternatively, you can open the .cobolBuild script in the editor and make any changes to the code analysis settings manually (though, these changes are reverted if the IDE rebuilds the project).
You can use the .cobolBuild script file from outside of the workspace to perform code analysis, provided that the script and the source files are stored in the same location. This can be useful if you want to integrate your code analysis tasks into a continuous integration (CI) framework or when you store your applications outside of the workspace - for example, in a version control system such as Subversion.
In this case, you can manually modify the file to create more complex code analysis targets. You would not be able to edit the script if it is opened as part of a project as the IDE rebuilds the script each time it rebuilds the project.
See the section, Properties for Code Analysis in the .cobolBuild script, in this topic for the .cobolBuild script parameters that must be present. Ensure that the rulesDir and rulesDir.custom tags point to the locations of the files that contain the code analysis rules to execute.
The results of running code analysis from the command line are shown in the command prompt window alongside all the build messages.
The messages have the following format:
[Filename and full path] [LocationInFile (start line, column, end line, column)] : [ErrorMessage (error/warning + output code)] : [RuleSetName] : [Rule] : [Code snippet the location refers to]
For example:
C:\Tutorials\Projects\MyProject\MyProgram.cbl (14,8,14,33): warning MFCA0001 : Within Entire Program : Dead Statements : display "Some Message"