1 $env:SONAR_SCANNER_VERSION = "4.4.0.2170"
2 $env:SONAR_DIRECTORY = [System.IO.Path]::Combine($(get-location).Path,".sonar")
3 $env:SONAR_SCANNER_HOME = "$env:SONAR_DIRECTORY/sonar-scanner-$env:SONAR_SCANNER_VERSION-windows"
4 rm $env:SONAR_SCANNER_HOME -Force -Recurse -ErrorAction SilentlyContinue
5 New-Item -path $env:SONAR_SCANNER_HOME -type directory
6 (New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$env:SONAR_SCANNER_VERSION-windows.zip", "$env:SONAR_DIRECTORY/sonar-scanner.zip")
7 Add-Type -AssemblyName System.IO.Compression.FileSystem
8 [System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/sonar-scanner.zip", "$env:SONAR_DIRECTORY")
9 rm ./.sonar/sonar-scanner.zip -Force -ErrorAction SilentlyContinue
10 $env:SONAR_SCANNER_OPTS="-server"
11 
12 rm "$env:SONAR_DIRECTORY/build-wrapper-win-x86" -Force -Recurse -ErrorAction SilentlyContinue
13 (New-Object System.Net.WebClient).DownloadFile("https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip", "$env:SONAR_DIRECTORY/build-wrapper-win-x86.zip")
14 [System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/build-wrapper-win-x86.zip", "$env:SONAR_DIRECTORY")
15 
16 if ($args[0] -eq "--build") {
17     & $env:SONAR_DIRECTORY/build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir bw-output cmake --build $env:BUILD_DIR
18 } elseif($args[0] -eq "--analyze") {
19     $defines = @(
20         "sonar.organization=owncloud-1",
21         "sonar.projectKey=owncloud_client",
22         "sonar.sources=.",
23         "sonar.cfamily.build-wrapper-output=bw-output",
24         "sonar.host.url=https://sonarcloud.io",
25         "sonar.exclusions=docs/**,man/**,translations/**,admin/**,test/**,src/3rdparty/qtokenizer/test/**",
26         "sonar.cfamily.threads=$env:NUMBER_OF_PROCESSORS",
27         "sonar.cfamily.cache.enabled=true",
28         "sonar.cfamily.cache.path=${HOME}/cache/sonarcloud")
29     for($i = 0; $i -lt $defines.Length; $i++) {
30         $defines[$i] = ("-D{0}" -f $defines[$i])
31     }
32     & $env:SONAR_SCANNER_HOME/bin/sonar-scanner.bat @defines
33 }
34