Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sonarqube java api to fetch all the Issues/Violations for a project

Tags:

sonarqube

I am using the sonar web api to query the sonar server for violations. Is there a java code to fetch all the Issues/Violations of a particular project in sonarqube? Please, any suggestions?

like image 252
iowasandroid Avatar asked Dec 19 '13 12:12

iowasandroid


1 Answers


I think you've found the answer to this question by now. However, I'll go ahead and answer this one. There are two ways of fetching all the issues of a particular project.
  1. Using the webservice sonarqube exposes.
    http://docs.sonarqube.org/pages/viewpage.action?pageId=2392181#WebService/api/issues-GetaListofIssues
  2. Using a sonar plugin How to code a custom sonar plugin? https://github.com/SonarSource/sonar-custom-plugin-example

How to get all the issues- Use 'ProjectIssues' BatchComponent to list all the issues using org.sonar.api.issue.ProjectIssues.issues()

Use @DependsUpon(DecoratorBarriers.ISSUES_TRACKED) annotation on your decorator. This will make sure that the decorator is executed once issues are tracked as stated in the documentation.

Extract from DecoratorBarriers class:


    /**
     * This barrier is after {@link #ISSUES_ADDED}. The decorators that need to list all issues must be declared
     * after this barrier : {@code @DependsUpon(value=DecoratorBarriers.ISSUES_TRACKED)}
     *
     * @since 3.6
     */
    String ISSUES_TRACKED = "END_OF_VIOLATION_TRACKING";
like image 108
Gaurav Goel Avatar answered Oct 19 '22 12:10

Gaurav Goel