We have seen in the previous post how to install Sonar and its Java Runner. This last one allows us to realize analysis without using tools like Maven or Ant.
In this post, we will present how to do a first analysis on Mainframe-Cobol source code.
Let’s remember that:
- The sonar-runner.properties file is dedicated to the connexion to Sonar and our database
- We launch an analysis with the sonar-runner.bat file.
When you install a server of code analysis, it is important to differentiate correctly the different spaces you will be using, according to their object:
- A space dedicated to the various software and their different versions: Oracle, Java, Tomcat, Sonar, etc.
- The space dedicated to the delivery and the installation of the source code to analyze.
- The space dedicated to the implementation of analyses: configuration, backups, customization, creation of reports, extraction of data, documentation of your analyses (useful when you begin to get a lot of different ones, or when you have to get back to an old one, or different people operate the analysis server), etc.
Sonar allows us to specify this space in the sonar-runner.bat, with the PROJECT_HOME variable. We are thus going to look into this file for the following line:
and modify it to indicate a sub-directory \Projets in which I will put the configuration file of my analysis. Really, I would not recommand to place this space under the directory of the Java Runner, it is only for the needs of our demonstration.
So, I modified this sonar-runner.bat file in order to insert the following three lines:
- Display the directory of the Java Runner SONAR_RUNNER_HOME:
echo “SONAR_RUNNER_HOME = %SONAR_RUNNER_HOME%”
- Define the analysis space PROJECT_HOME as the sub-directory \Projets under the previous folder, and display it:
echo “PROJECT_HOME = %PROJECT_HOME%”
Configuration of our first analysis
In order to realize an analysis, the Java Runner uses the sonar-project.properties file located in our environment of analysis. Here we have for objective to analyze some Cobol programs we placed in a directory C:\SRC\Mainframe.
Without detailing all the available parameters for such an analysis, we are going to create our file sonar-project.properties with the following attributes:
- First, the mandatory data: name and key for this application / first analysis, with a version number:
# required metadata
sonar.projectName=Cobol 1st Analysis
- Localization of the files to analyze:
- Last parameter: the programming language for this application:
#The value of the property must be the key of the language.
Run the first analysis
In a DOS command window, we launch the sonar-runner.bat:
- First are displayed the 2 variables designing the directory of the Java Runner and our analysis space: With the directory where is located the source code:
- And every possible error (here, an incorrect character chain into the Cobol source code):
- Thanks to Sonar, a syntax error in our Cobol code will not stop it and soon, the ‘Analysis successfull’ message is displayed:
We could realize our first analysis successfully and in the simplest possible way, with the configuration of some parameters in the sonar-project.properties, without the need to manage Maven files, whose syntax is sometimes long and complex.
However, the approach described here presents two inconveniences:
- The Java Runner works only with the sonar-project.properties file. Rename this one and the Java Runner will not work correctly anymore. It is thus necessary to modify this file every time we want to do a new analysis.
- Checking the possible errors in a DOS window is not very friendly, especially for long analysis and / or with a lot of errors.
We will see in our next post how to improve our analysis server, with the help of our friend Jenkins.