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
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))
public class Violation extends Model {
+ private Long id = null;
private String message = null;
private String severity = null;
private Integer line = null;
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 {
this.review = review;
return this;
}
+
+ /**
+ * @since 2.9
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @since 2.9
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
}
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"));
*/
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;
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
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));
[
- {"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
[
{
+ "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",
-[{"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
[
- {"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
[
- {"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