Skip to content

Commit c86b496

Browse files
Merge pull request #58 from Trivadis/feature/issue-57-support-codecop-4.4
Support db* CODECOP 4.4
2 parents 2905819 + bd3f92f commit c86b496

File tree

10 files changed

+1864
-1131
lines changed

10 files changed

+1864
-1131
lines changed

azure-pipelines.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,29 @@ steps:
4040
packageType: 'maven'
4141
feed: '18837db9-b003-4158-aea6-2cbe5db0f9f0/2243676f-5a13-4f9a-842a-0d4b65c80104'
4242
definition: 'trivadis.tvdcc:tvdcc'
43-
version: '4.3.0'
43+
version: '4.4.0-snapshot' # lowercase is necessary
4444
files: '*.jar'
4545
downloadPath: '$(Pipeline.Workspace)'
4646

4747
- task: Bash@3
4848
inputs:
4949
targetType: 'inline'
50-
script: for f in $(Pipeline.Workspace)/tvdcc-4.3.0*.jar; do echo $f; mv $f $(Pipeline.Workspace)/tvdcc.jar; done
50+
script: for f in $(Pipeline.Workspace)/tvdcc-4.4.0*.jar; do echo $f; mv $f $(Pipeline.Workspace)/tvdcc.jar; done
5151

5252
- task: DownloadPackage@1
5353
inputs:
5454
packageType: 'maven'
5555
feed: '18837db9-b003-4158-aea6-2cbe5db0f9f0/2243676f-5a13-4f9a-842a-0d4b65c80104'
5656
definition: 'trivadis.oracle:plsql'
57-
version: '4.2.0'
57+
version: '4.2.1-snapshot' # lowercase is necessary
5858
files: '*.jar'
5959
downloadPath: '$(Pipeline.Workspace)/lib'
6060

61+
- task: Bash@3
62+
inputs:
63+
targetType: 'inline'
64+
script: for f in $(Pipeline.Workspace)/lib/plsql-4.2.1*.jar; do echo $f; cp $f $(Pipeline.Workspace)/lib/plsql-4.2.1-SNAPSHOT.jar; done
65+
6166
- task: Maven@3
6267
displayName: 'Maven com.trivadis.tvdcc'
6368
inputs:

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<!-- The Basics -->
66
<groupId>trivadis.tvdcc</groupId>
77
<artifactId>sonar-plsql-cop-custom-validators-plugin</artifactId>
8-
<version>4.3.2-SNAPSHOT</version>
8+
<version>4.4.0-SNAPSHOT</version>
99
<packaging>sonar-plugin</packaging>
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -33,17 +33,17 @@
3333
<!-- contains TrivadisGuidelines3 -->
3434
<groupId>trivadis.tvdcc</groupId>
3535
<artifactId>tvdcc</artifactId>
36-
<version>4.3.1</version>
36+
<version>4.4.0-SNAPSHOT</version>
3737
<scope>system</scope>
3838
<systemPath>${tvdcc.basedir}/tvdcc.jar</systemPath>
3939
</dependency>
4040
<dependency>
4141
<!-- contains PLSQLValidator -->
4242
<groupId>trivadis.oracle</groupId>
4343
<artifactId>plsql</artifactId>
44-
<version>4.2.0</version>
44+
<version>4.2.1-SNAPSHOT</version>
4545
<scope>system</scope>
46-
<systemPath>${tvdcc.basedir}/lib/plsql-4.2.0.jar</systemPath>
46+
<systemPath>${tvdcc.basedir}/lib/plsql-4.2.1-SNAPSHOT.jar</systemPath>
4747
</dependency>
4848
<dependency>
4949
<!-- required to build SonarQube plugin for minimal target version -->
@@ -359,8 +359,8 @@
359359
</license>
360360
</licenses>
361361
<organization>
362-
<name>Trivadis AG</name>
363-
<url>https://www.trivadis.com/</url>
362+
<name>Trivadis - Part of Accenture</name>
363+
<url>https://www.accenture.com/</url>
364364
</organization>
365365
<developers>
366366
<developer>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright 2019 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+
package com.trivadis.tvdcc.validators;
17+
18+
import java.util.ArrayList;
19+
import java.util.HashMap;
20+
import java.util.List;
21+
22+
import org.eclipse.emf.ecore.EObject;
23+
import org.eclipse.emf.ecore.EPackage;
24+
import org.eclipse.xtext.EcoreUtil2;
25+
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
26+
import org.eclipse.xtext.validation.Check;
27+
import org.eclipse.xtext.validation.EValidatorRegistrar;
28+
29+
import com.trivadis.oracle.plsql.plsql.BinaryCompoundExpressionLevel6;
30+
import com.trivadis.oracle.plsql.plsql.BinaryCompoundExpressionLevel7;
31+
import com.trivadis.oracle.plsql.plsql.CollectionTypeDefinition;
32+
import com.trivadis.oracle.plsql.plsql.ConstantDeclaration;
33+
import com.trivadis.oracle.plsql.plsql.PLSQLFile;
34+
import com.trivadis.oracle.plsql.plsql.SimpleExpressionNameValue;
35+
import com.trivadis.oracle.plsql.plsql.SimpleExpressionNumberValue;
36+
import com.trivadis.oracle.plsql.plsql.SimpleExpressionStringValue;
37+
import com.trivadis.oracle.plsql.plsql.UserDefinedType;
38+
import com.trivadis.oracle.plsql.validation.PLSQLCopValidator;
39+
40+
public class OverrideTrivadisGuidelines extends TrivadisGuidelines3 implements PLSQLCopValidator {
41+
42+
// must be overridden to avoid duplicate issues when used via ComposedChecks
43+
@Override
44+
public void register(EValidatorRegistrar registrar) {
45+
List<EPackage> ePackages = getEPackages();
46+
if (registrar.getRegistry().get(ePackages.get(0)) == null) {
47+
// standalone validator, default registration required
48+
super.register(registrar);
49+
}
50+
}
51+
52+
public boolean isConstantDeclaration(
53+
54+
final EObject obj) {
55+
ConstantDeclaration constantDeclaration = EcoreUtil2.getContainerOfType(obj, ConstantDeclaration.class);
56+
return (constantDeclaration != null);
57+
}
58+
59+
public boolean isLoggerCall(EObject obj) {
60+
if (obj == null) {
61+
return false;
62+
} else {
63+
BinaryCompoundExpressionLevel7 func = EcoreUtil2.getContainerOfType(obj, BinaryCompoundExpressionLevel7.class);
64+
if (func == null) {
65+
return false;
66+
} else {
67+
if (func.getLeft() instanceof SimpleExpressionNameValue) {
68+
if (func.eContainer() instanceof BinaryCompoundExpressionLevel6) {
69+
BinaryCompoundExpressionLevel6 pkg = (BinaryCompoundExpressionLevel6) func.eContainer();
70+
if (pkg.getBinaryOperator().equals(".")) {
71+
if (pkg.getLeft() instanceof SimpleExpressionNameValue) {
72+
SimpleExpressionNameValue pkgName = (SimpleExpressionNameValue) pkg.getLeft();
73+
if (pkgName.getValue().equalsIgnoreCase("logger")) {
74+
return true;
75+
}
76+
}
77+
}
78+
}
79+
}
80+
return isLoggerCall(func.eContainer());
81+
}
82+
}
83+
}
84+
85+
/*
86+
* Override G-1050: Avoid using literals in your code. (guidelines version 3.x)
87+
* Override G-05: Avoid using literals in your code. (guidelines version 2.x)
88+
* re-implement existing functionality while ignoring logger calls
89+
* "&& !isLoggerCall(obj)" is the only addition to the original code
90+
*/
91+
@Check
92+
@Override
93+
public void checkGuideline5(PLSQLFile file) {
94+
HashMap<String, Integer> map = new HashMap<>();
95+
int threshold = Integer.parseInt(System.getProperty(COP_1050_THRESHOLD, "2"));
96+
List<EObject> warnings = new ArrayList<>();
97+
List<SimpleExpressionNumberValue> numbers = EcoreUtil2.getAllContentsOfType(file, SimpleExpressionNumberValue.class);
98+
for (SimpleExpressionNumberValue literal : numbers) {
99+
ConstantDeclaration declartion = EcoreUtil2.getContainerOfType(literal, ConstantDeclaration.class);
100+
UserDefinedType udf = EcoreUtil2.getContainerOfType(literal, UserDefinedType.class);
101+
CollectionTypeDefinition collDef = EcoreUtil2.getContainerOfType(literal, CollectionTypeDefinition.class);
102+
if (declartion == null && udf == null && collDef == null && !literal.getValue().replace(".", "").equals("0")
103+
&& !literal.getValue().replace(".", "").equals("1")) {
104+
updateLiteralMap(literal, map, threshold);
105+
warnings.add(literal);
106+
}
107+
}
108+
List<SimpleExpressionStringValue> strings = EcoreUtil2.getAllContentsOfType(file, SimpleExpressionStringValue.class);
109+
for (SimpleExpressionStringValue literal : strings) {
110+
ConstantDeclaration declartion = EcoreUtil2.getContainerOfType(literal, ConstantDeclaration.class);
111+
if (declartion == null) {
112+
UserDefinedType udf = EcoreUtil2.getContainerOfType(literal, UserDefinedType.class);
113+
if (udf == null) {
114+
updateLiteralMap(literal, map, threshold);
115+
warnings.add(literal);
116+
}
117+
}
118+
}
119+
for (EObject obj : warnings) {
120+
if (!withinThreshold(obj, map, threshold) && !isLoggerCall(obj)) {
121+
warning(getGuidelineMsg(5), obj, null, getGuidelineId(5), serialize(NodeModelUtils.getNode(obj)));
122+
}
123+
}
124+
}
125+
}

