From 1ae9da926fecb5e2eac4bb9f2f21c60db30320b4 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 4 May 2011 16:53:02 +0200 Subject: SONAR-2381, SONAR-2382 Web services return comment in HTML by default Available for the Violation and Review WS: - parameter 'output' on the request - if set to 'html', comments are returned in HTML - otherwise comments are returned as raw text - Java WS client updated consequently --- .../java/org/sonar/wsclient/services/ReviewQuery.java | 17 +++++++++++++++++ .../org/sonar/wsclient/services/ViolationQuery.java | 17 +++++++++++++++++ .../org/sonar/wsclient/services/ReviewQueryTest.java | 13 ++++--------- .../org/sonar/wsclient/services/ViolationQueryTest.java | 5 +++-- 4 files changed, 41 insertions(+), 11 deletions(-) (limited to 'sonar-ws-client/src') diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java index 21dc8d0d0d5..38c3780ce2d 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java @@ -35,6 +35,7 @@ public class ReviewQuery extends Query { private String[] resourceKeysOrIds; private String[] authorLoginsOrIds; private String[] assigneeLoginsOrIds; + private String output; public ReviewQuery() { } @@ -187,6 +188,21 @@ public class ReviewQuery extends Query { return this; } + /** + * @return the output + */ + public String getOutput() { + return output; + } + + /** + * @param output the output to set + */ + public ReviewQuery setOutput(String output) { + this.output = output; + return this; + } + @Override public String getUrl() { StringBuilder url = new StringBuilder(BASE_URL); @@ -203,6 +219,7 @@ public class ReviewQuery extends Query { appendUrlParameter(url, "resources", resourceKeysOrIds); appendUrlParameter(url, "authors", authorLoginsOrIds); appendUrlParameter(url, "assignees", assigneeLoginsOrIds); + appendUrlParameter(url, "output", output); return url.toString(); } 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 e3eb5dd60de..42408d98c03 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 @@ -32,6 +32,7 @@ public class ViolationQuery extends Query { private String[] severities; private Integer limit; private Boolean includeReview; + private String output; public ViolationQuery(String resourceKeyOrId) { this.resourceKeyOrId = resourceKeyOrId; @@ -144,6 +145,21 @@ public class ViolationQuery extends Query { return this; } + /** + * @since 2.8 + */ + public String getOutput() { + return output; + } + + /** + * @since 2.8 + */ + public ViolationQuery setOutput(String output) { + this.output = output; + return this; + } + @Override public String getUrl() { StringBuilder url = new StringBuilder(BASE_URL); @@ -159,6 +175,7 @@ public class ViolationQuery extends Query { appendUrlParameter(url, "categories", categories); appendUrlParameter(url, "priorities", severities); appendUrlParameter(url, "include_review", includeReview); + appendUrlParameter(url, "output", output); return url.toString(); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java index 0dc688784c1..bf692cbbcb5 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ReviewQueryTest.java @@ -40,16 +40,11 @@ public class ReviewQueryTest extends QueryTestCase { @Test public void resourceTreeViolations() { ReviewQuery query = new ReviewQuery(); - query.setIds(10L, 11L); - query.setReviewType("FALSE_POSITIVE"); - query.setStatuses("OPEN"); - query.setSeverities("MINOR", "INFO"); - query.setProjectKeysOrIds("com.sonar.foo:bar"); - query.setResourceKeysOrIds("2", "3"); - query.setAuthorLoginsOrIds("20"); - query.setAssigneeLoginsOrIds("admin"); + query.setIds(10L, 11L).setReviewType("FALSE_POSITIVE").setStatuses("OPEN").setSeverities("MINOR", "INFO") + .setProjectKeysOrIds("com.sonar.foo:bar").setResourceKeysOrIds("2", "3").setAuthorLoginsOrIds("20").setAssigneeLoginsOrIds("admin") + .setOutput("html"); assertThat( query.getUrl(), - is("/api/reviews?ids=10,11&review_type=FALSE_POSITIVE&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&")); + is("/api/reviews?ids=10,11&review_type=FALSE_POSITIVE&statuses=OPEN&severities=MINOR,INFO&projects=com.sonar.foo%3Abar&resources=2,3&authors=20&assignees=admin&output=html&")); } } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java index f7f9279906d..9a7140db3ee 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ViolationQueryTest.java @@ -40,9 +40,10 @@ public class ViolationQueryTest extends QueryTestCase { .setLimit(20) .setSeverities("MAJOR", "BLOCKER") .setQualifiers("FIL") - .setRuleKeys("checkstyle:foo", "pmd:bar"); + .setRuleKeys("checkstyle:foo", "pmd:bar") + .setOutput("html"); assertThat( query.getUrl(), - is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle%3Afoo,pmd%3Abar&priorities=MAJOR,BLOCKER&")); + is("/api/violations?resource=myproject&depth=-1&limit=20&qualifiers=FIL&rules=checkstyle%3Afoo,pmd%3Abar&priorities=MAJOR,BLOCKER&output=html&")); } } -- cgit v1.2.3