aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-21 16:56:21 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-21 18:40:48 +0200
commite8bf534ec680e583b0e7683c92f1be31ab66a74e (patch)
tree69a2281fa2f3b036e945c1b27d41c9afd2043a75 /sonar-ws-client
parent5c66787f6e31f2931f28b78d3eb056503cdfe57a (diff)
downloadsonarqube-e8bf534ec680e583b0e7683c92f1be31ab66a74e.tar.gz
sonarqube-e8bf534ec680e583b0e7683c92f1be31ab66a74e.zip
SONAR-2380 The "violations" web service API must not return
"false-positive" violation Also modified the batch side ViolationQuery class that I created so that they have the same API.
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java19
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java19
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshallerTest.java11
-rw-r--r--sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json2
-rw-r--r--sonar-ws-client/src/test/resources/violations/violations.json4
6 files changed, 47 insertions, 9 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 f993b14321f..e29c37396ba 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
@@ -33,6 +33,7 @@ public class Violation extends Model {
private String resourceScope = null;
private String resourceQualifier = null;
private Date createdAt = null;
+ private boolean switchedOff;
public String getMessage() {
return message;
@@ -152,6 +153,22 @@ public class Violation extends Model {
* @since 2.5
*/
public boolean isCreatedAfter(Date date) {
- return createdAt!=null && date!=null && createdAt.after(date);
+ return createdAt != null && date != null && createdAt.after(date);
}
+
+ /**
+ * @since 2.8
+ */
+ public Violation setSwitchedOff(boolean switchedOff) {
+ this.switchedOff = switchedOff;
+ return this;
+ }
+
+ /**
+ * @since 2.8
+ */
+ public boolean isSwitchedOff() {
+ return switchedOff;
+ }
+
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
index 0fc6d244d57..06a75f94c9e 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ViolationQuery.java
@@ -20,6 +20,7 @@
package org.sonar.wsclient.services;
public class ViolationQuery extends Query<Violation> {
+
public static final String BASE_URL = "/api/violations";
private String resourceKeyOrId;
@@ -30,6 +31,7 @@ public class ViolationQuery extends Query<Violation> {
private String[] categories;
private String[] severities;
private Integer limit;
+ private boolean isSwitchedOff;
public ViolationQuery(String resourceKeyOrId) {
this.resourceKeyOrId = resourceKeyOrId;
@@ -127,6 +129,21 @@ public class ViolationQuery extends Query<Violation> {
return this;
}
+ /**
+ * @since 2.8
+ */
+ public ViolationQuery setSwitchedOff(boolean ignore) {
+ this.isSwitchedOff = ignore;
+ return this;
+ }
+
+ /**
+ * @since 2.8
+ */
+ public boolean isSwitchedOff() {
+ return isSwitchedOff;
+ }
+
@Override
public String getUrl() {
StringBuilder url = new StringBuilder(BASE_URL);
@@ -141,6 +158,8 @@ public class ViolationQuery extends Query<Violation> {
appendUrlParameter(url, "rules", ruleKeys);
appendUrlParameter(url, "categories", categories);
appendUrlParameter(url, "priorities", severities);
+ appendUrlParameter(url, "switched_off", isSwitchedOff);
+
return url.toString();
}
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 0df77ae74fc..df62e5c0e16 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
@@ -33,6 +33,7 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
violation.setLine(utils.getInteger(json, "line"));
violation.setSeverity(utils.getString(json, "priority"));
violation.setCreatedAt(utils.getDateTime(json, "createdAt"));
+ violation.setSwitchedOff(utils.getBoolean(json, "switchedOff"));
Object rule = utils.getField(json, "rule");
if (rule != null) {
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 614ed46b79f..3f3da0e81fc 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,17 +19,17 @@
*/
package org.sonar.wsclient.unmarshallers;
-import org.junit.Test;
-import org.sonar.wsclient.services.Violation;
-
-import java.util.List;
-
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 java.util.List;
+
+import org.junit.Test;
+import org.sonar.wsclient.services.Violation;
+
public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
@Test
@@ -52,6 +52,7 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
assertThat(violation.getResourceName(), is("TraceableResourceLimitingPool"));
assertThat(violation.getResourceQualifier(), is("CLA"));
assertThat(violation.getResourceScope(), is("FIL"));
+ assertThat(violation.isSwitchedOff(), is(true));
}
@Test
diff --git a/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json b/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json
index acfffe3e152..7c8aa24b70a 100644
--- a/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json
+++ b/sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json
@@ -1,3 +1,3 @@
[
- {"message":"throw java.lang.Exception","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":"throw java.lang.Exception","priority":"MAJOR","switchedOff":true,"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"}},
] \ No newline at end of file
diff --git a/sonar-ws-client/src/test/resources/violations/violations.json b/sonar-ws-client/src/test/resources/violations/violations.json
index 92c98b332f0..1dbad54bb6e 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,"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"}}
+ {"message":"throw java.lang.Exception","line":97,"createdAt":"2010-12-01T13:55:22+0300","priority":"MAJOR","switchedOff":true,"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","switchedOff":false,"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