diff options
Diffstat (limited to 'sonar-ws-client')
4 files changed, 35 insertions, 12 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java index 4bbf784e3ee..5b1bdbeac25 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java @@ -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; + } } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java index ab8a91fa96a..1d0154df2d8 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java @@ -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")); diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java index ff879b6ebaf..7eb1e1aaf7b 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java @@ -19,6 +19,12 @@ */ 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 { diff --git a/sonar-ws-client/src/test/resources/violations/violations.json b/sonar-ws-client/src/test/resources/violations/violations.json index ec9fb7b682a..92c98b332f0 100644 --- a/sonar-ws-client/src/test/resources/violations/violations.json +++ b/sonar-ws-client/src/test/resources/violations/violations.json @@ -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 |