Skip to content

Commit

Permalink
Merge pull request #1583 from laedit/SonarQube-migration
Browse files Browse the repository at this point in the history
Sonarqube migration
  • Loading branch information
matthid authored Jun 11, 2017
2 parents 3275c96 + e0d6538 commit fb73333
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 9 deletions.
1 change: 0 additions & 1 deletion FAKE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "help", "help", "{564BD198-0
help\nuget.md = help\nuget.md
help\octopusdeploy.md = help\octopusdeploy.md
help\slacknotification.md = help\slacknotification.md
help\sonarcube.md = help\sonarcube.md
help\specifictargets.md = help\specifictargets.md
help\teamcity.md = help\teamcity.md
help\typescript.md = help\typescript.md
Expand Down
3 changes: 2 additions & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ let dotnetAssemblyInfos =
"Fake.Tools.Git", "Running git commands"
"Fake.Testing.Common", "Common testing data types"
"Fake.Tracing.NAntXml", "NAntXml"
"Fake.Windows.Chocolatey", "Running and packaging with Chocolatey" ]
"Fake.Windows.Chocolatey", "Running and packaging with Chocolatey"
"Fake.Testing.SonarQube", "Analyzing your project with SonarQube" ]

let assemblyInfos =
[ "./src/app/FAKE/AssemblyInfo.fs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Analyze your code with SonarQube

**Note: This documentation is for FAKE.exe before version 5 (or the non-netcore version). The documentation needs te be updated, please help! **

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"

Expand All @@ -16,8 +14,10 @@ compilation has finished. The result is then collected and sent to the SonarQube

## Minimal working example

open Fake.Testing

Target "BeginSonarQube" (fun _ ->
SonarQube Begin (fun p ->
SonarQube.Begin (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Expand All @@ -26,7 +26,7 @@ compilation has finished. The result is then collected and sent to the SonarQube
)

Target "EndSonarQube" (fun _ ->
SonarQubeEnd()
SonarQube.End None
)

Target "Default" DoNothing
Expand All @@ -49,7 +49,7 @@ By default, the SonarQube module looks for the MSBuild runner in the 'tools/Sona
* 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 ->
SonarQube.Begin (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Expand All @@ -60,7 +60,7 @@ In the SonarQubeParams, this is the new field Settings:
* 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 ->
SonarQube.Begin (fun p ->
{p with
Key = "MyProject"
Name = "Main solution"
Expand Down
7 changes: 6 additions & 1 deletion help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
<li><a href="@(prefix)windows-chocolatey.html">Chocolatey</a></li>
</ul>
</li>
<li>
<a href="@(prefix)404.html">Testing</a>
<ul>
<li><a href="@(prefix)testing-sonarqube.html">SonarQube</a></li>
</ul>
</li>
<li>
<a href="@(prefix)404.html">Legacy / Not Migrated</a>
<ul>
Expand All @@ -119,7 +125,6 @@
<li><a href="@(prefix)todo-wix.html">Windows.WiX</a></li>
<li><a href="@(prefix)todo-slacknotification.html">API.Slack</a></li>
<li><a href="@(prefix)todo-msteamsnotification.html">API.MsTeams</a></li>
<li><a href="@(prefix)todo-sonarcube.html">Testing.SonarQube</a></li>
<li><a href="@(prefix)todo-stylecop.html">DotNet.StyleCop</a></li>
<li><a href="@(prefix)todo-deploy.html">Fake.Deploy</a></li>
<li><a href="@(prefix)todo-iis.html">?.?.IIS</a></li>
Expand Down
15 changes: 15 additions & 0 deletions src/Fake-netcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.DotNet.Paket", "app\Fa
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.netcore", "app\Fake.netcore\Fake.netcore.fsproj", "{6B339DA3-8DED-4262-A427-3C4CCDD00650}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Testing.SonarQube", "app\Fake.Testing.SonarQube\Fake.Testing.SonarQube.fsproj", "{2A985028-4410-40F7-992C-5397DC1ED116}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -410,6 +412,18 @@ Global
{CDFB2B10-050A-4188-8F72-2BCC61E9814F}.Release|x64.Build.0 = Release|x64
{CDFB2B10-050A-4188-8F72-2BCC61E9814F}.Release|x86.ActiveCfg = Release|x86
{CDFB2B10-050A-4188-8F72-2BCC61E9814F}.Release|x86.Build.0 = Release|x86
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|x64.ActiveCfg = Debug|x64
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|x64.Build.0 = Debug|x64
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|x86.ActiveCfg = Debug|x86
{2A985028-4410-40F7-992C-5397DC1ED116}.Debug|x86.Build.0 = Debug|x86
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|Any CPU.Build.0 = Release|Any CPU
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|x64.ActiveCfg = Release|x64
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|x64.Build.0 = Release|x64
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|x86.ActiveCfg = Release|x86
{2A985028-4410-40F7-992C-5397DC1ED116}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E2CF8635-E7C4-4470-92DD-F706F052BF7B} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
Expand Down Expand Up @@ -440,5 +454,6 @@ Global
{E32B2631-476A-4C2D-AE18-275ED7A22F10} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{80314941-78D5-4928-B943-93FC945E050F} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{CDFB2B10-050A-4188-8F72-2BCC61E9814F} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{2A985028-4410-40F7-992C-5397DC1ED116} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions src/app/Fake.Testing.SonarQube/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Analizing your project with SOnarQube")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Analizing your project with SOnarQube"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
34 changes: 34 additions & 0 deletions src/app/Fake.Testing.SonarQube/Fake.Testing.SonarQube.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>1.0.0-alpha-10</VersionPrefix>
<TargetFramework>netstandard1.6</TargetFramework>
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants>
<DebugType>pdbonly</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Fake.Testing.SonarQube</AssemblyName>
<OutputType>Library</OutputType>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);portable-net45+win8;dnxcore50</PackageTargetFallback>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
<DefineConstants>$(DefineConstants);NETSTANDARD;USE_HTTPCLIENT</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="SonarQube.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Tracing\Fake.Core.Tracing.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.Core.Globbing\Fake.Core.Globbing.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-compile-fsc">
<Version>1.0.0-preview2-020000</Version>
</DotNetCliToolReference>
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
101 changes: 101 additions & 0 deletions src/app/Fake.Testing.SonarQube/SonarQube.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/// Contains a task to run the msbuild runner of [SonarQube analyzer](http://sonarqube.org).
module Fake.Testing.SonarQube

open System.IO
open Fake.Core
open Fake.Core.Globbing
open Fake.Core.Process
open Fake.IO.FileSystem.Operators

/// [omit]
/// The supported commands of SonarQube. It is called with Begin before compilation, and End after compilation.
type private SonarQubeCall = Begin | End

/// Parameter type to configure the SonarQube runner.
type SonarQubeParams = {
/// FileName of the SonarQube runner exe.
ToolsPath : string
/// Key to identify the SonarQube project
Key : string
/// Name of the project
Name : string
/// Version number of the project
Version : string
/// Individual global settings for SonarQube
Settings : string list
/// Read settings from configuration file
Config : string option
}

/// SonarQube default parameters - tries to locate MSBuild.SonarQube.exe in any subfolder.
let SonarQubeDefaults =
{ ToolsPath = Tools.findToolInSubPath "MSBuild.SonarQube.Runner.exe" (Directory.GetCurrentDirectory() @@ "tools" @@ "SonarQube")
Key = null
Name = null
Version = "1.0"
Settings = []
Config = None }

/// [omit]
/// Execute the external msbuild runner of SonarQube. Parameters are given to the command line tool as required.
let private SonarQubeCall (call: SonarQubeCall) (parameters : SonarQubeParams) =
let sonarPath = parameters.ToolsPath
let setArgs = parameters.Settings |> List.fold (fun acc x -> acc + "/d:" + x + " ") ""

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 " + setArgs + cfgArgs

let result =
ExecProcess (fun info ->
info.FileName <- sonarPath
info.Arguments <- args) System.TimeSpan.MaxValue
if result <> 0 then failwithf "Error during sonar qube call %s" (call.ToString())

/// This task to can be used to run the begin command of [Sonar Qube](http://sonarqube.org/) on a project.
/// ## Parameters
///
/// - `setParams` - Function used to overwrite the SonarQube default parameters.
///
/// ## Sample
/// open Fake.Testing
///
/// SonarQube.Begin (fun p ->
/// {p with
/// Key = "MyProject"
/// Name = "MainTool"
/// Version = "1.0 })
///
let Begin setParams =
use __ = Trace.traceTask "SonarQube" "Begin"
let parameters = setParams SonarQubeDefaults
SonarQubeCall Begin parameters

/// This task to can be used to run the end command of [Sonar Qube](http://sonarqube.org/) on a project.
/// ## Parameters
///
/// - `setParams` - Function used to overwrite the SonarQube default parameters.
///
/// ## Sample
/// open Fake.Testing
///
/// SonarQube.End None
///
/// SonarQube.End (fun p ->
/// {p with
/// Settings = ["sonar.login=login", "sonar.password=password"] })
///
let End setParams =
use __ = Trace.traceTask "SonarQube" "End"
let parameters = match setParams with
| Some setParams -> setParams SonarQubeDefaults
| None -> (fun p -> { p with Settings = [] }) SonarQubeDefaults
SonarQubeCall End parameters
4 changes: 4 additions & 0 deletions src/app/Fake.Testing.SonarQube/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
group netcore
FSharp.NET.Sdk
FSharp.Core
NETStandard.Library
3 changes: 3 additions & 0 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
<Compile Include="..\Fake.DotNet.Paket\PaketTemplate.fs">
<Link>Fake.DotNet.Paket/PaketTemplate.fs</Link>
</Compile>
<Compile Include="..\Fake.Testing.SonarQube\SonarQube.fs">
<Link>Fake.Testing.SonarQube/SonarQube.fs</Link>
</Compile>
<Compile Include="UserInputHelper.fs" />
<Compile Include="CSharpHelper.fs" />
<Compile Include="EnvironmentHelper.fs" />
Expand Down
7 changes: 7 additions & 0 deletions src/app/FakeLib/SonarQubeHelper.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/// Contains a task to run the msbuild runner of [Sonar Qube analyzer](http://sonarqube.org).
[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
module Fake.SonarQubeHelper
open TraceHelper

/// The supported commands of Sonar Qube. It is called with Begin before compilation, and End after compilation.
[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
type SonarQubeCall = Begin | End

[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
/// Parameter type to configure the sonar qube runner.
[<CLIMutable>]
type SonarQubeParams =
Expand All @@ -22,6 +25,7 @@ type SonarQubeParams =
Config : string option
}

[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
/// SonarQube default parameters - tries to locate MSBuild.SonarQube.exe in any subfolder.
let SonarQubeDefaults =
{ ToolsPath = findToolInSubPath "MSBuild.SonarQube.Runner.exe" (currentDirectory @@ "tools" @@ "SonarQube")
Expand All @@ -31,6 +35,7 @@ let SonarQubeDefaults =
Settings = []
Config = None }

[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
/// 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
Expand Down Expand Up @@ -66,6 +71,7 @@ let SonarQubeCall (call: SonarQubeCall) (parameters : SonarQubeParams) =
/// Name = "MainTool"
/// Version = "1.0 })
///
[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
let SonarQube (call: SonarQubeCall) setParams =
use __ = traceStartTaskUsing "SonarQube" (call.ToString())
let parameters = setParams SonarQubeDefaults
Expand All @@ -77,5 +83,6 @@ let SonarQube (call: SonarQubeCall) setParams =
/// SonarQubeEnd
///
[<System.Obsolete("Use Fake.Testing.SonarQube instead (open Fake.Testing and use 'SonarQube.')")>]
let SonarQubeEnd() =
SonarQube End (fun p -> { p with Settings = [] })

0 comments on commit fb73333

Please sign in to comment.