Skip to content

Commit

Permalink
Merge pull request #1172 from Slesa/NewSonarOptions
Browse files Browse the repository at this point in the history
New sonar options
  • Loading branch information
forki committed Mar 13, 2016
2 parents 58dce73 + de38a92 commit ca959b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
29 changes: 27 additions & 2 deletions help/sonarcube.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ compilation has finished. Then the result is collected and send to the SonarQube
{p with
Key = "MyProject"
Name = "Main solution"
Version = "1.0.0" })
Version = "1.0.0" }
)

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

Target "Default" DoNothing
Expand All @@ -45,3 +45,28 @@ compilation has finished. Then the result is collected and send to the SonarQube
RunTargetOrDefault "Default"

The MSBuild runner is searched in 'tools/SonarQube'. This can be overwritten with the ToolsPath property of the parameters.

## Additional options for SonarQube

* You can send additional global settings to the server with the '/d:' parameter.
In the SonarQubeParams, this is the new field Settings:

SonarQube Begin (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Version = "1.0.0"
Settings = ["sonar.debug"; "sonar.newversion"] }
)

* Configuration can also be read from a configuration file. This is the '/s:' parameter.
This can be done with the new field Config:

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

23 changes: 20 additions & 3 deletions src/app/FakeLib/SonarQubeHelper.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Contains a task to run the msbuild runner of [Sonar Qube analyzer](http://sonarqube.org).
module Fake.SonarQubeHelper
open TraceHelper

/// The supported commands of Sonar Qube. It is called with Begin before compilation, and End after compilation.
type SonarQubeCall = Begin | End
Expand All @@ -14,21 +15,37 @@ type SonarQubeParams =
Name : string
/// Version number of the project
Version : string
/// Individual global settings for SonarQube
Settings : List<string>
/// Read settings from configuration file
Config : string option
}

/// 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" }
Version = "1.0"
Settings = []
Config = None }

/// 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 + "\""
let setArgs = parameters.Settings |> List.fold (fun acc x -> acc + "/d:"+x+" ") ""
//match parameters.Settings with
//| Some(x) -> (" /d:"+x)
//| None -> ""
let cfgArgs =
match parameters.Config with
| Some(x) -> (" /s:"+x)
| None -> ""
let args =
match call with
| Begin -> "begin /k:\"" + parameters.Key + "\" /n:\"" + parameters.Name + "\" /v:\"" + parameters.Version + "\" " + setArgs + cfgArgs
| End -> "end"

let result =
ExecProcess (fun info ->
info.FileName <- sonarPath
Expand Down

0 comments on commit ca959b4

Please sign in to comment.