【发布时间】:2015-06-01 17:44:52
【问题描述】:
【问题讨论】:
-
我已经访问了 SonarSource API 文档,但对我来说真的很模糊。有人知道在哪里可以找到更好的文档吗?
【问题讨论】:
只需在参数中添加&format=json。
见http://docs.sonarqube.org/display/SONARQUBE43/Web+Service+API#WebServiceAPI-ResponseFormats
【讨论】:
针对您的问题,如何从外部评论中致电:
如果您想从 Java 程序调用 SonarQube Web 服务 API,您可以使用 Apache HTTP 客户端:
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpGet httpGet = new HttpGet("http://localhost:9000/api/resources?metrics=lines");
try(CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(httpGet);) {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
}
}
在这种情况下,它会打印 SonarQube 上的所有项目,并附加度量“行”。您可以将多个指标添加到列表中,以逗号分隔:
"http://localhost:9000/api/resources?metrics=lines,blocker_violations"
【讨论】: