diff --git a/pom.xml b/pom.xml
index d903e175..e46e9b28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,19 +154,7 @@ THE SOFTWARE.
commons-lang3
3.0
-
-
- org.apache.httpcomponents
- httpcore
- 4.4.4
-
-
-
- org.apache.httpcomponents
- httpclient
- 4.5.2
-
-
+
diff --git a/src/main/java/jenkinsci/plugins/influxdb/InfluxDbPublisher.java b/src/main/java/jenkinsci/plugins/influxdb/InfluxDbPublisher.java
index 2ac2f058..e180ad95 100644
--- a/src/main/java/jenkinsci/plugins/influxdb/InfluxDbPublisher.java
+++ b/src/main/java/jenkinsci/plugins/influxdb/InfluxDbPublisher.java
@@ -239,13 +239,13 @@ public void perform(Run, ?> build, FilePath workspace, Launcher launcher, Task
addPoints(pointsToWrite, perfGen, listener);
}
- /**
- * SonarQubePointGenerator sonarGen = new SonarQubePointGenerator(measurementRenderer, customPrefix, build);
- * if (sonarGen.hasReport()) {
- * listener.getLogger().println("[InfluxDB Plugin] SonarQube data found. Writing to InfluxDB...");
- * addPoints(pointsToWrite, sonarGen, listener);
- * }
- */
+
+ SonarQubePointGenerator sonarGen = new SonarQubePointGenerator(measurementRenderer, customPrefix, build);
+ if (sonarGen.hasReport()) {
+ listener.getLogger().println("[InfluxDB Plugin] SonarQube data found. Writing to InfluxDB...");
+ addPoints(pointsToWrite, sonarGen, listener);
+ }
+
ChangeLogPointGenerator changeLogGen = new ChangeLogPointGenerator(measurementRenderer, customPrefix, build);
if (changeLogGen.hasReport()) {
diff --git a/src/main/java/jenkinsci/plugins/influxdb/generators/SonarQubePointGenerator.java b/src/main/java/jenkinsci/plugins/influxdb/generators/SonarQubePointGenerator.java
index 5b61d16e..b46ed1e7 100644
--- a/src/main/java/jenkinsci/plugins/influxdb/generators/SonarQubePointGenerator.java
+++ b/src/main/java/jenkinsci/plugins/influxdb/generators/SonarQubePointGenerator.java
@@ -7,12 +7,11 @@
import java.net.URISyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
import org.apache.commons.lang3.StringUtils;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
import org.influxdb.dto.Point;
import hudson.model.Run;
@@ -22,7 +21,7 @@
import net.sf.json.JSONObject;
public class SonarQubePointGenerator extends AbstractPointGenerator {
-
+
public static final String BUILD_DISPLAY_NAME = "display_name";
public static final String SONARQUBE_LINES_OF_CODE = "lines_of_code";
public static final String SONARQUBE_COMPLEXITY = "complexity";
@@ -61,11 +60,11 @@ public boolean hasReport() {
if (!StringUtils.isEmpty(sonarBuildLink)) {
setSonarDetails(sonarBuildLink);
return true;
- }
+ }
} catch (IOException e) {
//
}
-
+
return false;
}
@@ -79,63 +78,58 @@ public void setSonarDetails(String sonarBuildLink) {
} catch (URISyntaxException e) {
//
}
-
+
}
+
public Point[] generate() {
Point point = null;
try {
point = buildPoint(measurementName("sonarqube_data"), customPrefix, build)
.addField(BUILD_DISPLAY_NAME, build.getDisplayName())
- .addField(SONARQUBE_CRTITCAL_ISSUES,
- getSonarIssues(this.SONAR_ISSUES_URL, "CRITICAL"))
- .addField(SONARQUBE_BLOCKER_ISSUES,
- getSonarIssues(this.SONAR_ISSUES_URL, "BLOCKER"))
- .addField(SONARQUBE_MAJOR_ISSUES,
- getSonarIssues(this.SONAR_ISSUES_URL, "MAJOR"))
- .addField(SONARQUBE_MINOR_ISSUES,
- getSonarIssues(this.SONAR_ISSUES_URL, "MINOR"))
- .addField(SONARQUBE_INFO_ISSUES,
- getSonarIssues(this.SONAR_ISSUES_URL, "INFO"))
- .addField(SONARQUBE_LINES_OF_CODE,
- getLinesofCode(this.SONAR_METRICS_URL))
- .build();
+ .addField(SONARQUBE_CRTITCAL_ISSUES, getSonarIssues(this.SONAR_ISSUES_URL, "CRITICAL"))
+ .addField(SONARQUBE_BLOCKER_ISSUES, getSonarIssues(this.SONAR_ISSUES_URL, "BLOCKER"))
+ .addField(SONARQUBE_MAJOR_ISSUES, getSonarIssues(this.SONAR_ISSUES_URL, "MAJOR"))
+ .addField(SONARQUBE_MINOR_ISSUES, getSonarIssues(this.SONAR_ISSUES_URL, "MINOR"))
+ .addField(SONARQUBE_INFO_ISSUES, getSonarIssues(this.SONAR_ISSUES_URL, "INFO"))
+ .addField(SONARQUBE_LINES_OF_CODE, getLinesofCode(this.SONAR_METRICS_URL)).build();
} catch (IOException e) {
- //handle
+ // handle
}
return new Point[] { point };
}
-
public String getResult(String request) throws IOException {
- CloseableHttpClient client = null;
- CloseableHttpResponse response = null;
StringBuffer result = new StringBuffer();
- try {
-
- client = HttpClientBuilder.create().build();
- HttpGet getrequest = new HttpGet(request);
-
- response = client.execute(getrequest);
-
- BufferedReader rd;
-
- rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+
+ try
+ {
+ URL url = new URL(request);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setRequestProperty("Accept", "application/json");
+
+ if (conn.getResponseCode() != 200) {
+ throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
+ }
+ BufferedReader rd = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
- } catch (UnsupportedOperationException | IOException e) {
- //handle
- } finally {
- if (response != null) {
- response.close();
- }
- if (client != null) {
- client.close();
- }
+ conn.disconnect();
+
+ } catch (MalformedURLException e) {
+
+ e.printStackTrace();
+
+ } catch (IOException e) {
+
+ e.printStackTrace();
+
}
+
return result.toString();
}
@@ -159,7 +153,6 @@ private String getSonarProjectURLFromBuildLogs(Run, ?> build) throws IOExcepti
return url;
}
-
private String getSonarProjectName(String url) throws URISyntaxException {
URI uri = new URI(url);
String[] projectUrl = uri.getPath().split("/");
@@ -180,12 +173,12 @@ public int getLinesofCode(String url) throws IOException {
linesofcodeCount = metricsObject.getInt("value");
}
}
-
+
return linesofcodeCount;
}
public int getSonarIssues(String url, String severity) throws IOException {
- String output = getResult(url+severity);
+ String output = getResult(url + severity);
return JSONObject.fromObject(output).getInt("total");
}