IMPORTANT:
|
Integrate NDepend v6 with SonarQube
- Plugin Prerequisites
- Install the NDepend Plugin
- Generate the set of NDepend Rules that will be configured into the SonarQube server
- Start SonarQube
- Configure the NDepend Rules in the SonarQube server
- Activate the NDepend Rules in the SonarQube server
- Run MSBuild Sonar-Runner
- Browse NDepend Rules Issues in the SonarQube UI
IMPORTANT:
|
Plugin Prerequisites
Install SonarQube
Download http://www.sonarqube.org/downloads/
Install SonarRunner
Download http://www.sonarqube.org/downloads/
Install doc http://docs.sonarqube.org/display/SONAR/Installing+and+Configuring+SonarQube+Runner
Install the C# sonar plugin sonar-csharp-plugin
Download http://www.sonarsource.com/products/plugins/languages/c-sharp/
Copy the sonar-csharp-plugin-VERSION.jar to the $SonarQubeInstallDir$\extensions\plugins directory.
Install the NDepend Plugin
- from the $NDependInstallDir$\Integration\SonarQube directory
- to the $SonarQubeInstallDir$\extensions\plugins directory
Copy the sonar-ndepend-plugin-VERSION.jar
Notice that this plugin is open sourced at: https://github.com/SonarCommunity/sonar-ndepend
Generate the set of NDepend Rules that will be configured into the Sonar server
Generate the NDepend rules set to configure into SonarQube, using the executable:
$NDependInstallDir$\Integration\SonarQube\NDepend.SonarQube.RuleSetBuilder.exe
that takes 2 command line arguments:
- The absolute file path of the NDepend project file (file name extension .ndproj)
- The absolute file path of the output XML file path (file name extension extension .xml). Later we'll explain how to use its XML content.
Notice that the rules taken account are activated rules defined in:
- The NDepend project file,
- Rules defined in the NDepend Rules Files referenced by the NDepend project file
- and NDepend rules defined in source code
IMPORTANT:
|
Start Sonar
Start Sonar : for example on a Windows x64 machine do: $SonarQubeInstallDir$\bin\windows-x86-64\StartSonar.
Note that the communication from NDepend to SonarQube occurs through XML files: hence NDepend must run on Windows but the SonarQube server can run on any OS.
In a browser open http://localhost:9000/ and log to SonarQube as admin.
Configure the NDepend Rules in the Sonar server
-
From the SonarQube web UI, go to Settings > NDepend and:
- In the NDepend Rules textbox, set the XML content of the XML file generated by NDepend.SonarQube.RuleSetBuilder.exe (see above).
In the Path to textbox, set the NDepend.SonarQube.RuleRunner.exe absolute path.
This executable can be found under $NDependInstallDir$\Integration\SonarQube\NDepend.SonarQube.RuleRunner.exe
Don't prefix the path with an environnement variable path, write the entire variable path.
Click Save and restart Sonar.
NOTE:
|
Activate the NDepend Rules in the Sonar server
- log as admin in the SonarQube UI
- go to the Rules tab
- choose the NDepend C# repository
- and activate these rules in the profile you want by clicking on Bulk Change -> Activate In
The NDepend rules are now loaded in the SonarQube repository but not activated yet.
To activate them, you have to:
Run MSBuild Sonar-Runner
Here is the SonarQube documentation concerning runnig MSBuild Sonar-Runner from the command line argument.
Make sure to add the path to the NDepend project file (.ndproj extension) this way:
SonarQube.Scanner.MSBuild.exe begin /key:{SonarQube project key} /name:{SQ project name} /version:{SQ project version} /d:sonar.cs.ndepend.projectPath={the path of ndproj}
IMPORTANT:
|
What if I run Sonar on a Linux machine and NDepend on a Windows machine?
|
By default the NDepend analysis is executed by the ndepend sonar plugin. However you can launch the analysis before the sonar execution using the RulesRunner.exe command...
SonarQube\NDepend.SonarQube.RuleRunner.exe C:\work\project.ndproj C:\work\ndepend-report.xml
...and give the result file to the sonar plugin using the sonar.cs.ndepend.reportPath variable
/d:sonar.cs.ndepend.reportPath=C:\work\ndepend-report.xml
In this case the sonar plugin will use the result file and will not launch the ndepend analysis.
This possibility could be used for the MultiModule sonar projects where the NDepend analysis could be executed many times for each module. Executing NDepend once you will gain in performance.
REMARKS:
|
Browse NDepend Rules Issues in the SonarQube UI
NDepend Rules Issues are now reported as any issues in the SonarQube UI.
You can browse it, go to source code declaration (in the UI), assign it, change its status...