Skip to content

Commit f592fa3

Browse files
committed
Fix #8 and #9 - Restructured Tool Support section with individual chapters on 4 db*CODECOP tools as well as plscope-util
1 parent 7b50d70 commit f592fa3

26 files changed

+192
-35
lines changed

docs/7-tool-support/.pages

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
collapse_single_pages: true
1+
title: Tool Support
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# db\* CODECOP for SQL Developer
2+
3+
## Introduction
4+
5+
[db\* CODECOP for SQL Developer](https://github.com/Trivadis/plsql-cop-sqldev) is a **free extension** to check an editor content for compliance violations of this coding guideline. The extension may be parameterized to your preferred set of rules and allows checking this set against a program unit.
6+
7+
db\* CODECOP calculates metrics per PL/SQL unit, such as:
8+
9+
- McCabe’s cyclomatic complexity
10+
- Halstead’s volume
11+
- The maintainability index
12+
- Lines
13+
- Commands (SQL\*Plus and SQL)
14+
- Statements (within a PL/SQL unit)
15+
- etc.
16+
17+
And aggregates them on file level.
18+
19+
The results are presented in an additional tabbed panel. One tab shows all guideline violations to quickly navigate to the corresponding code position. The other tab contains a full HTML report, which also may be opened in your external browser.
20+
21+
## Examples
22+
23+
Open an Oracle PL/SQL or SQL script in a SQL Developer editor and press Ctrl-Shift-C to check your code against the Trivadis PL/SQL & SQL guidelines.
24+
25+
![Check](../images/tvdcc-sqldev-check.png)
26+
27+
Navigate through the issues using the cursor keys to highlight the related code section in the linked editor.
28+
29+
![Issues](../images/tvdcc-sqldev-issues.png)
30+
31+
Dock the db\* CODECOP output window on your favorite position within SQL Developer and click on the report tab to reveal some additional metrics. Open the report in an external browser to print or save the report.
32+
33+
![Report](../images/tvdcc-sqldev-report.png)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
![SonarQube Dashboard](../images/sonar_1.png)
74+
75+
Under `Issues` the following `Blocker` are shown:
76+
77+
![SonarQube Issues](../images/sonar_2.png)
78+
79+
By clicking on the reddish box you can drill down to the source code.
80+
81+
![SonarQube Issues in Source](../images/sonar_3.png)
82+
83+
When clicking on `Why is this an issue?` the complete rule is shown in similar way as in these guidelines.
84+
85+
![SonarQube Guideline Details](../images/sonar_4.png)
86+
87+
See [SonarQube documentation](https://docs.sonarqube.org/latest/) for more information.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# db\* CODECOP Command Line
2+
3+
## Introduction
4+
5+
[Trivadis db\* CODECOP](https://github.com/Trivadis/plsql-cop-cli) is a command line utility to check Oracle SQL*Plus files for compliance violations of this coding guideline.
6+
7+
Furthermore McCabe’s cyclomatic complexity, Halstead’s volume, the maintainability index and some other software metrics are calculated for each PL/SQL unit and aggregated on file level.
8+
9+
The code checking results are stored in XML, HTML and Excel files for further processing.
10+
11+
To get the most out of this command line utility you should make it part of your Continuous Integration environment by using the [db\* CODECOP for SonarQube](https://github.com/Trivadis/plsql-cop-sonar) plugin. This way you may control the quality of your code base over time.
12+
13+
Have also a look at [db\* CODECOP for SQL Developer](https://github.com/Trivadis/plsql-cop-sqldev) if you are interested to check the code quality of PL/SQL code within SQL Developer. It’s a free extension.
14+
15+
db\* CODECOP supports custom validators. We provide some [example validators in this GitHub repository](https://github.com/Trivadis/plsql-cop-validators). You may use these validators as is or amend/extend them to suit your needs.
16+
17+
## Examples
18+
19+
Here are some screen shot taken from an of an HTML report based on the samples provided with db\* CODECOP.
20+
21+
![Processing & Content](../images/plsqlcop_processing.png)
22+
![Issue Overview](../images/plsqlcop_issues_overview.png)
23+
![Complex PL/SQL Units](../images/plsqlcop_complex_plsql_units.png)
24+
![File Overview](../images/plsqlcop_file_overview.png)
25+
![File Issues](../images/plsqlcop_file_issues.png)
26+
27+
These [HTML](https://trivadis.github.io/plsql-cop-cli/tvdcc_report.html) and [Excel](https://trivadis.github.io/plsql-cop-cli/tvdcc_report.xlsx) reports have been created by db\* CODECOP and are based on a simple set of good and bad example files distributed with db\* CODECOP.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# db\* CODECOP Validators
2+
3+
db\* CODECOP supports custom validators. A validator must implement the `PLSQLCopValidator` Java interface and has to be a direct or indirect descendant of the `PLSQLValidator` class. Such a class can be used in the command line utility and the SQL Developer extension.
4+
5+
For SonarQube a `ValidationConfig` is required. A config defines the validator with its rules and quality profile for SonarQube. See [GLPValidatorConfig](https://github.com/Trivadis/plsql-cop-validators/tree/main/src/main/java/com/trivadis/sonar/plugin/GLPValidatorConfig.java). The referenced XML files are generated based on the validator and the optional [sample guidelines](https://github.com/Trivadis/plsql-cop-validators/tree/main/src/main/resources/GLP/sample).
6+
7+
You may use these validators as is or amend/extend them to suit your needs.
8+
9+
## Provided Validators
10+
11+
The [db\* CODECOP Validators](https://github.com/Trivadis/plsql-cop-validators) project provides the following custom validators in the package `com.trivadis.tvdcc.validators`:
12+
13+
Class | Description
14+
----- | -----------
15+
TrivadisPlsqlNaming | Checks [Naming Conventions](https://trivadis.github.io/plsql-and-sql-coding-guidelines/2-naming-conventions/naming-conventions/#naming-conventions-for-plsql) of the Trivadis PL/SQL & SQL Coding Guidelines
16+
GLP | Checks naming of global and local variables and parameters
17+
SQLInjection | Looks for SQL injection vulnerabilities, e.g. unasserted parameters in dynamic SQL
18+
Hint | Looks for unknown hints and invalid table references
19+
OverrideTrivadisGuidelines | Extends TrivadisGuidelines3 and overrides check for [G-1050](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.0/4-language-usage/1-general/g-1050/).
20+
TrivadisGuidelines3Plus | Combines the validators TrivadisPlsqlNaming, SQLInjection and OverrideTrivadisGuidelines.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# plscope-utils
2+
3+
## Introduction
4+
[plscope-utils](https://github.com/PhilippSalvisberg/plscope-utils) is based on PL/Scope which is available in the Oracle Database since version 11.1. It consists of the following two components:
5+
6+
- [Core Database Objects](https://github.com/PhilippSalvisberg/plscope-utils/blob/main/database/README.md)
7+
8+
Provides relational views and PL/SQL packages to simplify common source code analysis tasks. Requires a server side installation.
9+
10+
- [SQL Developer Extension (plscope-utils for SQL Developer)](https://github.com/PhilippSalvisberg/plscope-utils/blob/main/sqldev/README.md)
11+
12+
Extends SQL Developer by a ```PL/Scope``` node in the database navigator tree, context menus, views shown for tables, views and PL/SQL nodes and some reports. Requires a client side installation only.
13+
14+
Part of plscope-utils is a check of naming conventions according to this coding guideline - either as a database view or a Oracle SQL Developer report.

docs/7-tool-support/tool-support.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/9-appendix/appendix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ n/a | 7330 | Always assign values to OUT parameters. | Major | | | ✘ |
115115
74 | 7440 | Never use OUT parameters to return values from a function. | Major | | | | | | ✘ | |
116116
75 | 7450 | Never return a NULL value from a BOOLEAN function. | Major | | | | | ✘ | | | ✘
117117
n/a | 7460 | Try to define your packaged/standalone function deterministic if appropriate. | Major | | ✘ | | | | | |
118-
76 | 7510 | Always prefix ORACLE supplied packages with owner schema name. | Major | | | | | | | ✘ |
118+
76 | 7510 | Always prefix Oracle supplied packages with owner schema name. | Major | | | | | | | ✘ |
119119
77 | 7710 | Avoid cascading triggers. | Major | | | ✘ | | | | | ✘
120120
n/a | 7720 | Never use multiple UPDATE OF in trigger event clause. | Blocker | | | ✘ | | ✘ | | | ✘
121121
n/a | 7730 | Avoid multiple DML events per trigger. | Minor | | | ✘ | | | | | ✘
-117 KB
Binary file not shown.
-75.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)