diff --git a/README.md b/README.md index 175c118..41fa515 100755 --- a/README.md +++ b/README.md @@ -34,11 +34,12 @@ cp ./build/libs/xlr-sonar-plugin-1.0.jar $XLRelease_HOME/plugins #Usage# -1. Go to the Settings > Configuration and define a Sonarqube Server Reference +1. Go to the Settings > Configuration and define a Sonarqube Server Reference. eg https://builds.apache.org/analysis +![Configuration](images/snapshot1.png) 2. Then go to a release template and go to the release summary view -3. Add the Sonar Tile from the drop down list +3. Add the Sonar Tile from the drop down list. Provide a project id. eg. ant-master 4. Specify what all metrics you want to show in summary ( Keys are the key used as Sonar metrics URI params, Value part is a Nice to Show Header for that metric) -![Configuration] (/images/snapshot1.png) +![Configuration](images/snapshot2.png) 5. On saving, you'll get the Preview. You can even click on the Data items represented as hyperlinks that take you back to the Sonar Dashboard in a separate browser. -![Preview] (/images/snapshot2.png) +![Preview](images/snapshot3.png) diff --git a/build.gradle b/build.gradle index de56f16..0e8186f 100755 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id "com.xebialabs.xl.docker" version "1.0.0" } -version="1.0.0" +version="v1.1.0" apply plugin: 'java' apply plugin: 'idea' diff --git a/images/snapshot1.png b/images/snapshot1.png old mode 100755 new mode 100644 index d3b1c32..f181358 Binary files a/images/snapshot1.png and b/images/snapshot1.png differ diff --git a/images/snapshot2.png b/images/snapshot2.png old mode 100755 new mode 100644 index 295f6ae..a3e5259 Binary files a/images/snapshot2.png and b/images/snapshot2.png differ diff --git a/images/snapshot3.png b/images/snapshot3.png new file mode 100644 index 0000000..c102b61 Binary files /dev/null and b/images/snapshot3.png differ diff --git a/src/main/resources/sonar/SonarSummaryTile.py b/src/main/resources/sonar/SonarSummaryTile.py index 55e79ba..ae80582 100755 --- a/src/main/resources/sonar/SonarSummaryTile.py +++ b/src/main/resources/sonar/SonarSummaryTile.py @@ -4,7 +4,8 @@ # FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS. # -import com.xhaus.jyson.JysonCodec as json +import json +from xlrelease.HttpRequest import HttpRequest if not sonarServer: raise Exception("Sonar server ID must be provided") @@ -19,34 +20,21 @@ content = None RESPONSE_OK_STATUS = 200 print "Sending content %s" % content - -def get_row_data(item): - row_map = {} - for column in detailsViewColumns: - if detailsViewColumns[column] and "." in detailsViewColumns[column]: - json_col = detailsViewColumns[column].split('.') - if item[json_col[0]]: - row_map[column] = item[json_col[0]][json_col[1]] - else: - row_map[column] = item[column] - row_map['link'] = sonarUrl + "nav_to.do?uri=%s.do?sys_id=%s" % (tableName, item['sys_id']) - return row_map -sonarServerAPIUrl = sonarUrl + '/api/resources?resource=%s&metrics=%s' % (resource,','.join(metrics.keys())) -print sonarServerAPIUrl -sonarResponse = XLRequest(sonarServerAPIUrl, 'GET', content, credentials['username'], credentials['password'], 'application/json').send() +sonarServerAPIUrl = '/api/measures/component?componentKey=%s&metricKeys=%s' % (resource,','.join(metrics.keys())) +http_request = HttpRequest(sonarServer, credentials['username'], credentials['password']) +sonarResponse = http_request.get(sonarServerAPIUrl) if sonarResponse.status == RESPONSE_OK_STATUS: - json_data = json.loads(sonarResponse.read()) + json_data = json.loads(sonarResponse.getResponse()) data1 = {} - data1['id'] = json_data[0]['id'] - data1['key'] = json_data[0]['key'] - data1['name'] = json_data[0]['name'] - data1['version'] = json_data[0]['version'] + data1['id'] = json_data['component']['id'] + data1['key'] = json_data['component']['key'] + data1['name'] = json_data['component']['name'] data1['sonarUrl'] = sonarUrl - for item in json_data[0]['msr']: - data1[item['key']] = item['val'] + for item in json_data['component']['measures']: + data1[item['metric']] = item['value'] data = data1 else: - error = json.loads(sonarResponse.read()) + error = json.loads(sonarResponse.getResponse()) if 'Invalid table' in error['error']['message']: print "Invalid Table Name" data = {"Invalid table name"} @@ -54,4 +42,4 @@ def get_row_data(item): else: print "Failed to run query in Sonar" sonarResponse.errorDump() - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/src/main/resources/synthetic.xml b/src/main/resources/synthetic.xml index 414b5a3..43ff32c 100755 --- a/src/main/resources/synthetic.xml +++ b/src/main/resources/synthetic.xml @@ -6,7 +6,10 @@ --> - + +