如何从api / sonarqube的指标中获取Json?

时间:2015-05-29 09:39:17

标签: json sonarqube

我尝试使用api / metrics的GET方法来检索用于我的程序的JSON,但文档中没有描述requestUrl中使用的所有参数。

例如,在我的程序中,我发现使用Google Chrome控制台,requestUrl就是这个:

  

http://localhost:9000/api/resources?resource=my%3AjavaSample%3AMandria%2Fsrc%2Fmandria%2FIllnessException.java&metrics=new_technical_debt%2Cblocker_violations%2Cburned_budget%2Cbusiness_value%2Cclasses%2Ccomment_lines%2Ccomment_lines_density%2Ccomplexity%2Cclass_complexity%2Cfile_complexity%2Cfunction_complexity%2Cbranch_coverage%2Cnew_it_branch_coverage%2Cnew_branch_coverage%2Cconfirmed_issues%2Ccoverage%2Cnew_it_coverage%2Cnew_coverage%2Ccritical_violations%2Cdirectories%2Cduplicated_blocks%2Cduplicated_files%2Cduplicated_lines%2Cduplicated_lines_density%2Cfalse_positive_issues%2Cpackage_tangles%2Cfiles%2Cfile_complexity_distribution%2Cfunctions%2Cfunction_complexity_distribution%2Cgenerated_lines%2Cgenerated_ncloc%2Cit_branch_coverage%2Cit_coverage%2Cit_line_coverage%2Cit_uncovered_conditions%2Cit_uncovered_lines%2Cinfo_violations%2Cviolations%2Cline_coverage%2Cnew_it_line_coverage%2Cnew_line_coverage%2Clines%2Cncloc%2Clines_to_cover%2Cnew_it_lines_to_cover%2Cnew_lines_to_cover%2Cmajor_violations%2Cminor_violations%2Cnew_blocker_violations%2Cnew_critical_violations%2Cnew_info_violations%2Cnew_major_violations%2Cnew_minor_violations%2Cnew_violations%2Copen_issues%2Coverall_branch_coverage%2Cnew_overall_branch_coverage%2Coverall_coverage%2Cnew_overall_coverage%2Coverall_line_coverage%2Cnew_overall_line_coverage%2Cnew_overall_lines_to_cover%2Coverall_uncovered_conditions%2Cnew_overall_uncovered_conditions%2Coverall_uncovered_lines%2Cnew_overall_uncovered_lines%2Cpackage_cycles%2Cpackage_feedback_edges%2Cpackage_tangle_index%2Cprojects%2Cpublic_api%2Cpublic_documented_api_density%2Cpublic_undocumented_api%2Calert_status%2Creopened_issues%2Csqale_rating%2Cskipped_tests%2Cstatements%2Cteam_size%2Csqale_index%2Csqale_debt_ratio%2Cuncovered_conditions%2Cnew_it_uncovered_conditions%2Cnew_uncovered_conditions%2Cuncovered_lines%2Cnew_it_uncovered_lines%2Cnew_uncovered_lines%2Ctests%2Ctest_execution_time%2Ctest_errors%2Ctest_failures%2Ctest_success_density

是否有可能找到更详细的文档或我尝试解决问题的方式不正确?

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

回答您的问题如何从外部评论中致电:

如果要从Java程序调用SonarQube Web服务API,可以使用Apache HTTP Client:

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"