]> source.dussan.org Git - sonarqube.git/commitdiff
Do not export resolved issues in the json report
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 16:47:19 +0000 (18:47 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 16:47:19 +0000 (18:47 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java
sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json

index b187eaca85f433143d897fe94e34b8e4df3f3fec..3e39bae003695d553097e669e407459b61b6fd2c 100644 (file)
@@ -112,32 +112,34 @@ public class JsonReport implements BatchComponent {
   private void writeJsonIssues(JsonWriter json, Set<RuleKey> ruleKeys, Set<String> componentKeys) throws IOException {
     json.name("issues").beginArray();
     for (DefaultIssue issue : getIssues()) {
-      json
-        .beginObject()
-        .name("key").value(issue.key())
-        .name("component").value(issue.componentKey())
-        .name("line").value(issue.line())
-        .name("message").value(issue.message())
-        .name("severity").value(issue.severity())
-        .name("rule").value(issue.ruleKey().toString())
-        .name("status").value(issue.status())
-        .name("resolution").value(issue.resolution())
-        .name("isNew").value(issue.isNew())
-        .name("reporter").value(issue.reporter())
-        .name("assignee").value(issue.assignee())
-        .name("effortToFix").value(issue.effortToFix());
-      if (issue.creationDate() != null) {
-        json.name("creationDate").value(DateUtils.formatDateTime(issue.creationDate()));
-      }
-      if (issue.updateDate() != null) {
-        json.name("updateDate").value(DateUtils.formatDateTime(issue.updateDate()));
-      }
-      if (issue.closeDate() != null) {
-        json.name("closeDate").value(DateUtils.formatDateTime(issue.closeDate()));
+      if (issue.resolution() == null) {
+        json
+          .beginObject()
+          .name("key").value(issue.key())
+          .name("component").value(issue.componentKey())
+          .name("line").value(issue.line())
+          .name("message").value(issue.message())
+          .name("severity").value(issue.severity())
+          .name("rule").value(issue.ruleKey().toString())
+          .name("status").value(issue.status())
+          .name("resolution").value(issue.resolution())
+          .name("isNew").value(issue.isNew())
+          .name("reporter").value(issue.reporter())
+          .name("assignee").value(issue.assignee())
+          .name("effortToFix").value(issue.effortToFix());
+        if (issue.creationDate() != null) {
+          json.name("creationDate").value(DateUtils.formatDateTime(issue.creationDate()));
+        }
+        if (issue.updateDate() != null) {
+          json.name("updateDate").value(DateUtils.formatDateTime(issue.updateDate()));
+        }
+        if (issue.closeDate() != null) {
+          json.name("closeDate").value(DateUtils.formatDateTime(issue.closeDate()));
+        }
+        json.endObject();
+        componentKeys.add(issue.componentKey());
+        ruleKeys.add(issue.ruleKey());
       }
-      json.endObject();
-      componentKeys.add(issue.componentKey());
-      ruleKeys.add(issue.ruleKey());
     }
     json.endArray();
   }
index 737376fcdbbae8a76258673be8096fbad21d1040..c9cb6d511eaebf18119f612d0915435086fa8450 100644 (file)
@@ -17,7 +17,6 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-
 package org.sonar.batch.scan;
 
 import com.google.common.collect.Lists;
@@ -79,15 +78,35 @@ public class JsonReportTest {
       .setKey("200")
       .setComponentKey("struts:org.apache.struts.Action")
       .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
-      .setMessage("SystemPrintln")
+      .setMessage("There are 2 cycles")
       .setSeverity("MINOR")
-      .setStatus(Issue.STATUS_CLOSED)
-      .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
+      .setStatus(Issue.STATUS_OPEN)
+      .setResolution(null)
       .setLine(1)
       .setEffortToFix(3.14)
       .setReporter("julien")
       .setAssignee("simon")
+      .setCreationDate(DateUtils.parseDate("2013-04-24"))
+      .setUpdateDate(DateUtils.parseDate("2013-04-25"))
+      .setNew(false);
+    when(ruleI18nManager.getName("squid", "AvoidCycles", Locale.getDefault())).thenReturn("Avoid Cycles");
+    when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
+
+    StringWriter writer = new StringWriter();
+    jsonReport.writeJson(writer);
+
+    JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/JsonReportTest/report.json"),
+      writer.toString(), false);
+  }
+
+  @Test
+  public void should_exclude_resolved_issues() throws JSONException {
+    DefaultIssue issue = new DefaultIssue()
+      .setKey("200")
+      .setComponentKey("struts:org.apache.struts.Action")
       .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
+      .setStatus(Issue.STATUS_CLOSED)
+      .setResolution(Issue.RESOLUTION_FIXED)
       .setCreationDate(DateUtils.parseDate("2013-04-24"))
       .setUpdateDate(DateUtils.parseDate("2013-04-25"))
       .setCloseDate(DateUtils.parseDate("2013-04-26"))
@@ -98,7 +117,7 @@ public class JsonReportTest {
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/JsonReportTest/report.json"),
+    JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json"),
       writer.toString(), false);
   }
 
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json b/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json
new file mode 100644 (file)
index 0000000..12f0bf5
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "version": "3.6",
+  "issues": [],
+  "components": [],
+  "rules": []
+}
index 1234b713bf868fbed6ea050122fc1066c6cb308e..6b6ead4619ec5ee2a1d7b85dc0487e390f07249e 100644 (file)
@@ -3,18 +3,16 @@
     "key": "200",
     "component": "struts:org.apache.struts.Action",
     "line": 1,
-    "message": "SystemPrintln",
+    "message": "There are 2 cycles",
     "severity": "MINOR",
     "rule": "squid:AvoidCycles",
-    "status": "CLOSED",
-    "resolution": "FALSE-POSITIVE",
+    "status": "OPEN",
     "isNew": false,
     "reporter": "julien",
     "assignee": "simon",
     "effortToFix": 3.14,
     "creationDate": "2013-04-24T00:00:00+0200",
-    "updateDate": "2013-04-25T00:00:00+0200",
-    "closeDate": "2013-04-26T00:00:00+0200"
+    "updateDate": "2013-04-25T00:00:00+0200"
   }
 ], "components": [
   {