|
| 1 | +# db\* CODECOP for SonarQube |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +[db\* CODECOP for SonarQube](https://github.com/Trivadis/plsql-cop-sonar) is a plugin for [SonarQube](http://www.sonarqube.org/). The plugin analyses SQL and PL/SQL code and calculates various metrics and checks the code for compliance of this coding guideline. |
| 6 | + |
| 7 | +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 PostgreSQL, Microsoft SQL Server and Oracle Database. For evaluation purposes, the embedded H2 database can also be used. |
| 8 | + |
| 9 | +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 db\* CODECOP plugin if you care about your PL/SQL code quality. |
| 10 | + |
| 11 | +## Examples |
| 12 | + |
| 13 | +### Run Code Analysis via SonarScanner |
| 14 | + |
| 15 | +You start an analysis from the command line as follows (see [docs](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/) for more information): |
| 16 | + |
| 17 | +``` |
| 18 | +sonar-scanner -Dsonar.projectKey="sample" |
| 19 | +``` |
| 20 | + |
| 21 | +Here's an excerpt of the output: |
| 22 | + |
| 23 | +``` |
| 24 | +INFO: Scanner configuration file: /usr/local/opt/sonar-scanner/conf/sonar-scanner.properties |
| 25 | +INFO: Project root configuration file: NONE |
| 26 | +INFO: SonarQube Scanner 4.1.0.1829 |
| 27 | +... |
| 28 | +INFO: Project configuration: |
| 29 | +INFO: 115 files indexed |
| 30 | +INFO: Quality profile for plsql: db* CODECOP |
| 31 | +INFO: ------------- Run sensors on module sample |
| 32 | +INFO: JavaScript/TypeScript frontend is enabled |
| 33 | +INFO: Define db* CODECOP PlugIn (Secondary) |
| 34 | +INFO: Load metrics repository |
| 35 | +INFO: Load metrics repository (done) | time=36ms |
| 36 | +INFO: PlSQL COP Sensor initializing |
| 37 | +INFO: Instantiate class: com.trivadis.sonar.plugin.TrivadisGuidelines3ValidatorConfig |
| 38 | +INFO: Sensor CSS Rules [cssfamily] |
| 39 | +INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped. |
| 40 | +INFO: Sensor CSS Rules [cssfamily] (done) | time=1ms |
| 41 | +INFO: Sensor PL/SQL Sensor [plsql] |
| 42 | +INFO: 115 source files to be analyzed |
| 43 | +INFO: Load project repositories |
| 44 | +INFO: Load project repositories (done) | time=10ms |
| 45 | +... |
| 46 | +INFO: Analysis report generated in 149ms, dir size=603 KB |
| 47 | +INFO: Analysis report compressed in 1101ms, zip size=264 KB |
| 48 | +INFO: Analysis report uploaded in 1858ms |
| 49 | +INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=sample |
| 50 | +INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report |
| 51 | +INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AXiSv3IJVMRTx5sCSVMo |
| 52 | +INFO: Analysis total time: 27.088 s |
| 53 | +INFO: ------------------------------------------------------------------------ |
| 54 | +INFO: EXECUTION SUCCESS |
| 55 | +INFO: ------------------------------------------------------------------------ |
| 56 | +INFO: Total time: 28.961s |
| 57 | +INFO: Final Memory: 40M/144M |
| 58 | +INFO: ------------------------------------------------------------------------ |
| 59 | +``` |
| 60 | + |
| 61 | +At the end of the run an URL to the scanner result is provided. |
| 62 | + |
| 63 | +### Run Code Analyis with CI Environments |
| 64 | + |
| 65 | +You can call the SonarScanner also from Gradle, .NET projects, Maven, Ant, Jenkins, etc. Whichever method you use, in the end the analysis report will be uploaded to SonarQube. |
| 66 | + |
| 67 | +See [SonarScanner](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/) for more information. |
| 68 | + |
| 69 | +### View Code Analysis Result in SonarQube |
| 70 | + |
| 71 | +Here are the results of the previous analysis. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +Under `Issues` the following `Blocker` are shown: |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +By clicking on the reddish box you can drill down to the source code. |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +When clicking on `Why is this an issue?` the complete rule is shown in similar way as in these guidelines. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +See [SonarQube documentation](https://docs.sonarqube.org/latest/) for more information. |
0 commit comments