]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4160 Add violation date to dry run json report
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 21 Feb 2013 17:29:14 +0000 (18:29 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 21 Feb 2013 17:29:14 +0000 (18:29 +0100)
sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java
sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java

index e2a82ed534268fce020de71b4f4fffca4a0e8ce8..ea38fe4cda5cd726eacf3666b4dc517a87d02a32 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.Violation;
 import org.sonar.api.scan.filesystem.ModuleFileSystem;
+import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.SonarException;
 import org.sonar.batch.index.DefaultIndex;
 import org.sonar.core.i18n.RuleI18nManager;
@@ -116,7 +117,11 @@ public class DryRunExporter implements BatchComponent {
             .name("rule_key").value(violation.getRule().getKey())
             .name("rule_repository").value(violation.getRule().getRepositoryKey())
             .name("rule_name").value(name(violation.getRule()))
-            .endObject();
+            .name("is_new").value(violation.isNew());
+          if (violation.getCreatedAt() != null) {
+            json.name("created_at").value(DateUtils.formatDateTime(violation.getCreatedAt()));
+          }
+          json.endObject();
         }
 
         json.endArray();
index b892aa9af66987c7826d974099ef653fd3b363f3..0f44ba3d455e188f0aeaca03ae2db7b759993486 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RulePriority;
 import org.sonar.api.rules.Violation;
 import org.sonar.api.scan.filesystem.ModuleFileSystem;
+import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.index.DefaultIndex;
 import org.sonar.core.i18n.RuleI18nManager;
 import org.sonar.java.api.JavaClass;
@@ -88,6 +89,7 @@ public class DryRunExporterTest {
     when(violation.getMessage()).thenReturn("VIOLATION");
     when(violation.getRule()).thenReturn(rule);
     when(violation.getSeverity()).thenReturn(RulePriority.INFO);
+    when(violation.getCreatedAt()).thenReturn(DateUtils.parseDate("2013-01-30"));
     when(ruleI18nManager.getName(rule, Locale.getDefault())).thenReturn("RULE_NAME");
     doReturn(Arrays.asList(violation)).when(dryRunExporter).getViolations(resource);
 
@@ -96,8 +98,8 @@ public class DryRunExporterTest {
     String json = output.toString();
 
     assertThat(json)
-      .isEqualTo(
-        "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"line\":1,\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\"}]}}");
+      .startsWith(
+        "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"line\":1,\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\",\"is_new\":false,\"created_at\":\"2013-01-30T00:00");
   }
 
   @Test
@@ -118,7 +120,7 @@ public class DryRunExporterTest {
     String json = output.toString();
 
     assertThat(json).isEqualTo(
-      "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\"}]}}");
+      "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\",\"is_new\":false}]}}");
   }
 
   @Test