-
Notifications
You must be signed in to change notification settings - Fork 21
/
appveyor.ps1
157 lines (131 loc) · 3.8 KB
/
appveyor.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
$ErrorActionPreference = "Stop"
function FetchAndUnzip
{
param ([string]$Url, [string]$Out)
$tmp = [System.IO.Path]::GetTempFileName()
[System.Reflection.Assembly]::LoadWithPartialName('System.Net.Http') | Out-Null
$client = (New-Object System.Net.Http.HttpClient)
try
{
if (-not([string]::IsNullOrEmpty($env:GITHUB_TOKEN)))
{
$credentials = [string]::Format([System.Globalization.CultureInfo]::InvariantCulture, "{0}:", $env:GITHUB_TOKEN);
$credentials = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials));
$client.DefaultRequestHeaders.Authorization = (New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", $credentials));
}
$contents = $client.GetByteArrayAsync($url).Result;
[System.IO.File]::WriteAllBytes($tmp, $contents);
}
finally
{
$client.Dispose()
}
if (-not(Test-Path $Out))
{
mkdir $Out | Out-Null
}
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmp, $Out)
}
function InstallAppveyorTools
{
$travisUtilsVersion = "16"
$localPath = "$env:USERPROFILE\.local"
$travisUtilsPath = "$localPath\travis-utils-$travisUtilsVersion"
if (Test-Path $travisUtilsPath)
{
echo "Reusing the Travis Utils version $travisUtilsVersion already downloaded under $travisUtilsPath"
}
else
{
$url = "https://github.com/SonarSource/travis-utils/archive/v$travisUtilsVersion.zip"
echo "Downloading Travis Utils version $travisUtilsVersion from $url into $localPath"
FetchAndUnzip $url $localPath
}
$mavenLocalRepository = "$env:USERPROFILE\.m2\repository"
if (-not(Test-Path $mavenLocalRepository))
{
mkdir $mavenLocalRepository | Out-Null
}
echo "Installating Travis Utils closed source Maven projects into $mavenLocalRepository"
Copy-Item "$travisUtilsPath\m2repo\*" $mavenLocalRepository -Force -Recurse
$env:ORCHESTRATOR_CONFIG_URL = ""
$env:TRAVIS = "ORCH-332"
}
function Build
{
param ([string]$Project, [string]$Sha1)
$msg = "Fetch [" + $Project + ":" + $Sha1 + "]"
echo $msg
$url = "https://github.com/$Project/archive/$Sha1.zip"
$tmp = "c:\snapshot"
if (Test-Path $tmp)
{
Cmd /C "rmdir /S /Q $tmp"
}
FetchAndUnzip $url $tmp
$msg = "Build [" + $Project + ":" + $Sha1 + "]"
echo $msg
pushd $tmp\*
try
{
mvn install "--batch-mode" "-DskipTests" "-Pdev"
CheckLastExitCode
}
finally
{
popd
}
}
function BuildSnapshot
{
param ([string]$Project)
echo "Fetch and build snapshot of [$Project]"
Build $Project "HEAD"
}
function CheckLastExitCode
{
param ([int[]]$SuccessCodes = @(0))
if ($SuccessCodes -notcontains $LastExitCode)
{
$msg = @"
EXE RETURNED EXIT CODE $LastExitCode
CALLSTACK:$(Get-PSCallStack | Out-String)
"@
throw $msg
}
}
switch ($env:RUN_ITS)
{
"false"
{
InstallAppveyorTools
mvn verify "--batch-mode" "-B" "-e" "-V"
CheckLastExitCode
}
"true"
{
InstallAppveyorTools
mvn package "--batch-mode" "-Dsource.skip=true" "-Denforcer.skip=true" "-Danimal.sniffer.skip=true" "-Dmaven.test.skip=true"
CheckLastExitCode
if ($env:SQ_VERSION -eq "DEV")
{
BuildSnapshot "SonarSource/sonarqube"
}
pushd its/plugin
try
{
mvn install "--batch-mode" "-DcsharpVersion=4.1" "-Dsonar.runtimeVersion=$env:SQ_VERSION" "-Dmaven.test.redirectTestOutputToFile=false" "-Dsonar.jdbc.dialect=embedded" "-Dorchestrator.updateCenterUrl=http://update.sonarsource.org/update-center-dev.properties" "-Dmaven.localRepository=$env:USERPROFILE\.m2\repository"
Push-AppveyorArtifact "C:\projects\sonar-resharper\target\sonar-resharper-plugin.jar" -FileName "sonar-resharper-plugin-v$env:APPVEYOR_BUILD_VERSION-$env:SQ_POSTFIX.jar"
CheckLastExitCode
}
finally
{
popd
}
}
default
{
throw "RUN_ITS should be set to either ""true"" or ""false"", not: ""$env:RUN_ITS"""
}
}