Skip to content

Commit daac98d

Browse files
committed
Add error rules to the report analyse
1 parent ca20776 commit daac98d

File tree

4 files changed

+72
-12
lines changed

4 files changed

+72
-12
lines changed

src/main/java/fr/cnes/sonarqube/plugins/icode/report/AnalysisProject.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import fr.cnes.sonarqube.plugins.icode.measures.ReportFunctionRuleInterface;
7-
import fr.cnes.sonarqube.plugins.icode.measures.ReportInterface;
8-
import fr.cnes.sonarqube.plugins.icode.measures.ReportModuleRuleInterface;
9-
106
/**
117
*
128
* @author Cyrille FRANCOIS
@@ -176,10 +172,47 @@ public ReportFunctionRuleInterface[] getRatioCommentMeasureByFunction(){
176172
res = listOfRes.toArray(new ReportFunctionRuleInterface[listOfRes.size()]);
177173
return res;
178174
}
179-
180-
181175

176+
@Override
177+
public ErrorInterface[] getErrors() {
178+
ReportFunctionRuleInterface[] res=null;
179+
List<ReportFunctionRuleInterface> listOfRes = new ArrayList<ReportFunctionRuleInterface>();
180+
for (AnalysisRule analysisRule : listOfAnalysisRule) {
181+
if((!analysisRule.analysisRuleId.endsWith(AnalysisRule.RATIO_COMMENT)) &&
182+
(!analysisRule.analysisRuleId.endsWith(AnalysisRule.COMPLEXITY_SIMPLIFIED)) &&
183+
(!analysisRule.analysisRuleId.endsWith(AnalysisRule.LINE_OF_CODE)) &&
184+
(!analysisRule.analysisRuleId.endsWith(AnalysisRule.NESTING))){
185+
if(analysisRule.result.resultTypePlace.equals("method")){
186+
187+
// Check if the rule does not exist into ICodeRulesDefinition
188+
if(isUnexpectedRule(analysisRule)){
189+
190+
// Unexcepted rule analyse is save as a COM.DEFAULT rule issue...
191+
if(this.isF77()){
192+
analysisRule.analysisRuleId = AnalysisRule.F77+"COM.DEFAULT";
193+
}
194+
if(this.isF90()){
195+
analysisRule.analysisRuleId = AnalysisRule.F77+"COM.DEFAULT";
196+
}
197+
else{
198+
analysisRule.analysisRuleId = AnalysisRule.SHELL+"COM.DEFAULT";
199+
}
200+
}
201+
listOfRes.add(analysisRule);
202+
}
203+
}
204+
}
205+
res = listOfRes.toArray(new ReportFunctionRuleInterface[listOfRes.size()]);
206+
return (ErrorInterface[]) res;
207+
}
182208

209+
private boolean isUnexpectedRule(AnalysisRule analysisRule){
210+
boolean res=true;
211+
if(analysisRule.analysisRuleId.equals("COM.DATA.FloatCompare")){
212+
res=false;
213+
}
214+
return res;
215+
}
183216

184217
/* ReportInterface */
185218
}

src/main/java/fr/cnes/sonarqube/plugins/icode/report/AnalysisRule.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package fr.cnes.sonarqube.plugins.icode.report;
22

3-
import fr.cnes.sonarqube.plugins.icode.measures.ReportFunctionRuleInterface;
4-
53
public class AnalysisRule implements ReportFunctionRuleInterface{
64
static final String RESULT = "result";
75
static final String ANALYSIS_RULE_ID = "analysisRuleId";
86

97
public static final String F77 = "F77";
108
public static final String F90 = "F90";
9+
public static final String SHELL = "SHELL";
1110

1211
public static final String COMPLEXITY_SIMPLIFIED = "MET.ComplexitySimplified";
1312
public static final String NESTING = "MET.Nesting";
@@ -40,6 +39,36 @@ public String getLine() {
4039
// TODO Auto-generated method stub
4140
return result.resultLine;
4241
}
42+
43+
@Override
44+
public String getLoc() {
45+
// TODO Auto-generated method stub
46+
return "0";
47+
}
48+
49+
@Override
50+
public String getComplexity() {
51+
// TODO Auto-generated method stub
52+
return "0";
53+
}
54+
55+
@Override
56+
public String getLineDescriptor() {
57+
// TODO Auto-generated method stub
58+
return "";
59+
}
60+
61+
@Override
62+
public String getRuleKey() {
63+
// TODO Auto-generated method stub
64+
return analysisRuleId;
65+
}
66+
67+
@Override
68+
public String getDescription() {
69+
// TODO Auto-generated method stub
70+
return "";
71+
}
4372

4473

4574
}

src/main/java/fr/cnes/sonarqube/plugins/icode/report/ReportInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fr.cnes.sonarqube.plugins.icode.measures;
1+
package fr.cnes.sonarqube.plugins.icode.report;
22

33
/**
44
* Expected report services for a ICode report
@@ -23,5 +23,5 @@ public interface ReportInterface {
2323
ReportModuleRuleInterface getModuleRatioCommentMeasure();
2424
ReportFunctionRuleInterface[] getRatioCommentMeasureByFunction();
2525

26-
26+
ErrorInterface[] getErrors();
2727
}

src/main/java/fr/cnes/sonarqube/plugins/icode/report/XmlReportReader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.xml.sax.SAXException;
1515
import org.xml.sax.helpers.DefaultHandler;
1616

17-
import fr.cnes.sonarqube.plugins.icode.measures.ReportInterface;
18-
1917
/**
2018
* SAX parser for XML ICode report input file
2119
*

0 commit comments

Comments
 (0)