aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-11-08 15:59:29 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-11-08 15:59:29 +0100
commitd27d70998b977ccdd57bcfeb41347e58af368b48 (patch)
treec74738765e1ffae6215c08bf6cda34dacb6d680d /sonar-plugin-api
parent2219ae6127f6e5d6eca9fd5408318ae61141b71a (diff)
downloadsonarqube-d27d70998b977ccdd57bcfeb41347e58af368b48.tar.gz
sonarqube-d27d70998b977ccdd57bcfeb41347e58af368b48.zip
SONAR-4776 Load issues changelog at the begin of each module analysis
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java30
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java9
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java16
3 files changed, 53 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
index bae84f2e21e..ea505af1b48 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/internal/DefaultIssue.java
@@ -24,7 +24,6 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
@@ -41,6 +40,8 @@ import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.*;
+import static com.google.common.collect.Lists.newArrayList;
+
/**
* PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
*
@@ -78,6 +79,9 @@ public class DefaultIssue implements Issue {
// Current changes
private FieldDiffs currentChange = null;
+ // all changes
+ private List<FieldDiffs> changes = null;
+
// true if the the issue did not exist in the previous scan.
private boolean isNew = true;
@@ -393,17 +397,39 @@ public class DefaultIssue implements Issue {
}
currentChange.setDiff(field, oldValue, newValue);
}
+ addChange(currentChange);
return this;
}
+
@CheckForNull
public FieldDiffs currentChange() {
return currentChange;
}
+ public DefaultIssue addChange(FieldDiffs change) {
+ if (changes == null) {
+ changes = newArrayList();
+ }
+ changes.add(change);
+ return this;
+ }
+
+ public DefaultIssue setChanges(List<FieldDiffs> changes) {
+ this.changes = changes;
+ return this;
+ }
+
+ public List<FieldDiffs> changes() {
+ if (changes == null) {
+ return Collections.emptyList();
+ }
+ return ImmutableList.copyOf(changes);
+ }
+
public DefaultIssue addComment(DefaultIssueComment comment) {
if (comments == null) {
- comments = Lists.newArrayList();
+ comments = newArrayList();
}
comments.add(comment);
return this;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
index 2cd8cdbdfda..0e464d40ec5 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
@@ -32,6 +32,7 @@ import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.fest.assertions.MapAssert.entry;
+import static org.mockito.Mockito.mock;
public class DefaultIssueTest {
@@ -208,4 +209,12 @@ public class DefaultIssueTest {
fail("Unexpected exception: " + e);
}
}
+
+ @Test
+ public void all_changes_contain_current_change() throws Exception {
+ IssueChangeContext issueChangeContext = mock(IssueChangeContext.class);
+ DefaultIssue issue = new DefaultIssue().setKey("AAA").setFieldChange(issueChangeContext, "actionPlan", "1.0", "1.1");
+
+ assertThat(issue.changes()).hasSize(1);
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java
index e6f31fafb69..6a07ac3cffb 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/FieldDiffsTest.java
@@ -49,6 +49,22 @@ public class FieldDiffsTest {
}
@Test
+ public void test_diff_by_key() throws Exception {
+ diffs.setDiff("severity", "BLOCKER", "INFO");
+ diffs.setDiff("resolution", "OPEN", "FIXED");
+
+ assertThat(diffs.diffs()).hasSize(2);
+
+ FieldDiffs.Diff diff = diffs.diffs().get("severity");
+ assertThat(diff.oldValue()).isEqualTo("BLOCKER");
+ assertThat(diff.newValue()).isEqualTo("INFO");
+
+ diff = diffs.diffs().get("resolution");
+ assertThat(diff.oldValue()).isEqualTo("OPEN");
+ assertThat(diff.newValue()).isEqualTo("FIXED");
+ }
+
+ @Test
public void should_keep_old_value() throws Exception {
diffs.setDiff("severity", "BLOCKER", "INFO");
diffs.setDiff("severity", null, "MAJOR");