Skip to content

Commit

Permalink
Changes to plugin for working with Sonar Version 5.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmohleji committed Mar 23, 2017
1 parent 2fde93d commit 8eff881
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 33 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file modified images/snapshot1.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/snapshot2.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/snapshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 13 additions & 25 deletions src/main/resources/sonar/SonarSummaryTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -19,39 +20,26 @@
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"}
sonarResponse.errorDump()
else:
print "Failed to run query in Sonar"
sonarResponse.errorDump()
sys.exit(1)
sys.exit(1)
5 changes: 4 additions & 1 deletion src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
-->
<synthetic xsi:schemaLocation="http://www.xebialabs.com/deployit/synthetic synthetic.xsd" xmlns="http://www.xebialabs.com/deployit/synthetic" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<type type="sonarqube.Server" extends="configuration.HttpConnection"/>
<type type="sonarqube.Server" extends="configuration.HttpConnection">
<property name="checkConfigurationPath" hidden="true" default="/api"/>
<property name="scriptLocation" hidden="true" default="configuration/HttpConnectionCheck.py"/>
</type>

<type type="sonar.SonarSummaryTile" label="sonar Summary Tile query tile" extends="xlrelease.Tile">
<property name="uri" hidden="true" default="include/SonarSummaryTile/sonar-query-summary-view.html" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
var keyName = Object.getOwnPropertyNames(sonardata)[metric];
var finalKeyName = tile.configurationProperties.metrics.value[keyName];
switch(keyName){
case 'key' : result[keyName] = { key : 'Project Key', value : sonardata[keyName], url : sonardata['sonarUrl'] + '/dashboard/index/' + sonardata['id']}; break;
case 'key' : result[keyName] = { key : 'Project Key', value : sonardata[keyName], url : sonardata['sonarUrl'] + '/overview?id=' + sonardata['key']}; break;
case 'version' : result[keyName] = { key : 'Arfifact Version', value : sonardata[keyName]}; break;
case 'name' : break;
case 'id' : break;
case 'sonarUrl' : break;
default : result[keyName] = { key : finalKeyName, value : sonardata[keyName], url : sonardata['sonarUrl'] + '/drilldown/measures/' + sonardata['id'] + '?metric=' + keyName};
default : result[keyName] = { key : finalKeyName, value : sonardata[keyName], url : sonardata['sonarUrl'] + '/component_measures/metric/' + keyName + '/list?id=' + sonardata['key']};

}

Expand Down

0 comments on commit 8eff881

Please sign in to comment.