This post has already been read 3039 times!
PL/SQL Cop for SonarQube is a plugin for SonarQube. The plugin analyses SQL and PL/SQL code and calculates various metrics and checks the code for compliance of the Trivadis PL/SQL & SQL Coding Guidelines Version 2.0. Behind the scenes the plugin calls the PL/SQL Cop command line utility for the static code analysis.
A static code analysis is typically initiated as part of an continuous integration setup, e.g. at the end of a Jenkins or Hudson build job. SonarQube stores the result of the analysis in a relational database. Supported are HSQLDB, PostgreSQL, MySQL, Microsoft SQL Server and Oracle Database, of course.
Since every analysis is stored as a snapshot in the SonarQube repository the improvement or the decrease of the code quality may be monitored very well. Use SonarQube and the PL/SQL Cop plugin if you care about your PL/SQL code quality.
Setup a build job with a standalone SonarQube analysis at the end of the job. Here’s an example within a Jenkins build job:
Important are the analysis properties. The mandatory ones are sonar.projectKey, sonar.projectName, sonar.projectVersion and sonar.sources. You may defined them as shown above or within a sonar.properties file in the source folder. See the SonarQube documentation for more information.
The build job is typically started after a change in the software configuration system such as GIT, SVN or CVS or other relevant events. You may even trigger the build manually. The log of such a build job looks as follows:
At the bottom of a build log you find a link to the SonarQube project dashboard. Click on it and the following project dashboard is shown:
You see that 6 critical issues have been found in the guideline project. Click on “6” to drill down to the critical issues.
Click on the arrow on the right side of an issue to drill down to the source code.
Click on the three dots after the issue text to get more information about the violated guideline.
Copy the downloaded sonar-plsql-cop-plugin-1.0.2.jar file into the extensions/plugins folder of your SonarQube installation and restart the SonarQube server. Login as admin, click on “Settings” in the main menu bar and configure the “Trivadis :: PL/SQL Cop” section as shown below
Press “Save Trivadis :: PL/SQL Cop Settings” to the configuration.
It’s important to note, that this version of PL/SQL Cop for SonarQube works from version 4.5.0 up to version 5.1.2. Newer versions are not yet supported due to changes in various plugin interfaces.