-
Notifications
You must be signed in to change notification settings - Fork 19
/
install-plugin.ps1
210 lines (163 loc) · 7.1 KB
/
install-plugin.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$PluginId = "Machine.Specifications.Runner.Resharper9"
$RootSuffix = "ReSharper"
$ResharperUrl = "https://data.services.jetbrains.com/products/releases?code=RSU&type=release"
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$Version = "0.1.0"
$MainProject = "$PSScriptRoot\src\Machine.Specifications.Runner.ReSharper\Machine.Specifications.Runner.ReSharper.csproj"
$NugetExe = "$PSScriptRoot\tools\nuget.exe"
Function Invoke-Exe {
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[String]
$Executable,
[Parameter(ValueFromRemainingArguments = $true)]
[String[]]
$Arguments
)
Write-Host "> $Executable $Arguments"
$result = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru
if (-Not $result.ExitCode -eq 0) {
throw "'$Executable $Arguments' failed with exit code $($result.ExitCode)"
}
}
Function Write-User-Settings {
param(
[Parameter(Mandatory = $true)]
[String]
$HostIdentifier,
[Parameter(Mandatory = $true)]
[String]
$UserProjectFile
)
if (!(Test-Path "$UserProjectFile")) {
Set-Content -Path "$UserProjectFile" -Value "<Project><PropertyGroup Condition=`"'`$(Configuration)' == 'Debug'`"><HostFullIdentifier></HostFullIdentifier></PropertyGroup></Project>"
}
$xml = [xml] (Get-Content "$UserProjectFile")
$node = $xml.SelectSingleNode(".//HostFullIdentifier")
$node.InnerText = $HostIdentifier
$xml.Save("$UserProjectFile")
}
Function Read-SdkVersion {
$xml = [xml] (Get-Content "$MainProject")
$node = $xml.SelectSingleNode(".//SdkVersion")
if ($null -eq $node) {
throw "SdkVersion not found in '$MainProject'"
}
$value = $node.InnerText
return $value.Substring(2, 2) + $value.Substring(5, 1)
}
Function Write-Nuspec {
param(
[Parameter(Mandatory=$true)]
[String]
$NuspecFile
)
$sdkVersion = Read-SdkVersion
$nextSdkVersion = [int]$sdkVersion + 1
$nuspec = @'
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Machine.Specifications.Runner.Resharper9</id>
<version>{0}</version>
<authors>Machine Specifications</authors>
<description>Machine Specifications</description>
<dependencies>
<dependency id="Wave" version="[{1}.0, {2})" />
</dependencies>
</metadata>
<files>
<file src="..\src\Machine.Specifications.Runner.ReSharper\bin\Debug\net461\Machine.Specifications.Runner.ReSharper.dll" target="DotFiles" />
<file src="..\src\Machine.Specifications.Runner.ReSharper\bin\Debug\net461\Machine.Specifications.Runner.Utility.dll" target="DotFiles" />
<file src="..\src\Machine.Specifications.Runner.ReSharper.Adapters\bin\Debug\net461\Machine.Specifications.Runner.ReSharper.Adapters.net461.dll" target="DotFiles" />
<file src="..\src\Machine.Specifications.Runner.ReSharper.Tasks\bin\Debug\net461\Machine.Specifications.Runner.ReSharper.Tasks.net461.dll" target="DotFiles" />
<file src="..\src\Machine.Specifications.Runner.ReSharper.Adapters\bin\Debug\netstandard2.0\Machine.Specifications.Runner.ReSharper.Adapters.netstandard20.dll" target="DotFiles" />
<file src="..\src\Machine.Specifications.Runner.ReSharper.Tasks\bin\Debug\netstandard2.0\Machine.Specifications.Runner.ReSharper.Tasks.netstandard20.dll" target="DotFiles" />
</files>
</package>
'@ -f $Version,$sdkVersion,$nextSdkVersion
Set-Content -Path "$NuspecFile" -Value $nuspec
}
Function Get-ToolPath {
param(
[Parameter(Mandatory = $true)]
[String]
$ToolUrl
)
$file = $ToolUrl.Substring($ToolUrl.LastIndexOf("/") + 1)
return "$PSScriptRoot\tools\" + $file
}
Function Get-Tool {
param(
[Parameter(Mandatory = $true)]
[String]
$ToolUrl
)
$file = Get-ToolPath $ToolUrl
if (!(Test-Path $file)) {
mkdir -Force $(Split-Path $file -Parent) > $null
Write-Output "Downloading from $ToolUrl"
(New-Object System.Net.WebClient).DownloadFile($ToolUrl, $file)
} else {
$filename = $file.Substring($file.LastIndexOf("\") + 1)
Write-Output "Using $($filename) from cache"
}
}
Function Install-Hive {
param(
[Parameter(Mandatory = $true)]
[String]
$InstallerFile
)
Write-Output "Installing experimental hive"
Invoke-Exe $InstallerFile "/SpecificProductNames=ReSharper" "/Hive=$RootSuffix" "/VsVersion=15.0;16.0" "/Silent=True"
}
Function Get-InstallationPath {
$version = Read-SdkVersion
return $(Get-ChildItem "$env:APPDATA\JetBrains\ReSharperPlatformVs*\v$version`_*$RootSuffix\NuGet.Config" | Sort-Object | Select-Object -Last 1).Directory
}
Function Save-PackagesConfig {
$installPath = Get-InstallationPath
if (Test-Path "$installPath\packages.config") {
$xml = [xml] (Get-Content "$installPath\packages.config")
} else {
$xml = [xml] ("<?xml version=`"1.0`" encoding=`"utf-8`"?><packages></packages>")
}
if ($null -eq $xml.SelectSingleNode(".//package[@id='$PluginId']/@id")) {
$pluginNode = $xml.CreateElement('package')
$pluginNode.setAttribute("id", "$PluginId")
$pluginNode.setAttribute("version", "$Version")
$packagesNode = $xml.SelectSingleNode("//packages")
$packagesNode.AppendChild($PluginNode) > $null
$xml.Save("$installPath\packages.config")
}
}
# Download tools
$url = [uri] $(Invoke-WebRequest -UseBasicParsing $ResharperUrl | ConvertFrom-Json).RSU[0].downloads.windows.link
$resharperTool = Get-ToolPath $url
Get-Tool $url
Get-Tool $NugetUrl
# Build plugin
$artifacts = "$PSScriptRoot\artifacts"
Write-Nuspec "$artifacts\Package.nuspec"
Invoke-Exe dotnet build "$PSScriptRoot\Machine.Specifications.Runner.Resharper.sln" /p:Version=$Version /p:HostFullIdentifier="" /p:UseSharedCompilation=false
Invoke-Exe $NugetExe pack "$artifacts\Package.nuspec" -version $Version -outputDirectory "$artifacts"
# Install hive
Install-Hive $resharperTool
# Set up environment
Save-PackagesConfig
# Install plugin
Invoke-Exe $NugetExe install $PluginId -OutputDirectory "$env:LOCALAPPDATA\JetBrains\plugins" -Source "$artifacts" -DependencyVersion Ignore
# Reinstall hive
Install-Hive $resharperTool
# Set user project settings
$installPath = Get-InstallationPath
$hostIdentifier = "$($installPath.Parent.Name)_$($installPath.Name.Split('_')[-1])"
Write-User-Settings $hostIdentifier "$PSScriptRoot\src\Machine.Specifications.Runner.ReSharper\Machine.Specifications.Runner.ReSharper.csproj.user"
Write-User-Settings $hostIdentifier "$PSScriptRoot\src\Machine.Specifications.Runner.ReSharper.Adapters\Machine.Specifications.Runner.ReSharper.Adapters.csproj.user"
Write-User-Settings $hostIdentifier "$PSScriptRoot\src\Machine.Specifications.Runner.ReSharper.Tasks\Machine.Specifications.Runner.ReSharper.Tasks.csproj.user"
Write-Output "Installed plugin to hive"