Created
October 22, 2018 08:44
-
-
Save kumbasar/84dcfe6ca1fe0975604fad20f59ca8a7 to your computer and use it in GitHub Desktop.
A groovy code to get code coverage and line size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def sonarqube_host = "http://SONARQUBE_URL:9000" | |
def projectname = "MY_PROJECT" | |
def SONARCUBE_URL = "${sonarqube_host}/api/measures/component?componentKey=${projectname}&metricKeys=coverage,ncloc" | |
def son_ncloc = 'N/A' | |
def son_coverage = 'N/A' | |
def authString = "amin:admin".getBytes().encodeBase64().toString() | |
URL u = new URL ("${SONARCUBE_URL}") | |
HttpURLConnection huc = (HttpURLConnection) u.openConnection () | |
huc.setRequestProperty("Authorization", "Basic ${authString}") | |
int code = huc.getResponseCode() | |
if (code == 200) { | |
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream())); | |
StringBuilder sb = new StringBuilder(); | |
String line; | |
while ((line = br.readLine()) != null) { | |
sb.append(line+"\n"); | |
} | |
br.close(); | |
son_coverage = (new JsonSlurper().parseText(sb.toString())).component.measures.find{ it.metric=='coverage' }.value | |
son_ncloc = (new JsonSlurper().parseText(sb.toString())).component.measures.find{ it.metric=='ncloc' }.value | |
} | |
println son_coverage + " " + son_ncloc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment