Skip to content

Commit 505d3de

Browse files
committed
Search rules into repository. Add COM.DEFAULT for unknown rules
1 parent bf45a5d commit 505d3de

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import org.sonar.api.utils.log.Logger;
7+
import org.sonar.api.utils.log.Loggers;
8+
9+
import fr.cnes.sonarqube.plugins.icode.measures.ICodeSensor;
10+
import fr.cnes.sonarqube.plugins.icode.rules.ICodeRulesDefinition;
11+
612
/**
713
*
814
* @author Cyrille FRANCOIS
915
*
1016
*/
1117
public class AnalysisProject implements ReportInterface{
1218

19+
private static final Logger LOGGER = Loggers.get(AnalysisProject.class);
20+
1321
static final String ANALYSIS_PROJECT_NAME = "analysisProjectName";
1422
static final String ANALYSIS_PROJECT_VERSION = "analysisProjectVersion";
1523

@@ -188,17 +196,10 @@ public ErrorInterface[] getErrors() {
188196
if(isUnexpectedRule(analysisRule)){
189197

190198
// 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-
}
199+
analysisRule.analysisRuleId = "COM.DEFAULT";
200200
}
201201
listOfRes.add(analysisRule);
202+
LOGGER.debug("AnalysisRule: "+analysisRule.toString());
202203
}
203204
}
204205
}
@@ -208,9 +209,12 @@ public ErrorInterface[] getErrors() {
208209

209210
private boolean isUnexpectedRule(AnalysisRule analysisRule){
210211
boolean res=true;
211-
if(analysisRule.analysisRuleId.equals("COM.DATA.FloatCompare")){
212-
res=false;
213-
}
212+
213+
// if(analysisRule.analysisRuleId.equals("COM.DATA.FloatCompare")){
214+
// res=false;
215+
// }
216+
res = !ICodeRulesDefinition.existRule(analysisRule.analysisRuleId);
217+
214218
return res;
215219
}
216220

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String getComplexity() {
5555
@Override
5656
public String getLineDescriptor() {
5757
// TODO Auto-generated method stub
58-
return "";
58+
return result.resultLine;
5959
}
6060

6161
@Override
@@ -66,8 +66,11 @@ public String getRuleKey() {
6666

6767
@Override
6868
public String getDescription() {
69-
// TODO Auto-generated method stub
70-
return "";
69+
String res="";
70+
if(result != null && result.resultValue != null){
71+
res = result.resultValue;
72+
}
73+
return res;
7174
}
7275

7376

src/main/java/fr/cnes/sonarqube/plugins/icode/rules/ICodeRulesDefinition.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
import java.io.InputStream;
2323
import java.nio.charset.StandardCharsets;
24+
import java.util.ArrayList;
25+
import java.util.Collection;
26+
import java.util.List;
2427

2528
import org.sonar.api.server.rule.RulesDefinition;
2629
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
30+
import org.sonar.api.server.rule.RulesDefinition.NewRule;
2731

2832
import fr.cnes.sonarqube.plugins.icode.languages.ICodeLanguage;
2933

@@ -43,6 +47,7 @@ public final class ICodeRulesDefinition implements RulesDefinition {
4347
protected static final String REPO_NAME = ICodeLanguage.NAME;
4448

4549
private static NewRepository repository;
50+
private static List<String> allRuleIds = new ArrayList<String>();
4651

4752
protected String rulesDefinitionFilePath() {
4853
return PATH_TO_RULES_XML;
@@ -57,8 +62,12 @@ private void defineRulesForLanguage(Context context, String repositoryKey, Strin
5762
RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader();
5863
rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name());
5964
}
60-
6165
repository.done();
66+
Collection<NewRule> col = repository.rules();
67+
allRuleIds = new ArrayList<String>();
68+
for (NewRule newRule : col) {
69+
allRuleIds.add(newRule.key());
70+
}
6271
}
6372

6473
@Override
@@ -69,4 +78,8 @@ public void define(Context context) {
6978
public static String getRepositoryKeyForLanguage() {
7079
return ICodeLanguage.KEY + "-" + KEY;
7180
}
81+
82+
public static boolean existRule(String analysisRuleId){
83+
return allRuleIds.contains(analysisRuleId);
84+
}
7285
}

0 commit comments

Comments
 (0)