Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/main/java/org/owasp/benchmark/score/WriteTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class WriteFiles {
private static final String FINDBUGS_FILE = "target/findbugsXml.xml";
private static final String PMD_FILE = "target/pmd.xml";
private static final String SONAR_FILE = "target/sonarqube.xml";
private static final String SONAR_URL = "http://localhost:9000";
private static final String SPOTBUGS_FILE = "target/spotbugsXml.xml";

public String getVersionNumber(String toolName) {
Expand Down Expand Up @@ -135,7 +136,7 @@ public String getVersionNumber(String toolName) {
root = doc.getDocumentElement();
return Reader.getAttributeValue("version", root);
case "sonar":
return "TBD";
return getSonarVersion(SONAR_URL + "/api/server/version");
}
} catch (Exception e) {
System.out.println("An error occurred during results file parsing: " + e.getMessage());
Expand Down Expand Up @@ -265,8 +266,8 @@ public void writeSonarResults() {
JSONObject json = null;

try {
while (issues.length() < total) {
json = new JSONObject(getSonarResults("http://localhost:9000", page));
while (issues.length() < total && page <= 20) {
json = new JSONObject(getSonarResults(SONAR_URL + "/api/issues/search?resolved=false&ps=500&p=" + page));
total = (int) json.get("total");

JSONArray issueSubset = json.getJSONArray("issues");
Expand All @@ -286,11 +287,18 @@ public void writeSonarResults() {
System.out.println("There was an error while writing SonarQube results.");
}
}

public static String getSonarResults(String sonarURL, int page) {

public static String getSonarVersion(String sonarURL) {
return getHttpResponse(sonarURL, "There was an error trying to retrieve SonarQube version.");
}

public static String getSonarResults(String sonarURL){
return getHttpResponse(sonarURL, "There was an error trying to retrieve SonarQube results.");
}

public static String getHttpResponse(String url, String errorMessege) {
StringBuffer response = new StringBuffer();
try {
String url = sonarURL + "/api/issues/search?resolved=false&ps=500&p=" + page;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
Expand All @@ -305,7 +313,7 @@ public static String getSonarResults(String sonarURL, int page) {
}
in.close();
} catch (Exception e) {
System.out.println("There was an error trying to retrieve SonarQube results.");
System.out.println(errorMessege);
}
return response.toString();
}
Expand Down