Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SonarQube support #1140

Merged
merged 2 commits into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions help/sonarcube.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Analyze your code with SonarQube

From the [web page](http://sonarqube.org):
"The SonarQube® platform is an open source quality management platform, dedicated to continuously analyzing and measuring the technical quality of source code, from project portfolio down to the method level"

It can analyze a lot of different programming languages, from PHP, Erlang, Css to Cobol. C# can be installed
with an additional plugin. This must be done on the SonarQube server.
To support the analysis process on a build server, an additional command line tool called "MSBuild.SonarQube.Runner.exe"
must be used. The sonar qube module in FAKE provides a function 'SonarQube' to call this tool with the needed parameters.

This function must be called twice, one time at the beginning of the compilation process and one time after
compilation has finished. Then the result is collected and send to the SonarQube server.


## Minimal working example

Target "BeginSonarQube" (fun _ ->

SonarQube Begin (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Version = "1.0.0" })
)

Target "EndSonarQube" (fun _ ->
SonarQube End (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Version = "1.0.0" })
)

Target "Default" DoNothing

"Clean"
==> "SetAssemblyInfo"
==> "BeginSonarQube"
==> "Build" <=> "BuildTests"
==> "EndSonarQube"
==> "RunTests"
==> "Deploy"
==> "Default"

RunTargetOrDefault "Default"

The MSBuild runner is searched in 'tools/SonarQube'. This can be overwritten with the ToolsPath property of the parameters.
1 change: 1 addition & 0 deletions help/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Some of our users are:
* [Elastacloud](http://elastacloud.com/)
* [Digital Furnace Games](http://digitalfurnacegames.com/)
* [Recognos Romania](http://www.recognos.ro/en)
* [Centigrade GmbH](http://www.centigrade.de)
1 change: 1 addition & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
<Compile Include="DynamicsCRMHelper.fs" />
<Compile Include="Appcast.fs" />
<Compile Include="PicklesHelper.fs" />
<Compile Include="SonarQubeHelper.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
Expand Down
57 changes: 57 additions & 0 deletions src/app/FakeLib/SonarQubeHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[<AutoOpen>]
/// Contains a task to run the msbuild runner of [Sonar Qube analyzer](http://sonarqube.org).
module Fake.SonarQubeHelper

/// The supported commands of Sonar Qube. It is called with Begin before compilation, and End after compilation.
type SonarQubeCall = Begin | End

/// Parameter type to configure the sonar qube runner.
type SonarQubeParams =
{ /// FileName of the sonar qube runner exe.
ToolsPath : string
/// Key to identify the sonar qube project
Key : string
/// Name of the project
Name : string
/// Version number of the project
Version : string
}

/// SonarQube default parameters - tries to locate MSBuild.SonarQube.exe in any subfolder.
let SonarQubeDefaults =
{ ToolsPath = findToolInSubPath "MSBuild.SonarQube.Runner.exe" (currentDirectory @@ "tools" @@ "SonarQube")
Key = null
Name = null
Version = "1.0" }

/// Execute the external msbuild runner of Sonar Qube. Parameters are fiven to the command line tool as required.
let SonarQubeCall (call: SonarQubeCall) (parameters : SonarQubeParams) =
let sonarPath = parameters.ToolsPath
let args = match call with
| Begin -> "begin /k:\"" + parameters.Key + "\" /n:\"" + parameters.Name + "\" /v:\"" + parameters.Version + "\""
| End -> "end"
let result =
ExecProcess (fun info ->
info.FileName <- sonarPath
info.Arguments <- args) System.TimeSpan.MaxValue
if result <> 0 then failwithf "Error during sonar qube call " (call.ToString())

/// This task to can be used to run [Sonar Qube](http://conarqube.org/) on a project.
/// ## Parameters
///
/// - `call` - Begin or End, to start analysis or finish it
/// - `setParams` - Function used to overwrite the SonarQube default parameters.
///
/// ## Sample

/// SonarQube Begin (fun p ->
/// {p with
/// Key = "MyProject"
/// Name = "MainTool"
/// Version = "1.0 })
///
let SonarQube (call: SonarQubeCall) setParams =
traceStartTask "SonarQube" (call.ToString())
let parameters = setParams SonarQubeDefaults
SonarQubeCall call parameters
traceEndTask "SonarQube" (call.ToString())