Quantcast

Link Crucible with Sonar

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Link Crucible with Sonar

Alistair Todd
If you use Crucible for code reviews and Sonar for all the wonderful things Sonar does, then here's an easy way to open Sonar reports for files you're looking at in Crucible.

Install these two greasemonkey scripts, first changing the values for your-crucible-server and your-sonar-server in the "match" tag and in the Javascript.

(Chrome users - save these two scripts in files with ".user.js" extensions. Open chrome://chrome/extensions/ then drag the files onto the screen and click add)

Now, when looking at a file review in Crucible, the filename at the top is clickable. A new tab opens. If there is only one match in Sonar, you will be taken straight to the page for that resource, otherwise you'll get a list of search results, with a link to open the Sonar page in a new tab.

This is just a quick hack - I'm sure there are people who can make this much cleaner and more robust. 

If you do come up with improvements, please post them back here!

Thanks,
Al

1) Make class name at the top of a Crucible page clickable to search Sonar:

// ==UserScript==
// @name       Crucible to Sonar Search Clickable Class Names Userscript
// @namespace  http://agilejava.co.uk/
// @version    0.1
// @description  Makes java class names in crucible clickable to perform Sonar search
// @match      https://your-crucible-server/fisheye/cru/*
// @copyright  2012+, Alistair Todd Ltd
// ==/UserScript==

var filenames = document.evaluate("//span[contains(@class, 'path')]/span[contains(@class, 'path-basename')]", document,  null,  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,  null);

for(var i=0; i<filenames.snapshotLength; i++){
    
    var filename = filenames.snapshotItem(i);    
    var filenameText = filename.innerHTML;
    
    if(filenameText.indexOf(".java") != -1){        
        var searchText = filenameText.substring(0,filenameText.indexOf(".java"));        
        filename.innerHTML="<a href='http://your-sonar-server:9000/search?s=" + searchText + "' target=_blank>" + filenameText + "</a>"       
     }
}


2) Make the Sonar search results clickable to open the resource in Sonar

// ==UserScript==
// @name       Sonar Linkable Search Results Userscript
// @namespace  http://agilejava.co.uk/
// @version    0.1
// @description  Makes clickable links for a sonar search results page
// @include      http://your-sonar-server:9000/search*
// @copyright  2012+, Alistair Todd Ltd
// ==/UserScript==


var allListItems, listItem;
allListItems = document.evaluate('//li', document,  null,  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,  null);

if(allListItems.snapshotLength == 1){ 
 var listItem = allListItems.snapshotItem(0);  
 var link="http://your-sonar-server:9000/dashboard/index/"+listItem.id; 
 window.location.replace(link);
}

for(var i=0; i<allListItems.snapshotLength;i++){    
 var listItem = allListItems.snapshotItem(i);  
 var text=listItem.innerHTML;
 listItem.innerHTML=text+" <a href='http:// your-sonar-server :9000/dashboard/index/"+listItem.id+"' target=_blank>Click To View</a>";
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Link Crucible with Sonar

Freddy Mallet
Thanks Alistair for having shared this greasemonkey scripts !

As you're mentioning Crucible and Code Review, FYI we've started thinking about a way to really monitor, review and validate all new incoming changes directly from Sonar. I hope we'll be able to make some progress toward this direction in the upcoming months.
-----
Sonar for Continuous Inspection



On Wed, Sep 12, 2012 at 12:18 PM, Alistair Todd <[hidden email]> wrote:
If you use Crucible for code reviews and Sonar for all the wonderful things Sonar does, then here's an easy way to open Sonar reports for files you're looking at in Crucible.

Install these two greasemonkey scripts, first changing the values for your-crucible-server and your-sonar-server in the "match" tag and in the Javascript.

(Chrome users - save these two scripts in files with ".user.js" extensions. Open chrome://chrome/extensions/ then drag the files onto the screen and click add)

Now, when looking at a file review in Crucible, the filename at the top is clickable. A new tab opens. If there is only one match in Sonar, you will be taken straight to the page for that resource, otherwise you'll get a list of search results, with a link to open the Sonar page in a new tab.

This is just a quick hack - I'm sure there are people who can make this much cleaner and more robust. 

If you do come up with improvements, please post them back here!

Thanks,
Al

1) Make class name at the top of a Crucible page clickable to search Sonar:

// ==UserScript==
// @name       Crucible to Sonar Search Clickable Class Names Userscript
// @namespace  http://agilejava.co.uk/
// @version    0.1
// @description  Makes java class names in crucible clickable to perform Sonar search
// @copyright  2012+, Alistair Todd Ltd
// ==/UserScript==

var filenames = document.evaluate("//span[contains(@class, 'path')]/span[contains(@class, 'path-basename')]", document,  null,  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,  null);

for(var i=0; i<filenames.snapshotLength; i++){
    
    var filename = filenames.snapshotItem(i);    
    var filenameText = filename.innerHTML;
    
    if(filenameText.indexOf(".java") != -1){        
        var searchText = filenameText.substring(0,filenameText.indexOf(".java"));        
        filename.innerHTML="<a href='http://your-sonar-server:9000/search?s=" + searchText + "' target=_blank>" + filenameText + "</a>"       
     }
}


2) Make the Sonar search results clickable to open the resource in Sonar

// ==UserScript==
// @name       Sonar Linkable Search Results Userscript
// @namespace  http://agilejava.co.uk/
// @version    0.1
// @description  Makes clickable links for a sonar search results page
// @copyright  2012+, Alistair Todd Ltd
// ==/UserScript==


var allListItems, listItem;
allListItems = document.evaluate('//li', document,  null,  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,  null);

if(allListItems.snapshotLength == 1){ 
 var listItem = allListItems.snapshotItem(0);  
 window.location.replace(link);
}

for(var i=0; i<allListItems.snapshotLength;i++){    
 var listItem = allListItems.snapshotItem(i);  
 var text=listItem.innerHTML;
 listItem.innerHTML=text+" <a href='http:// your-sonar-server :9000/dashboard/index/"+listItem.id+"' target=_blank>Click To View</a>";
}


Loading...