DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Parse Sonarqube Data via Web API in Groovy


Shell

getdata.groovy

url = "http://10.0.2.74:9000/api/resources?resource=ESB:com.boco.esb.analysismgr.service.impl&metrics=classes"

addr = url.toURL() 
conn= addr.openConnection() 
status = conn.getResponseCode() 
reader = new BufferedReader(new InputStreamReader(conn.getInputStream())) 
datastr = reader.readLine()

import groovy.json.JsonSlurper

slurper = new JsonSlurper()

data = slurper.parseText(datastr)

msr = data[0].msr.frmt_val[0]

Run Shell Script

  1. start shell: "groovysh"

  2. load script file: ". getdata.groovy";

  3. all variables in script file can be used in shell; evaluate variable value by its name directly;

  4. reload file: "purge all" then ". getdata.groovy";

Script

getdata_scpt.groovy

def url = "http://10.0.2.74:9000/api/resources?resource=ESB:com.boco.esb.analysismgr.service.impl&metrics=classes"
def addr = url.toURL()
def conn= addr.openConnection()
def status = conn.getResponseCode()
def reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
println reader.readLine()

run script

groovy getdata_scpt.groovy



Published

Dec 4, 2013

Last Updated

Dec 4, 2013

Category

Tech

Tags

  • groovy 13
  • sonar 17

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor