]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2812 The creation date of violation should not be reinitialized when the hash...
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 20 Sep 2011 09:00:48 +0000 (11:00 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 20 Sep 2011 09:01:31 +0000 (11:01 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java

index 81e93fe6f1be8a1fc2fad8524a9b1cdac763750c..67ca1ec63c504935cd3eff0f22ceeae36e444a3f 100644 (file)
@@ -116,6 +116,16 @@ public class ViolationTrackingDecorator implements Decorator {
               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;
   }
@@ -124,6 +134,15 @@ public class ViolationTrackingDecorator implements Decorator {
     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)) {
index ba798f14b2451eb557278ae35feb14eec7438c53..1da2991ece64fdd2af5e579dd99146da8e76960f 100644 (file)
@@ -102,6 +102,18 @@ public class ViolationTrackingDecoratorTest {
     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");