I’m using SonarQube version: 6.7.1
I’m trying to use sonarqube api to analyze archives on a folder and then give the issues of a specific filename but I’ve found two problems
First one is that this is retrieving issues from filenames of source folder that were deleted long time ago and I don’t understand why, because if I enter to sonarqube local web api on localhost/9000 that code is not there
and second and most important, I’m trying to get Issues from a filename but sonarqube is giving me issues from all the project(even projects when I had more than one), including deleted codes from the first problem I said above.
this is how I implemented it
public class SonarqubeServiceImpl implements SonarqubeService {
private final String SONAR_URL = "http://localhost:9000/";
private final String PROJECT_KEY = "refactor2";
private final String SRC_FOLDER = "src/main/java/com/uca/refactor2/activities";
private String EXECUTE_SONAR;
private String GET_ISSUES_URL = SONAR_URL + "api/issues/search?q=";
private static String POM_PATH = "pom.xml";
private RestTemplate restTemplate = new RestTemplate();
private InvocationRequest request;
private Invoker invoker;
@PostConstruct
private void init() {
System.out.println("PostConstruct");
buildSonarCommand();
configureMavenWithSonar();
}
@Override
public void runAnalysis() throws MavenInvocationException {
// Assuming everything is set up (done in init)
invoker.execute(request);
}
@Override
public IssuesResponse getIssuesFromFileName(String fileName) {
String URL = GET_ISSUES_URL + fileName;
return restTemplate.getForObject(URL, IssuesResponse.class);
}
private void configureMavenWithSonar() {
request = new DefaultInvocationRequest();
request.setPomFile(new File(POM_PATH));
request.setGoals(Collections.singletonList(EXECUTE_SONAR));
invoker = new DefaultInvoker();
// Set maven home in case env variables are not set
// (and using own installation)
invoker.setMavenHome(new File("apache-maven-3.5.2"));
}
private void buildSonarCommand() {
StringBuilder builder = new StringBuilder();
builder.append("sonar:sonar ");
builder.append(String.format("-Dsonar.host.url=%s ", SONAR_URL));
builder.append(String.format("-Dsonar.projectKey=%s ", PROJECT_KEY));
builder.append(String.format("-Dsonar.sources=%s ", SRC_FOLDER));
EXECUTE_SONAR = builder.toString();
}
}
I’m fetching issues with this URL
http://localhost:9000/api/issues/search?q=" + fileName;
but I get a mix of both errors I said above, I get issues from all files without the filter by fileName and I get issues from archives that doesn’t exist anymore on the folder
this is my first time with Sonarqube, Am I missing something?
edit: I don’t know how to format code, I’ve post the code more readable also at