]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4310 update issue message during tracking
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 12:38:41 +0000 (14:38 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 12:38:58 +0000 (14:38 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java

index fb1297aa31f64d3d8ae59d8e1cc4832a7dec164e..68a90e9162909630aab2350e541240470594c5ea 100644 (file)
@@ -149,14 +149,11 @@ public class IssueTrackingDecorator implements Decorator {
         issue.setManualSeverity(true);
         issue.setSeverity(ref.getSeverity());
       } else {
-        // Emulate change of severity in the current scan.
-        String severity = issue.severity();
-        issue.setSeverity(ref.getSeverity());
-        updater.setSeverity(issue, severity, changeContext);
+        updater.setPastSeverity(issue, ref.getSeverity(), changeContext);
       }
-      Integer line = issue.line();
-      issue.setLine(ref.getLine());
-      updater.setLine(issue, line);
+      updater.setPastLine(issue, ref.getLine());
+      updater.setPastMessage(issue, ref.getMessage(), changeContext);
+      updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext);
     }
   }
 
index e080d39eec986707e32e44f3912af4665f394b0d..ab393473128d2c0117187fb0fbcb72eda8e012ef 100644 (file)
@@ -46,6 +46,12 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
     return false;
   }
 
+  public boolean setPastSeverity(DefaultIssue issue, @Nullable String previousSeverity, IssueChangeContext context) {
+    String currentSeverity = issue.severity();
+    issue.setSeverity(previousSeverity);
+    return setSeverity(issue, currentSeverity, context);
+  }
+
   public boolean setManualSeverity(DefaultIssue issue, String severity, IssueChangeContext context) {
     if (!issue.manualSeverity() || !Objects.equal(severity, issue.severity())) {
       issue.setFieldDiff(context, "severity", issue.severity(), severity);
@@ -79,6 +85,12 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
     return false;
   }
 
+  public boolean setPastLine(DefaultIssue issue, @Nullable Integer previousLine) {
+    Integer currentLine = issue.line();
+    issue.setLine(previousLine);
+    return setLine(issue, currentLine);
+  }
+
   public boolean setResolution(DefaultIssue issue, @Nullable String resolution, IssueChangeContext context) {
     if (!Objects.equal(resolution, issue.resolution())) {
       issue.setFieldDiff(context, "resolution", issue.resolution(), resolution);
@@ -101,22 +113,31 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
     return false;
   }
 
-  public void setAuthorLogin(DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) {
+  public boolean setAuthorLogin(DefaultIssue issue, @Nullable String authorLogin, IssueChangeContext context) {
     if (!Objects.equal(authorLogin, issue.authorLogin())) {
       issue.setFieldDiff(context, "author", issue.authorLogin(), authorLogin);
       issue.setAuthorLogin(authorLogin);
       issue.setUpdateDate(context.date());
       issue.setChanged(true);
+      return true;
     }
+    return false;
   }
 
-  public void setMessage(DefaultIssue issue, @Nullable String s, IssueChangeContext context) {
+  public boolean setMessage(DefaultIssue issue, @Nullable String s, IssueChangeContext context) {
     if (!Objects.equal(s, issue.message())) {
-      issue.setFieldDiff(context, "message", issue.message(), s);
       issue.setMessage(s);
       issue.setUpdateDate(context.date());
       issue.setChanged(true);
+      return true;
     }
+    return false;
+  }
+
+  public boolean setPastMessage(DefaultIssue issue, @Nullable String previousMessage, IssueChangeContext context) {
+    String currentMessage = issue.message();
+    issue.setMessage(previousMessage);
+    return setMessage(issue, currentMessage, context);
   }
 
   public void addComment(DefaultIssue issue, String text, IssueChangeContext context) {
@@ -143,6 +164,12 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
     return false;
   }
 
+  public boolean setPastEffortToFix(DefaultIssue issue, @Nullable Double previousEffort, IssueChangeContext context) {
+    Double currentEffort = issue.effortToFix();
+    issue.setEffortToFix(previousEffort);
+    return setEffortToFix(issue, currentEffort, context);
+  }
+
   public boolean setAttribute(DefaultIssue issue, String key, @Nullable String value, IssueChangeContext context) {
     String oldValue = issue.attribute(key);
     if (!Objects.equal(oldValue, value)) {
index b9db96810f4a93b2ca7d576f4ddd6bda19bc602e..01e3c3b34c9a693af0d3913e2ba043b07ed417f6 100644 (file)
@@ -84,6 +84,18 @@ public class IssueUpdaterTest {
     assertThat(diff.newValue()).isEqualTo("BLOCKER");
   }
 
+  @Test
+  public void should_set_past_severity() throws Exception {
+    issue.setSeverity("BLOCKER");
+    boolean updated = updater.setPastSeverity(issue, "INFO", context);
+    assertThat(updated).isTrue();
+    assertThat(issue.severity()).isEqualTo("BLOCKER");
+
+    FieldDiffs.Diff diff = issue.diffs().get("severity");
+    assertThat(diff.oldValue()).isEqualTo("INFO");
+    assertThat(diff.newValue()).isEqualTo("BLOCKER");
+  }
+
   @Test
   public void should_update_severity() throws Exception {
     issue.setSeverity("BLOCKER");
@@ -145,6 +157,17 @@ public class IssueUpdaterTest {
     assertThat(issue.diffs()).isNull();
   }
 
+  @Test
+  public void should_set_past_line() throws Exception {
+    issue.setLine(42);
+    boolean updated = updater.setPastLine(issue, 123);
+    assertThat(updated).isTrue();
+    assertThat(issue.line()).isEqualTo(42);
+
+    // do not save change
+    assertThat(issue.diffs()).isNull();
+  }
+
   @Test
   public void should_not_change_line() throws Exception {
     issue.setLine(123);
@@ -249,4 +272,45 @@ public class IssueUpdaterTest {
     assertThat(issue.isChanged()).isFalse();
     assertThat(issue.effortToFix()).isEqualTo(3.14);
   }
+
+  @Test
+  public void should_set_past_effort() throws Exception {
+    issue.setEffortToFix(3.14);
+    boolean updated = updater.setPastEffortToFix(issue, 1.0, context);
+    assertThat(updated).isTrue();
+    assertThat(issue.effortToFix()).isEqualTo(3.14);
+
+    // do not save change
+    assertThat(issue.diffs()).isNull();
+  }
+
+  @Test
+  public void should_set_message() throws Exception {
+    boolean updated = updater.setMessage(issue, "the message", context);
+    assertThat(updated).isTrue();
+    assertThat(issue.isChanged()).isTrue();
+    assertThat(issue.message()).isEqualTo("the message");
+  }
+
+  @Test
+  public void should_set_past_message() throws Exception {
+    issue.setMessage("new message");
+    boolean updated = updater.setPastMessage(issue, "past message", context);
+    assertThat(updated).isTrue();
+    assertThat(issue.message()).isEqualTo("new message");
+
+    // do not save change
+    assertThat(issue.diffs()).isNull();
+  }
+
+  @Test
+  public void should_set_author() throws Exception {
+    boolean updated = updater.setAuthorLogin(issue, "eric", context);
+    assertThat(updated).isTrue();
+    assertThat(issue.authorLogin()).isEqualTo("eric");
+
+    FieldDiffs.Diff diff = issue.diffs().get("author");
+    assertThat(diff.oldValue()).isNull();
+    assertThat(diff.newValue()).isEqualTo("eric");
+  }
 }