Skip to content

Commit e53e97a

Browse files
committed
Merge dev into dev-2.0
2 parents 64bc952 + 2fd1814 commit e53e97a

File tree

17 files changed

+3027
-274
lines changed

17 files changed

+3027
-274
lines changed

sonar-project.properties

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

src/main/java/fr/cnes/sonar/plugins/icode/check/ICodeSensor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static void saveIssue(final SensorContext sensorContext, final CheckResult resul
268268
final String repositoryKey = ICodeRulesDefinition.getRepositoryKeyForLanguage(file.language());
269269
final RuleKey ruleKey = RuleKey.of(repositoryKey, result.getName());
270270
final NewIssueLocation location = issue.newLocation();
271-
final TextRange textRange = file.selectLine(result.getLine());
271+
final TextRange textRange = file.selectLine(result.getLine()>0?result.getLine():1);
272272
location.on(file);
273273
location.at(textRange);
274274
location.message(result.getMessage());
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package fr.cnes.sonar.plugins.icode.converter;
2+
3+
import com.thoughtworks.xstream.converters.ConverterLookup;
4+
import com.thoughtworks.xstream.converters.UnmarshallingContext;
5+
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;
6+
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
7+
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
8+
import com.thoughtworks.xstream.mapper.Mapper;
9+
import fr.cnes.sonar.plugins.icode.model.AnalysisRule;
10+
import fr.cnes.sonar.plugins.icode.model.Result;
11+
12+
public class AnalysisConverter extends ToAttributedValueConverter {
13+
14+
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup) {
15+
super(type, mapper, reflectionProvider, lookup);
16+
}
17+
18+
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup, String valueFieldName) {
19+
super(type, mapper, reflectionProvider, lookup, valueFieldName);
20+
}
21+
22+
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup, String valueFieldName, Class valueDefinedIn) {
23+
super(type, mapper, reflectionProvider, lookup, valueFieldName, valueDefinedIn);
24+
}
25+
26+
@Override
27+
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) {
28+
Object r = super.unmarshal(reader, unmarshallingContext);
29+
if (r.getClass() == AnalysisRule.class) {
30+
Result result = new Result();
31+
reader.moveDown();
32+
result.setFileName(reader.getAttribute("fileName"));
33+
result.setResultLine(reader.getAttribute("resultLine"));
34+
result.setResultTypePlace(reader.getAttribute("resultTypePlace"));
35+
result.setResultValue(reader.getAttribute("resultValue"));
36+
if(reader.hasMoreChildren()) {
37+
reader.moveDown();
38+
result.setResultMessage(reader.getValue());
39+
reader.moveUp();
40+
}
41+
reader.moveUp();
42+
((AnalysisRule) r).setResult(result);
43+
}
44+
return r;
45+
}
46+
}

src/main/java/fr/cnes/sonar/plugins/icode/languages/ICodeQualityProfiles.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.sonar.api.utils.log.Logger;
2525
import org.sonar.api.utils.log.Loggers;
2626

27-
import javax.xml.bind.JAXBException;
2827
import java.io.InputStream;
2928

