]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1450:
authorGodin <mandrikov@gmail.com>
Wed, 1 Dec 2010 13:19:46 +0000 (13:19 +0000)
committerGodin <mandrikov@gmail.com>
Wed, 1 Dec 2010 13:19:46 +0000 (13:19 +0000)
* Expose rule_failure.created_at in rest api
* Support createdAt in sonar-ws-client

sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java
sonar-ws-client/src/test/resources/violations/violations.json

index 30750eb6782e63a102b677eeaa54ca145bab02c3..7dc2efae3a5d3d3e48dbf3d57237c19e8769c245 100644 (file)
@@ -30,15 +30,16 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
     violation.setMessage(JsonUtils.getString(json, "message"));
     violation.setLine(JsonUtils.getInteger(json, "line"));
     violation.setPriority(JsonUtils.getString(json, "priority"));
+    violation.setCreatedAt(JsonUtils.getDate(json, "createdAt"));
 
-    JSONObject rule = (JSONObject)json.get("rule");
-    if (rule!=null) {
+    JSONObject rule = (JSONObject) json.get("rule");
+    if (rule != null) {
       violation.setRuleKey(JsonUtils.getString(rule, "key"));
       violation.setRuleName(JsonUtils.getString(rule, "name"));
     }
 
-    JSONObject resource = (JSONObject)json.get("resource");
-    if (resource!=null) {
+    JSONObject resource = (JSONObject) json.get("resource");
+    if (resource != null) {
       violation.setResourceKey(JsonUtils.getString(resource, "key"));
       violation.setResourceName(JsonUtils.getString(resource, "name"));
       violation.setResourceQualifier(JsonUtils.getString(resource, "qualifier"));
index 4ed4d7311fba1ebc1e5cf32d65245f7261078eaa..181b4332bf31f8afab40c7e363ad1664b26037a1 100644 (file)
@@ -28,7 +28,7 @@ class RuleFailure < ActiveRecord::Base
     json['message'] = message
     json['line'] = line if line
     json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
-    json['createdAt'] = format_datetime(created_at)
+    json['createdAt'] = format_datetime(created_at) if created_at
     json['rule'] = {
       :key => rule.key,
       :name => rule.name}
@@ -46,7 +46,7 @@ class RuleFailure < ActiveRecord::Base
       xml.message(message)
       xml.line(line) if line
       xml.priority(Sonar::RulePriority.to_s(failure_level))
-      xml.createdAt(format_datetime(created_at))
+      xml.createdAt(format_datetime(created_at)) if created_at
       xml.rule do
         xml.key(rule.key)
         xml.name(rule.name)
index 4bbf784e3eeeb2504c34a4155506ca0f01235a4f..5b1bdbeac25ce824b1e1fbfbbf64605c159078e5 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.wsclient.services;
 
+import java.util.Date;
+
 public class Violation extends Model {
 
   private String message = null;
@@ -30,6 +32,7 @@ public class Violation extends Model {
   private String resourceName = null;
   private String resourceScope = null;
   private String resourceQualifier = null;
+  private Date createdAt = null;
 
   public String getMessage() {
     return message;
@@ -107,4 +110,19 @@ public class Violation extends Model {
     this.resourceQualifier = resourceQualifier;
     return this;
   }
+
+  /**
+   * @since 2.5
+   */
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  /**
+   * @since 2.5
+   */
+  public Violation setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+    return this;
+  }
 }
index ab8a91fa96a8b7ce89e5dc45ff39931918186181..1d0154df2d80a8b56758ac179c21af675d2c23fe 100644 (file)
@@ -30,15 +30,16 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
     violation.setMessage(JsonUtils.getString(json, "message"));
     violation.setLine(JsonUtils.getInteger(json, "line"));
     violation.setPriority(JsonUtils.getString(json, "priority"));
+    violation.setCreatedAt(JsonUtils.getDateTime(json, "createdAt"));
 
-    JSONObject rule = (JSONObject)json.get("rule");
-    if (rule!=null) {
+    JSONObject rule = (JSONObject) json.get("rule");
+    if (rule != null) {
       violation.setRuleKey(JsonUtils.getString(rule, "key"));
       violation.setRuleName(JsonUtils.getString(rule, "name"));
     }
 
-    JSONObject resource = (JSONObject)json.get("resource");
-    if (resource!=null) {
+    JSONObject resource = (JSONObject) json.get("resource");
+    if (resource != null) {
       violation.setResourceKey(JsonUtils.getString(resource, "key"));
       violation.setResourceName(JsonUtils.getString(resource, "name"));
       violation.setResourceQualifier(JsonUtils.getString(resource, "qualifier"));
index ff879b6ebaf41502acdaa2f829cfdd9eca299f42..7eb1e1aaf7bb7082b0a03fe560e6d65cda3b4f41 100644 (file)
  */
 package org.sonar.wsclient.unmarshallers;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+
 import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 import org.sonar.wsclient.services.Violation;
@@ -26,11 +32,6 @@ import org.sonar.wsclient.services.Violation;
 import java.io.IOException;
 import java.util.List;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-
 public class ViolationUnmarshallerTest {
 
   @Test
@@ -44,10 +45,12 @@ public class ViolationUnmarshallerTest {
     violation = violations.get(0);
     assertThat(violation.getMessage(), is("throw java.lang.Exception"));
     assertThat(violation.getLine(), is(97));
+    assertThat(violation.getCreatedAt(), notNullValue());
     assertThat(violation.getPriority(), is("MAJOR"));
     assertThat(violation.getRuleKey(), is("pmd:SignatureDeclareThrowsException"));
     assertThat(violation.getRuleName(), is("Signature Declare Throws Exception"));
-    assertThat(violation.getResourceKey(), is("org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool"));
+    assertThat(violation.getResourceKey(),
+        is("org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool"));
     assertThat(violation.getResourceName(), is("TraceableResourceLimitingPool"));
     assertThat(violation.getResourceQualifier(), is("CLA"));
     assertThat(violation.getResourceScope(), is("FIL"));
@@ -58,6 +61,7 @@ public class ViolationUnmarshallerTest {
     Violation violation = new ViolationUnmarshaller().toModel(loadFile("/violations/violation-without-optional-fields.json"));
     assertThat(violation.getMessage(), not(nullValue()));
     assertThat(violation.getLine(), nullValue());
+    assertThat(violation.getCreatedAt(), nullValue());
   }
 
   private static String loadFile(String path) throws IOException {
index ec9fb7b682a23586c97f8c9429a9b0030515a083..92c98b332f088fb2328ff226516ff393c4bf252f 100644 (file)
@@ -1,4 +1,4 @@
 [
-  {"message":"throw java.lang.Exception","line":97,"priority":"MAJOR","rule":{"key":"pmd:SignatureDeclareThrowsException","name":"Signature Declare Throws Exception","category":"Maintainability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}},
-  {"message":"The user-supplied array 'threads' is stored directly.","line":242,"priority":"MAJOR","rule":{"key":"pmd:ArrayIsStoredDirectly","name":"Security - Array is stored directly","category":"Reliability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}}
+  {"message":"throw java.lang.Exception","line":97,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","rule":{"key":"pmd:SignatureDeclareThrowsException","name":"Signature Declare Throws Exception","category":"Maintainability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}},
+  {"message":"The user-supplied array 'threads' is stored directly.","line":242,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","rule":{"key":"pmd:ArrayIsStoredDirectly","name":"Security - Array is stored directly","category":"Reliability"},"resource":{"key":"org.apache.excalibur.components:excalibur-pool-instrumented:org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool","name":"TraceableResourceLimitingPool","scope":"FIL","qualifier":"CLA","language":"java"}}
 ]
\ No newline at end of file