pastViolationsByRule, referenceViolationsMap);
}
}
+
+ // Last check: match violation if same rule and same checksum but different line and different message
+ // See https://jira.codehaus.org/browse/SONAR-2812
+ for (Violation newViolation : newViolations) {
+ if (isNotAlreadyMapped(newViolation, referenceViolationsMap)) {
+ mapViolation(newViolation,
+ findPastViolationWithSameChecksum(newViolation, pastViolationsByRule.get(newViolation.getRule().getId())),
+ pastViolationsByRule, referenceViolationsMap);
+ }
+ }
}
return referenceViolationsMap;
}
return !violationMap.containsKey(newViolation);
}
+ private RuleFailureModel findPastViolationWithSameChecksum(Violation newViolation, Collection<RuleFailureModel> pastViolations) {
+ for (RuleFailureModel pastViolation : pastViolations) {
+ if (isSameChecksum(newViolation, pastViolation)) {
+ return pastViolation;
+ }
+ }
+ return null;
+ }
+
private RuleFailureModel findPastViolationWithSameLineAndMessage(Violation newViolation, Collection<RuleFailureModel> pastViolations) {
for (RuleFailureModel pastViolation : pastViolations) {
if (isSameLine(newViolation, pastViolation) && isSameMessage(newViolation, pastViolation)) {
assertThat(mapping.get(newViolation), equalTo(referenceViolation));
}
+ /**
+ * See https://jira.codehaus.org/browse/SONAR-2812
+ */
+ @Test
+ public void sameChecksumAndRuleButDifferentLineAndDifferentMessage() {
+ Violation newViolation = newViolation("new message", 1, 50, "checksum1");
+ RuleFailureModel referenceViolation = newReferenceViolation("old message", 2, 50, "checksum1");
+
+ Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Lists.newArrayList(referenceViolation));
+ assertThat(mapping.get(newViolation), equalTo(referenceViolation));
+ }
+
@Test
public void shouldCreateNewViolationWhenSameRuleSameMessageButDifferentLineAndChecksum() {
Violation newViolation = newViolation("message", 1, 50, "checksum1");