Skip to content

Commit d93f69c

Browse files
Merge pull request #69 from Trivadis/feature/23c
Use tvdcc-5.0.0 with support of Oracle Database 23c
2 parents 9ed4696 + 50e985c commit d93f69c

24 files changed

+290
-84
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ This project provides the following four custom validators in the package `com.t
1212

1313
Class | Description
1414
----- | -----------
15-
TrivadisPlsqlNaming | Checks [Naming Conventions](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.3/2-naming-conventions/naming-conventions/#naming-conventions-for-plsql) of the Trivadis PL/SQL & SQL Coding Guidelines
15+
TrivadisPlsqlNaming | Checks [Naming Conventions](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.4/2-naming-conventions/naming-conventions/#naming-conventions-for-plsql) of the Trivadis PL/SQL & SQL Coding Guidelines
1616
GLP | Checks naming of global and local variables and parameters
1717
SQLInjection | Looks for SQL injection vulnerabilities, e.g. unasserted parameters in dynamic SQL
1818
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.3/4-language-usage/1-general/g-1050/).
19+
OverrideTrivadisGuidelines | Extends TrivadisGuidelines3 and overrides check for [G-1050](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.4/4-language-usage/1-general/g-1050/).
2020
TrivadisGuidelines3Plus | Combines the validators TrivadisPlsqlNaming, SQLInjection and OverrideTrivadisGuidelines.
2121

2222
### TrivadisPlsqlNaming
2323

24-
This validator implements 15 guidelines to cover the chapter [2.2 Naming Conventions](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.3/2-naming-conventions/naming-conventions/#naming-conventions-for-plsql) of the Trivadis PL/SQL & SQL Coding Guidelines.
24+
This validator implements 15 guidelines to cover the chapter [2.2 Naming Conventions](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.4/2-naming-conventions/naming-conventions/#naming-conventions-for-plsql) of the Trivadis PL/SQL & SQL Coding Guidelines.
2525

2626
Guideline | Message
2727
--------- | -----------
@@ -128,7 +128,7 @@ The following guideline is overriden:
128128

129129
Guideline | Message
130130
--------- | -----------
131-
[G-1050](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.3/4-language-usage/1-general/g-1050/) | Avoid using literals in your code.
131+
[G-1050](https://trivadis.github.io/plsql-and-sql-coding-guidelines/v4.4/4-language-usage/1-general/g-1050/) | Avoid using literals in your code.
132132

133133
Literals as part of a [Logger](https://github.com/OraOpenSource/Logger) package call are not reported (see also [issue 8](https://github.com/Trivadis/plsql-cop-validators/issues/8)).
134134

install_tvdcc_libs.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
# set the directory where SQLcl libraries are stored
3+
# set the directory where libraries of db* CODECOP CLI are stored
44
if [[ "$1" = "" ]]; then
55
TVDCC_DIR="$HOME/tvdcc"
66
else
@@ -15,8 +15,8 @@ if ! test -f "${TVDCC_DIR}/tvdcc.jar"; then
1515
fi
1616

1717
# define versions according usage in pom.xml
18-
TVDCC_VERSION="4.5.1-SNAPSHOT"
19-
PLSQL_VERSION="4.2.3-SNAPSHOT"
18+
TVDCC_VERSION="5.0.0-SNAPSHOT"
19+
PLSQL_VERSION="5.0.0-SNAPSHOT"
2020

2121
# install JAR files into local Maven repository, these libs are not available in public Maven repositories
2222
mvn install:install-file -Dfile=$TVDCC_DIR/tvdcc.jar -DgeneratePom=true \

pom.xml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<!-- The Basics -->
66
<groupId>trivadis.tvdcc</groupId>
77
<artifactId>sonar-plsql-cop-custom-validators-plugin</artifactId>
8-
<version>4.5.1-SNAPSHOT</version>
8+
<version>5.0.0-SNAPSHOT</version>
99
<packaging>sonar-plugin</packaging>
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
<jdk.version>8</jdk.version>
1313
<jdk.test.version>17</jdk.test.version>
14-
<xtext.version>2.27.0</xtext.version>
14+
<xtext.version>2.28.0</xtext.version> <!-- latest version that runs with JDK8 -->
1515
<skip.genmodel>false</skip.genmodel>
1616
<skipTests>false</skipTests>
1717
</properties>
@@ -25,8 +25,8 @@
2525
<plugins>
2626
<plugin>
2727
<groupId>org.apache.maven.plugins</groupId>
28-
<version>3.10.1</version>
2928
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.12.1</version>
3030
<configuration>
3131
<!-- different Java version for main and test -->
3232
<!-- works with Maven builder from IDE or command line -->
@@ -36,6 +36,18 @@
3636
</plugin>
3737
</plugins>
3838
</build>
39+
<repositories>
40+
<repository>
41+
<id>plsqlcop</id>
42+
<url>https://pkgs.dev.azure.com/tvdvsts/2001.5038513/_packaging/plsqlcop/maven/v1</url>
43+
<releases>
44+
<enabled>true</enabled>
45+
</releases>
46+
<snapshots>
47+
<enabled>true</enabled>
48+
</snapshots>
49+
</repository>
50+
</repositories>
3951
</profile>
4052
<profile>
4153
<id>idea</id>
@@ -49,8 +61,8 @@
4961
<plugins>
5062
<plugin>
5163
<groupId>org.apache.maven.plugins</groupId>
52-
<version>3.10.1</version>
5364
<artifactId>maven-compiler-plugin</artifactId>
65+
<version>3.12.1</version>
5466
<configuration>
5567
<!-- IDEA requires same Java version for main and test -->
5668
<!-- see https://youtrack.jetbrains.com/issue/IDEA-85478 -->
@@ -60,6 +72,18 @@
6072
</plugin>
6173
</plugins>
6274
</build>
75+
<repositories>
76+
<repository>
77+
<id>plsqlcop</id>
78+
<url>https://pkgs.dev.azure.com/tvdvsts/2001.5038513/_packaging/plsqlcop/maven/v1</url>
79+
<releases>
80+
<enabled>true</enabled>
81+
</releases>
82+
<snapshots>
83+
<enabled>true</enabled>
84+
</snapshots>
85+
</repository>
86+
</repositories>
6387
</profile>
6488
<profile>
6589
<activation>
@@ -107,14 +131,14 @@
107131
<!-- contains TrivadisGuidelines3 -->
108132
<groupId>trivadis.tvdcc</groupId>
109133
<artifactId>tvdcc</artifactId>
110-
<version>4.5.1-SNAPSHOT</version>
134+
<version>5.0.0</version>
111135
<scope>provided</scope>
112136
</dependency>
113137
<dependency>
114138
<!-- contains PLSQLValidator -->
115139
<groupId>trivadis.oracle</groupId>
116140
<artifactId>plsql</artifactId>
117-
<version>4.2.3-SNAPSHOT</version>
141+
<version>5.0.0</version>
118142
<scope>provided</scope>
119143
</dependency>
120144
<dependency>
@@ -147,7 +171,7 @@
147171
<dependency>
148172
<groupId>junit</groupId>
149173
<artifactId>junit</artifactId>
150-
<version>4.13.1</version>
174+
<version>4.13.2</version>
151175
<scope>test</scope>
152176
</dependency>
153177
</dependencies>
@@ -167,7 +191,7 @@
167191
<plugin>
168192
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
169193
<artifactId>sonar-packaging-maven-plugin</artifactId>
170-
<version>1.18.0.372</version>
194+
<version>1.21.0.505</version> <!-- last version before breaking changes -->
171195
<extensions>true</extensions>
172196
<configuration>
173197
<pluginKey>plsql-cop-custom-validators</pluginKey>
@@ -177,7 +201,7 @@
177201
</plugin>
178202
<plugin>
179203
<groupId>org.apache.maven.plugins</groupId>
180-
<version>3.10.1</version>
204+
<version>3.12.1</version>
181205
<artifactId>maven-compiler-plugin</artifactId>
182206
<configuration>
183207
<source>${jdk.version}</source>
@@ -229,7 +253,7 @@
229253
<plugin>
230254
<groupId>org.apache.maven.plugins</groupId>
231255
<artifactId>maven-surefire-plugin</artifactId>
232-
<version>2.22.2</version>
256+
<version>3.2.5</version>
233257
<executions>
234258
<execution>
235259
<id>default-test</id>

src/main/java/com/trivadis/tvdcc/generators/GLPGenmodel.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@
1616

1717
package com.trivadis.tvdcc.generators;
1818

19+
import java.io.IOException;
20+
1921
import com.trivadis.oracle.plsql.validation.PLSQLValidatorPreferences;
2022
import com.trivadis.tvdcc.genmodel.GenRulesXml;
2123
import com.trivadis.tvdcc.genmodel.GenSqaleXml;
2224
import com.trivadis.tvdcc.validators.GLP;
2325

2426
public class GLPGenmodel {
2527

26-
public static void genPlsqlcopModelXml() {
28+
public static void genPlsqlcopModelXml() throws IOException {
2729
GenSqaleXml gen = new GenSqaleXml();
28-
gen.generate("./src/main/resources/GLP");
30+
gen.generate(GenUtil.getPath("src/main/resources/GLP"));
2931
}
3032

31-
public static void genRulesXml() {
33+
public static void genRulesXml() throws IOException {
3234
GenRulesXml gen = new GenRulesXml();
33-
String targetDir = "./src/main/resources/GLP";
34-
gen.generate(targetDir, "./src/main/resources/GLP/sample");
35+
String targetDir = GenUtil.getPath("src/main/resources/GLP");
36+
gen.generate(targetDir, GenUtil.getPath("src/main/resources/GLP/sample"));
3537
}
3638

37-
public static void main(String[] args) {
39+
public static void main(String[] args) throws IOException {
3840
PLSQLValidatorPreferences.INSTANCE.setValidatorClass(GLP.class);
3941
genPlsqlcopModelXml();
4042
genRulesXml();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 Philipp Salvisberg <[email protected]>
3+
*
4+
* Licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0
5+
* Unported License (the "License"); you may not use this file except
6+
* in compliance with the License. You may obtain a copy of the License at
7+
*
8+
* https://creativecommons.org/licenses/by-nc-nd/3.0/
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.trivadis.tvdcc.generators;
18+
19+
import java.io.IOException;
20+
import java.nio.file.FileVisitOption;
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
import java.util.List;
25+
import java.util.stream.Collectors;
26+
27+
28+
public class GenUtil {
29+
public static String getPath(String dirName) throws IOException {
30+
String ret = null;
31+
List<Path> dirs = Files.walk(Paths.get(""), FileVisitOption.FOLLOW_LINKS).filter(f -> f.toFile().getAbsolutePath().contains(dirName.substring(2)))
32+
.collect(Collectors.toList());
33+
if (dirs.size() > 0) {
34+
ret = dirs.get(0).toFile().getAbsolutePath();
35+
}
36+
return ret;
37+
}
38+
}

src/main/java/com/trivadis/tvdcc/generators/TrivadisGuidelines3PlusGenmodel.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
public class TrivadisGuidelines3PlusGenmodel {
3838

39-
public static void genPlsqlcopModelXml() {
39+
public static void genPlsqlcopModelXml() throws IOException {
4040
GenSqaleXml gen = new GenSqaleXml();
41-
gen.generate("./src/main/resources/TrivadisGuidelines3Plus");
41+
gen.generate(GenUtil.getPath("src/main/resources/TrivadisGuidelines3Plus"));
4242
}
4343

4444
public static void copy(String sourceDir, String targetDir) throws IOException {
@@ -57,25 +57,27 @@ public static void copy(String sourceDir, String targetDir) throws IOException {
5757
public static void copyGuidelinesFromJar(String targetDir) throws IOException, URISyntaxException {
5858
File tvdccJarFile = new File(
5959
TrivadisGuidelines3.class.getProtectionDomain().getCodeSource().getLocation().toURI());
60-
JarFile jarFile = new JarFile(tvdccJarFile);
61-
Enumeration<JarEntry> entries = jarFile.entries();
62-
while (entries.hasMoreElements()) {
63-
JarEntry entry = entries.nextElement();
64-
if (!entry.isDirectory() && entry.getName().startsWith("guidelines/")) {
65-
InputStream entryInputStream = jarFile.getInputStream(entry);
66-
Path targetFile = Paths.get(targetDir, entry.getName().substring(10));
67-
Files.copy(entryInputStream, targetFile, StandardCopyOption.REPLACE_EXISTING);
60+
if (tvdccJarFile.getName().endsWith(".jar")) {
61+
JarFile jarFile = new JarFile(tvdccJarFile);
62+
Enumeration<JarEntry> entries = jarFile.entries();
63+
while (entries.hasMoreElements()) {
64+
JarEntry entry = entries.nextElement();
65+
if (!entry.isDirectory() && entry.getName().startsWith("guidelines/")) {
66+
InputStream entryInputStream = jarFile.getInputStream(entry);
67+
Path targetFile = Paths.get(targetDir, entry.getName().substring(10));
68+
Files.copy(entryInputStream, targetFile, StandardCopyOption.REPLACE_EXISTING);
69+
}
6870
}
71+
jarFile.close();
6972
}
70-
jarFile.close();
7173
}
7274

7375
public static void genRulesXml() throws URISyntaxException, IOException {
7476
GenRulesXml gen = new GenRulesXml();
7577
String tempDir = Files.createTempDirectory("genmodel_").toString();
7678
copyGuidelinesFromJar(tempDir);
77-
copy("./src/main/resources/TrivadisGuidelines3Plus/sample", tempDir);
78-
gen.generate("./src/main/resources/TrivadisGuidelines3Plus", tempDir.toString());
79+
copy(GenUtil.getPath("src/main/resources/TrivadisGuidelines3Plus/sample"), tempDir);
80+
gen.generate(GenUtil.getPath("src/main/resources/TrivadisGuidelines3Plus"), tempDir.toString());
7981
}
8082

8183
public static void main(String[] args) throws URISyntaxException, IOException {

src/main/resources/TrivadisGuidelines3Plus/genmodel/plsqlcop-model.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@
25922592
<txt>mn</txt>
25932593
</prop>
25942594
</chc>
2595-
<!-- Always specify column names instead of positional references in GROUP BY clauses. -->
2595+
<!-- Always specify column names/aliases instead of positional references in GROUP BY clauses. -->
25962596
<chc>
25972597
<rule-repo>trivadis</rule-repo>
25982598
<rule-key>G-3182</rule-key>
@@ -2668,6 +2668,25 @@
26682668
<txt>mn</txt>
26692669
</prop>
26702670
</chc>
2671+
<!-- Avoid autonomous transactions. -->
2672+
<chc>
2673+
<rule-repo>trivadis</rule-repo>
2674+
<rule-key>G-3330</rule-key>
2675+
<prop>
2676+
<key>remediationFunction</key>
2677+
<txt>CONSTANT_ISSUE</txt>
2678+
</prop>
2679+
<prop>
2680+
<key>remediationFactor</key>
2681+
<val>0.0</val>
2682+
<txt>mn</txt>
2683+
</prop>
2684+
<prop>
2685+
<key>offset</key>
2686+
<val>60.0</val>
2687+
<txt>mn</txt>
2688+
</prop>
2689+
</chc>
26712690
<!-- Avoid using %NOTFOUND directly after the FETCH when working with BULK OPERATIONS and LIMIT clause. -->
26722691
<chc>
26732692
<rule-repo>trivadis</rule-repo>
@@ -2706,6 +2725,25 @@
27062725
<txt>mn</txt>
27072726
</prop>
27082727
</chc>
2728+
<!-- Never use a FOR LOOP for a query that should return not more than one row. (not implemented) -->
2729+
<chc>
2730+
<rule-repo>trivadis</rule-repo>
2731+
<rule-key>G-4387</rule-key>
2732+
<prop>
2733+
<key>remediationFunction</key>
2734+
<txt>CONSTANT_ISSUE</txt>
2735+
</prop>
2736+
<prop>
2737+
<key>remediationFactor</key>
2738+
<val>0.0</val>
2739+
<txt>mn</txt>
2740+
</prop>
2741+
<prop>
2742+
<key>offset</key>
2743+
<val>5.0</val>
2744+
<txt>mn</txt>
2745+
</prop>
2746+
</chc>
27092747
<!-- Always use parameters or pull in definitions rather than referencing external variables in a local program unit. -->
27102748
<chc>
27112749
<rule-repo>trivadis</rule-repo>

0 commit comments

Comments
 (0)