src/main/java/com/trivadis/tvdcc/validators/OverrideTrivadisGuidelines.xtend

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
<txt>mn</txt>
179179
</prop>
180180
</chc>
181-
<!-- Syntax error. Please contact the author if the code compiles successfully in your environment. -->
181+
<!-- Syntax error. Please check the limitations and contact the author if the code can be compiled successfully in your environment. -->
182182
<chc>
183183
<rule-repo>trivadis</rule-repo>
184184
<rule-key>E-0002</rule-key>

src/main/resources/GLP/genmodel/rules.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<rule>
55
<key>G-0000</key>
66
<name><![CDATA[G-0000: Avoid using the NOSONAR marker.]]></name>
7+
<type>CODE_SMELL</type>
78
<internalKey>G-0000</internalKey>
89
<severity>INFO</severity>
910
<cardinality>SINGLE</cardinality>
@@ -15,6 +16,7 @@
1516
<rule>
1617
<key>G-9001</key>
1718
<name><![CDATA[G-9001: Always prefix global variables with 'g_'.]]></name>
19+
<type>CODE_SMELL</type>
1820
<internalKey>G-9001</internalKey>
1921
<severity>MAJOR</severity>
2022
<cardinality>SINGLE</cardinality>
@@ -39,6 +41,7 @@ end pkg;
3941
<rule>
4042
<key>G-9002</key>
4143
<name><![CDATA[G-9002: Always prefix local variables with 'l_'.]]></name>
44+
<type>CODE_SMELL</type>
4245
<internalKey>G-9002</internalKey>
4346
<severity>MAJOR</severity>
4447
<cardinality>SINGLE</cardinality>
@@ -67,6 +70,7 @@ end p;
6770
<rule>
6871
<key>G-9003</key>
6972
<name><![CDATA[G-9003: Always prefix parameters with 'p_'.]]></name>
73+
<type>CODE_SMELL</type>
7074
<internalKey>G-9003</internalKey>
7175
<severity>MAJOR</severity>
7276
<cardinality>SINGLE</cardinality>
@@ -93,6 +97,7 @@ end p;
9397
<rule>
9498
<key>E-0001</key>
9599
<name>E-0001: Timeout occurred (after n seconds) during load/parse/validation of resource.</name>
100+
<type>BUG</type>
96101
<internalKey>E-0001</internalKey>
97102
<severity>BLOCKER</severity>
98103
<cardinality>SINGLE</cardinality>
@@ -105,7 +110,8 @@ end p;
105110
</rule>
106111
<rule>
107112
<key>E-0002</key>
108-
<name>E-0002: Syntax error. Please contact the author if the code compiles successfully in your environment.</name>
113+
<name>E-0002: Syntax error. Please check the limitations and contact the author if the code can be compiled successfully in your environment.</name>
114+
<type>BUG</type>
109115
<internalKey>E-0002</internalKey>
110116
<severity>BLOCKER</severity>
111117
<cardinality>SINGLE</cardinality>
@@ -120,13 +126,14 @@ end p;
120126
<rule>
121127
<key>E-0003</key>
122128
<name>E-0003: License limit reached.</name>
129+
<type>BUG</type>
123130
<internalKey>E-0003</internalKey>
124131
<severity>BLOCKER</severity>
125132
<cardinality>SINGLE</cardinality>
126133
<status>READY</status>
127134
<description><![CDATA[
128135
<h2>Reason</h2>
129-
<p>A db* CODECOP license key defines limitations for the number of files, lines, commands and bytes to be processed. Please contact your Trivadis representative to obtain a less restrictive license.</p>
136+
<p>A db* CODECOP license key defines limitations for the validity date, the major version, the number of files, the number of lines, the number commands and the number of bytes to be processed. Please contact your sales representative to obtain a less restrictive license.</p>
130137
]]></description>
131138
<tag>error</tag>
132139
</rule>

0 commit comments

Comments
 (0)