From 978287fc0b90a83a1895a820f03193dbc855d69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prei=C3=9F?= Date: Fri, 12 Feb 2016 15:04:18 +0100 Subject: [PATCH 1/2] Support for SonarQube --- help/sonarcube.md | 47 ++++++++++++++++++++++++ src/app/FakeLib/FakeLib.fsproj | 1 + src/app/FakeLib/SonarQubeHelper.fs | 57 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 help/sonarcube.md create mode 100644 src/app/FakeLib/SonarQubeHelper.fs diff --git a/help/sonarcube.md b/help/sonarcube.md new file mode 100644 index 00000000000..99973d0d8d1 --- /dev/null +++ b/help/sonarcube.md @@ -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. diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index cf643712a3f..a8fc5000e69 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -174,6 +174,7 @@ + diff --git a/src/app/FakeLib/SonarQubeHelper.fs b/src/app/FakeLib/SonarQubeHelper.fs new file mode 100644 index 00000000000..967e756c67a --- /dev/null +++ b/src/app/FakeLib/SonarQubeHelper.fs @@ -0,0 +1,57 @@ +[] +/// 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()) From acc2d9edf893737ed86b45d867596be30521e43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prei=C3=9F?= Date: Tue, 16 Feb 2016 10:16:20 +0100 Subject: [PATCH 2/2] Add Centigrade as user --- help/users.md | 1 + 1 file changed, 1 insertion(+) diff --git a/help/users.md b/help/users.md index 1aec67a57dc..f6ef7b72617 100644 --- a/help/users.md +++ b/help/users.md @@ -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)