aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-30 18:47:19 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-30 18:47:19 +0200
commit1503e7be2e25d2b55d91549a800870f63a1b25f7 (patch)
tree76892208ba3920613b8862b6dff1617e6677a7da /sonar-batch
parentd3de8d95facace01b83a4b9d7963e53d9cb6310f (diff)
downloadsonarqube-1503e7be2e25d2b55d91549a800870f63a1b25f7.tar.gz
sonarqube-1503e7be2e25d2b55d91549a800870f63a1b25f7.zip
Do not export resolved issues in the json report
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java52
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java29
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json6
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json8
4 files changed, 60 insertions, 35 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java
index b187eaca85f..3e39bae0036 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/JsonReport.java
@@ -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();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
index 737376fcdbb..c9cb6d511ea 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
@@ -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
index 00000000000..12f0bf5fee0
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report-without-resolved-issues.json
@@ -0,0 +1,6 @@
+{
+ "version": "3.6",
+ "issues": [],
+ "components": [],
+ "rules": []
+}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json b/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json
index 1234b713bf8..6b6ead4619e 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json
@@ -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": [
{