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();
}
* 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;
.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"))
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);
}
--- /dev/null
+{
+ "version": "3.6",
+ "issues": [],
+ "components": [],
+ "rules": []
+}
"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": [
{