]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2488 Add the id for violations in the WS Client
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 31 May 2011 12:05:06 +0000 (14:05 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 31 May 2011 15:48:32 +0000 (17:48 +0200)
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/false-positive.json
sonar-ws-client/src/test/resources/violations/violation-with-incorrect-line.json
sonar-ws-client/src/test/resources/violations/violation-with-review.json
sonar-ws-client/src/test/resources/violations/violation-without-optional-fields.json
sonar-ws-client/src/test/resources/violations/violations.json

index 0ce59a962d95225835bab069436540cad9d85f43..0df32113614577323a2920629f1ab6200f3f1081 100644 (file)
@@ -53,6 +53,7 @@ class RuleFailure < ActiveRecord::Base
 
   def to_json(include_review=false, convert_markdown=false)
     json = {}
+    json['id'] = id
     json['message'] = plain_message if plain_message
     json['line'] = line if line && line>=1
     json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
@@ -77,6 +78,7 @@ class RuleFailure < ActiveRecord::Base
 
   def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false, convert_markdown=false)
     xml.violation do
+      xml.id(id)
       xml.message(plain_message) if plain_message
       xml.line(line) if line && line>=1
       xml.priority(Sonar::RulePriority.to_s(failure_level))
index 704bc76efa814c926bb3e2a647dfe5b80b5c6e6c..f88a3157ff169660f8c153fc9e5248c60d4c3f73 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Date;
 
 public class Violation extends Model {
 
+  private Long id = null;
   private String message = null;
   private String severity = null;
   private Integer line = null;
@@ -85,8 +86,8 @@ public class Violation extends Model {
   public void setLine(Integer line) {
     if (line != null && line < 1) {
       /*
-       * This shouldn't happen, however line would be normalized to null if web service returns incorrect value (less than 1)
-       * in compliance with a contract for getLine method. Normalization added in 2.8 - see http://jira.codehaus.org/browse/SONAR-2386
+       * This shouldn't happen, however line would be normalized to null if web service returns incorrect value (less than 1) in compliance
+       * with a contract for getLine method. Normalization added in 2.8 - see http://jira.codehaus.org/browse/SONAR-2386
        */
       this.line = null;
     } else {
@@ -206,4 +207,18 @@ public class Violation extends Model {
     this.review = review;
     return this;
   }
+
+  /**
+   * @since 2.9
+   */
+  public Long getId() {
+    return id;
+  }
+
+  /**
+   * @since 2.9
+   */
+  public void setId(Long id) {
+    this.id = id;
+  }
 }
index c8b5558eb227162beb9448e72ff17e082d42d889..f721c7135c1095b49e66fdd9ea021cc5c6d70ebb 100644 (file)
@@ -29,6 +29,7 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
     WSUtils utils = WSUtils.getINSTANCE();
 
     Violation violation = new Violation();
+    violation.setId(utils.getLong(json, "id"));
     violation.setMessage(utils.getString(json, "message"));
     violation.setLine(utils.getInteger(json, "line"));
     violation.setSeverity(utils.getString(json, "priority"));
index 32e00d2dbd8b610ac7bba972422c0f35d5b24ced..1abfaa662c28a9be4b1e828725b8e08e921a9e51 100644 (file)
  */
 package org.sonar.wsclient.unmarshallers;
 
-import org.junit.Test;
-import org.sonar.wsclient.services.Review;
-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;
@@ -32,6 +26,12 @@ import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 
+import java.util.List;
+
+import org.junit.Test;
+import org.sonar.wsclient.services.Review;
+import org.sonar.wsclient.services.Violation;
+
 public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
 
   @Test
@@ -43,6 +43,7 @@ public class ViolationUnmarshallerTest extends UnmarshallerTestCase {
     assertThat(violations.size(), is(2));
 
     violation = violations.get(0);
+    assertThat(violation.getId(), is(1L));
     assertThat(violation.getMessage(), is("throw java.lang.Exception"));
     assertThat(violation.hasLine(), is(true));
     assertThat(violation.getLine(), is(97));
index e96a394d91191a91fbccf33aacf7cb9c1d5f057f..ee3293087b3d910249637e26e06616f8c0a67cbd 100644 (file)
@@ -1,3 +1,3 @@
 [
-  {"message":"throw java.lang.Exception","switchedOff": true, "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"}}
+  {"id":1,"message":"throw java.lang.Exception","switchedOff": true, "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"}}
 ]
\ No newline at end of file
index ef2ed50b85ccd9f39a5bbc25556707aa4c429db8..aa6b51c062efe41ff75238d16eea4ffce4ec021c 100644 (file)
@@ -1,5 +1,6 @@
 [
        {
+               "id":1,
                "message":"1 branches need to be covered by unit tests to reach the minimum threshold of 65.0% branch coverage.",
                "line":0,
                "priority":"MAJOR",
index 4de5df67356b52d11979f4e722825f20be683515..1cc185766f4fde4cc54c0191d6fbd20c8300e57b 100644 (file)
@@ -1 +1 @@
-[{"message":"'static' modifier out of order with the JLS suggestions.","line":33,"priority":"MINOR","createdAt":"2011-04-26T15:17:46+0200","rule":{"key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck","name":"Modifier Order"},"resource":{"key":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","name":"CodeReaderConfiguration","scope":"FIL","qualifier":"CLA","language":"java"},"review":{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","type":"VIOLATION","status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/>''Wouhou!!!!!''"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}}]
\ No newline at end of file
+[{"id":1,"message":"'static' modifier out of order with the JLS suggestions.","line":33,"priority":"MINOR","createdAt":"2011-04-26T15:17:46+0200","rule":{"key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck","name":"Modifier Order"},"resource":{"key":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","name":"CodeReaderConfiguration","scope":"FIL","qualifier":"CLA","language":"java"},"review":{"id":3,"createdAt":"2011-04-26T15:44:42+0200","updatedAt":"2011-04-26T15:44:42+0200","author":"admin","assignee":"admin","title":"'static' modifier out of order with the JLS suggestions.","type":"VIOLATION","status":"OPEN","severity":"MINOR","resource":"org.codehaus.sonar:sonar-channel:org.sonar.channel.CodeReaderConfiguration","line":33,"comments":[{"author":"admin","updatedAt":"2011-04-26T15:44:42+0200","text":"This is a review.<br/>And this is on multiple lines...<br/><br/>''Wouhou!!!!!''"},{"author":"admin","updatedAt":"2011-04-26T17:10:19+0200","text":"<em>Bold on multiple line?</em>"},{"author":"admin","updatedAt":"2011-04-26T17:11:02+0200","text":"And the bullets:<br/><ul><li>1 bullet</li>\n<li>2 bullets</li></ul>"},{"author":"admin","updatedAt":"2011-04-26T17:27:37+0200","text":"Wazzaa"}]}}]
\ No newline at end of file
index 7923febf306f40dce9904965970194523ca2d036..c787433e07cdd9c68a80c850467a236555c8f978 100644 (file)
@@ -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"}}
+  {"id":1,"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"}}
 ]
\ No newline at end of file
index 92c98b332f088fb2328ff226516ff393c4bf252f..66353635fabce6762b97f6f3aaf6599f7b3f0a76 100644 (file)
@@ -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"}}
+  {"id":1,"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"}},
+  {"id":2,"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