我正在尝试使用RedirectMatch
获取特定项目中未解决的错误和漏洞的总数。
我尝试将类型作为BUG传递给搜索查询。但我仍然得到所有未解决的东西。它没有采用参数类型。
如何使用Webservice获取确切数量的错误和漏洞?
这是我的代码连接到声纳并获取数据。
sonar-ws-5.6.jar
注意:我正在使用带有Java 1.8的sonarqube 5.6
截至目前,我正在迭代响应并获得计数
import java.util.ArrayList;
import java.util.List;
import org.sonarqube.ws.Issues.SearchWsResponse;
import org.sonarqube.ws.client.HttpConnector;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsClientFactories;
import org.sonarqube.ws.client.issue.SearchWsRequest;
public class SonarTest {
static String resourceKey = "com.company.projectname:parent";
public static void main(String[] args) {
try {
// Get Issue
HttpConnector httpConnector = HttpConnector.newBuilder().url("http://localhost:9000").credentials("admin", "admin").build();
SearchWsRequest issueSearchRequest = new SearchWsRequest();
issueSearchRequest.setPageSize(1000);
issueSearchRequest.setResolved(false);
List<String> bugTypesList = new ArrayList<String>();
bugTypesList.add("BUG");
issueSearchRequest.setTypes(bugTypesList);
WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
SearchWsResponse issuesResponse = wsClient.issues().search(issueSearchRequest);
System.out.println(issuesResponse.getIssuesList());
System.out.println("DONE");
} catch (Exception e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:1)
我正在使用ComponentWsRequest 来获取错误总数
我们可以传递指标键以获得所需的值。
这是代码,它给出了错误的总数。
List<String> VALUE_METRIC_KEYS = Arrays.asList("bugs");
ComponentWsRequest componentWsRequest = new ComponentWsRequest();
componentWsRequest.setComponentKey(resourceKey);
componentWsRequest.setMetricKeys(VALUE_METRIC_KEYS);
ComponentWsResponse componentWsResponse = wsClient.measures().component(componentWsRequest);
List<Measure>measureList = componentWsResponse.getComponent().getMeasuresList();
for(Measure measure : measureList){
System.out.println(measure);
}
我们可以使用任何指标键来获取相应的值:
“quality_gate_details”, “reliability_rating”, “reliability_remediation_effort”, “漏洞”, “security_rating”, “security_remediation_effort”, “code_smells”, “sqale_rating”, “sqale_debt_ratio”, “effort_to_reach_maintainability_rating_a”, “sqale_index”, “ncloc” , “线”, “声明”, “功能”, “类”, “文件”, “目录”, “duplicated_lines_density”, “duplicated_blocks”, “duplicated_lines”, “duplicated_files”, “复杂性”, “function_complexity”,” file_complexity”, “class_complexity”, “comment_lines_density”, “comment_lines”, “public_api”, “public_documented_api_density”, “public_undocumented_api”, “违规行为”, “open_issues”, “reopened_issues”, “confirmed_issues”, “false_positive_issues”, “wont_fix_issues”
答案 1 :(得分:1)
嗯,你抓到了一个bug!我使用了您的代码,发现types
参数未正确地从 WSClient 传递到实际的HTTP查询。
非常感谢您分享您的问题,SONAR-7871已打开,以便解决问题。