3029
/**
@@ -69,10 +68,10 @@ private void createBuiltInProfile(final Context context, final String language,
6968

7069
// Activate all i-Code CNES rules.
7170
for(final Rule rule : rules.getRules()) {
72-
defaultProfile.activateRule(repositoryKey, rule.key);
73-
LOGGER.info(String.format("Rule %s added to repository %s.", rule.key, repositoryKey));
71+
defaultProfile.activateRule(repositoryKey, rule.getKey());
72+
LOGGER.debug(String.format("Rule %s added to repository %s.", rule.getKey(), repositoryKey));
7473
}
75-
LOGGER.info(String.format("%s rules are activated.", defaultProfile.activeRules().size()));
74+
LOGGER.debug(String.format("%s rules are activated.", defaultProfile.activeRules().size()));
7675

7776
// Save the default profile.
7877
defaultProfile.setDefault(true);

src/main/java/fr/cnes/sonar/plugins/icode/measures/ICodeMetricsProcessor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public static void saveMeasure(final SensorContext context, final Map<String, In
7171
// Create a new measure from the scan context.
7272
final NewMeasure<Integer> newMeasure = context.newMeasure();
7373
// i-Code rule id.
74-
final String metricKey = rule.analysisRuleId;
74+
final String metricKey = rule.getAnalysisRuleId();
7575
// Determine if a measure is relative to a file or a method.
76-
final String metricScope = rule.result.resultTypePlace;
76+
final String metricScope = rule.getResult().getResultTypePlace();
7777
// Component concerned by the measure.
78-
final String metricComponent = rule.result.fileName;
78+
final String metricComponent = rule.getResult().getFileName();
7979
// Component concerned by the measure.
80-
final String measureValue = rule.result.resultValue;
80+
final String measureValue = rule.getResult().getResultValue();
8181

8282
// Is true if the metric must be interpreted by the plugin.
8383
boolean isCalculated = false;
@@ -140,8 +140,8 @@ public static void saveExtraMeasures(final SensorContext context, final Map<Stri
140140

141141
// Collect all measures on methods into specific list
142142
for(final AnalysisRule rule : project.getAnalysisRules()) {
143-
final String type = rule.result.resultTypePlace;
144-
final String id = rule.analysisRuleId;
143+
final String type = rule.getResult().getResultTypePlace();
144+
final String id = rule.getAnalysisRuleId();
145145
if(id.contains(COMMON_METRICS_KEY_PART) && type.equals("method")) {
146146
final List<AnalysisRule> sub = measures.getOrDefault(id, new ArrayList<>());
147147
sub.add(rule);
@@ -214,7 +214,7 @@ private static void computeFunctions(final SensorContext context, final Map<Stri
214214

215215
// Compute number of functions by file.
216216
for(final AnalysisRule measure : rawMeasures) {
217-
final String file = measure.result.fileName;
217+
final String file = measure.getResult().getFileName();
218218
Integer sum = functions.getOrDefault(file, 0) + 1;
219219
functions.put(file, sum);
220220
}
@@ -245,8 +245,8 @@ private static void computeComplexity(final SensorContext context, final Map<Str
245245

246246
// Compute complexity sum value by file.
247247
for(final AnalysisRule measure : rawMeasures) {
248-
final String file = measure.result.fileName;
249-
final Integer value = Double.valueOf((measure.result.resultValue)).intValue();
248+
final String file = measure.getResult().getFileName();
249+
final Integer value = Double.valueOf((measure.getResult().getResultValue())).intValue();
250250
Integer sum = complexity.getOrDefault(file, 0);
251251
sum += value;
252252
complexity.put(file, sum);
@@ -278,8 +278,8 @@ private static void computeNesting(final SensorContext context, final Map<String
278278

279279
// compute max nesting value by file
280280
for(final AnalysisRule measure : rawMeasures) {
281-
final String file = measure.result.fileName;
282-
final Integer value = Double.valueOf((measure.result.resultValue)).intValue();
281+
final String file = measure.getResult().getFileName();
282+
final Integer value = Double.valueOf((measure.getResult().getResultValue())).intValue();
283283
Integer max = nesting.getOrDefault(file, 0);
284284
max = Math.max(max,value);
285285
nesting.put(file, max);

src/main/java/fr/cnes/sonar/plugins/icode/model/AnalysisFile.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,33 @@
1616
*/
1717
package fr.cnes.sonar.plugins.icode.model;
1818

19-
import javax.xml.bind.annotation.XmlAttribute;
19+
20+
import com.thoughtworks.xstream.annotations.XStreamConverter;
21+
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;
2022

2123
/**
2224
* Class used to unmarshal i-Code xml file.
2325
*
2426
* It contains an analyzed file.
2527
*/
28+
@XStreamConverter(value = ToAttributedValueConverter.class)
2629
public class AnalysisFile {
27-
@XmlAttribute
28-
public String language;
29-
@XmlAttribute
30-
public String fileName;
30+
private String language;
31+
private String fileName;
32+
33+
public String getLanguage() {
34+
return language;
35+
}
36+
37+
public void setLanguage(String language) {
38+
this.language = language;
39+
}
40+
41+
public String getFileName() {
42+
return fileName;
43+
}
44+
45+
public void setFileName(String fileName) {
46+
this.fileName = fileName;
47+
}
3148
}

src/main/java/fr/cnes/sonar/plugins/icode/model/AnalysisInformations.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616
*/
1717
package fr.cnes.sonar.plugins.icode.model;
1818

19-
import javax.xml.bind.annotation.XmlAttribute;
19+
20+
import com.thoughtworks.xstream.annotations.XStreamConverter;
21+
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;
2022

2123
/**
2224
* Class used to unmarshal i-Code xml file.
2325
*
2426
* It contains meta data about the i-Code analysis.
2527
*/
28+
@XStreamConverter(ToAttributedValueConverter.class)
2629
public class AnalysisInformations {
27-
@XmlAttribute
28-
public String analysisConfigurationId;
29-
@XmlAttribute
30-
public String analysisDate;
31-
@XmlAttribute
32-
public String author;
30+
private String author;
31+
32+
public String getAuthor() {
33+
return author;
34+
}
35+
36+
public void setAuthor(String author) {
37+
this.author = author;
38+
}
3339
}

src/main/java/fr/cnes/sonar/plugins/icode/model/AnalysisProject.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
package fr.cnes.sonar.plugins.icode.model;
1818

19-
import javax.xml.bind.annotation.XmlAttribute;
20-
import javax.xml.bind.annotation.XmlElement;
21-
import javax.xml.bind.annotation.XmlRootElement;
19+
import com.thoughtworks.xstream.annotations.XStreamAlias;
20+
import com.thoughtworks.xstream.annotations.XStreamImplicit;
21+
import com.thoughtworks.xstream.annotations.XStreamInclude;
22+
2223
import java.util.ArrayList;
2324
import java.util.Arrays;
2425
import java.util.List;
@@ -28,18 +29,14 @@
2829
*
2930
* It contains meta data about the analyzed project.
3031
*/
31-
@XmlRootElement
32+
@XStreamAlias("analysisProject")
33+
@XStreamInclude({AnalysisFile.class, AnalysisRule.class, AnalysisInformations.class})
3234
public class AnalysisProject {
33-
@XmlAttribute
34-
public String analysisProjectName;
35-
@XmlAttribute
36-
public String analysisProjectVersion;
37-
@XmlElement
38-
public AnalysisInformations analysisInformations;
39-
@XmlElement
40-
public AnalysisFile[] analysisFile;
41-
@XmlElement
42-
public AnalysisRule[] analysisRule;
35+
private AnalysisInformations analysisInformations;
36+
@XStreamImplicit(itemFieldName = "analysisFile")
37+
private List<AnalysisFile> analysisFile;
38+
@XStreamImplicit(itemFieldName = "analysisRule")
39+
private List<AnalysisRule> analysisRule;
4340

4441
/**
4542
* Getter for accessing analysis rules (issues).
@@ -48,8 +45,8 @@ public class AnalysisProject {
4845
public List<AnalysisRule> getAnalysisRules() {
4946
// Retrieve issues (called rules)
5047
List<AnalysisRule> rules;
51-
if(analysisRule!=null) {
52-
rules = Arrays.asList(analysisRule);
48+
if(analysisRule !=null) {
49+
rules = this.analysisRule;
5350
} else {
5451
rules = new ArrayList<>();
5552
}
@@ -63,11 +60,28 @@ public List<AnalysisRule> getAnalysisRules() {
6360
public List<AnalysisFile> getAnalysisFiles() {
6461
// Retrieve files
6562
List<AnalysisFile> files;
66-
if(analysisFile!=null) {
67-
files = Arrays.asList(analysisFile);
63+
if(analysisFile !=null) {
64+
files = this.analysisFile;
6865
} else {
6966
files = new ArrayList<>();
7067
}
7168
return files;
7269
}
70+
71+
72+
public AnalysisInformations getAnalysisInformations() {
73+
return analysisInformations;
74+
}
75+
76+
public void setAnalysisInformations(AnalysisInformations analysisInformations) {
77+
this.analysisInformations = analysisInformations;
78+
}
79+
80+
public void setAnalysisFile(AnalysisFile[] analysisFile) {
81+
this.analysisFile = Arrays.asList(analysisFile);
82+
}
83+
84+
public void setAnalysisRule(AnalysisRule[] analysisRule) {
85+
this.analysisRule = Arrays.asList(analysisRule);
86+
}
7387
}

src/main/java/fr/cnes/sonar/plugins/icode/model/AnalysisRule.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,53 @@
1616
*/
1717
package fr.cnes.sonar.plugins.icode.model;
1818

19+
import com.thoughtworks.xstream.annotations.XStreamConverter;
20+
import com.thoughtworks.xstream.annotations.XStreamInclude;
1921
import fr.cnes.icode.data.CheckResult;
22+
import fr.cnes.sonar.plugins.icode.converter.AnalysisConverter;
2023

21-
import javax.xml.bind.annotation.XmlAttribute;
22-
import javax.xml.bind.annotation.XmlElement;
2324
import java.util.Objects;
2425

2526
/**
2627
* Class used to unmarshal i-Code xml file.
27-
*
28+
* <p>
2829
* It contains an issue and a violated rule.
2930
*/
31+
@XStreamInclude(Result.class)
32+
@XStreamConverter(value = AnalysisConverter.class, strings = {"result"})
3033
public class AnalysisRule {
3134

32-
@XmlAttribute
33-
public String analysisRuleId;
34-
@XmlElement
35-
public Result result;
35+
private String analysisRuleId;
36+
private Result result;
37+
38+
public String getAnalysisRuleId() {
39+
return analysisRuleId;
40+
}
41+
42+
public Result getResult() {
43+
return result;
44+
}
45+
46+
public void setAnalysisRuleId(String analysisRuleId) {
47+
this.analysisRuleId = analysisRuleId;
48+
}
49+
50+
public void setResult(Result result) {
51+
this.result = result;
52+
}
3653

3754
/**
3855
* Default constructor.
3956
*/
4057
public AnalysisRule() {
4158
this.analysisRuleId = "";
4259
this.result = new Result();
43-
this.result.fileName = "";
44-
this.result.resultId = "";
45-
this.result.resultMessage = "";
46-
this.result.resultLine = "";
47-
this.result.resultNamePlace = "";
48-
this.result.resultTypePlace = "";
49-
this.result.resultValue = "";
60+
this.result.setFileName("");
61+
this.result.setResultId("");
62+
this.result.setResultLine("");
63+
this.result.setResultMessage("");
64+
this.result.setResultTypePlace("");
65+
this.result.setResultValue("");
5066
}
5167

5268
/**
@@ -57,13 +73,14 @@ public AnalysisRule() {
5773
public AnalysisRule(final CheckResult checkResult) {
5874
this.analysisRuleId = checkResult.getName();
5975
this.result = new Result();
60-
this.result.fileName = checkResult.getFile().getPath();
61-
this.result.resultId = checkResult.getId();
62-
this.result.resultMessage = checkResult.getMessage();
63-
this.result.resultLine = String.valueOf(checkResult.getLine());
64-
this.result.resultNamePlace = checkResult.getLocation();
65-
this.result.resultTypePlace = Objects.isNull(checkResult.getLocation()) || checkResult.getLocation().isEmpty() ? "class" : "method";
66-
this.result.resultValue = String.valueOf(checkResult.getValue());
76+
this.result.setFileName(checkResult.getFile().getPath());
77+
this.result.setResultId(checkResult.getId());
78+
this.result.setResultLine(String.valueOf(checkResult.getLine()));
79+
this.result.setResultMessage(checkResult.getMessage());
80+
this.result.setResultTypePlace(Objects.isNull(checkResult.getLocation()) || checkResult.getLocation().isEmpty() ? "class" : "method");
81+
this.result.setResultValue(String.valueOf(checkResult.getValue()));
6782
}
6883

6984
}
85+
86+

0 commit comments

Comments
 (0)