forked from dotnet/aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallJdk.ps1
53 lines (48 loc) · 1.76 KB
/
InstallJdk.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
<#
.SYNOPSIS
Installs JDK into a folder in this repo.
.DESCRIPTION
This script downloads an extracts the JDK.
.PARAMETER JdkVersion
The version of the JDK to install. If not set, the default value is read from global.json
.PARAMETER Force
Overwrite the existing installation
#>
param(
[string]$JdkVersion,
[switch]$Force
)
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
Set-StrictMode -Version 1
$repoRoot = Resolve-Path "$PSScriptRoot\..\.."
$installDir = "$repoRoot\.tools\jdk\win-x64\"
$javacExe = "$installDir\bin\javac.exe"
$tempDir = "$repoRoot\obj"
if (-not $JdkVersion) {
$globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json
$JdkVersion = $globalJson.tools.jdk
}
if (Test-Path $javacExe) {
if ($Force) {
Remove-Item -Force -Recurse $installDir
}
else {
Write-Host "The JDK already installed to $installDir. Exiting without action. Call this script again with -Force to overwrite."
exit 0
}
}
Remove-Item -Force -Recurse $tempDir -ErrorAction Ignore | out-null
mkdir $tempDir -ea Ignore | out-null
mkdir $installDir -ea Ignore | out-null
Write-Host "Starting download of JDK ${JdkVersion}"
& $PSScriptRoot\Download.ps1 "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" "$tempDir/jdk.zip"
Write-Host "Done downloading JDK ${JdkVersion}"
Expand-Archive "$tempDir/jdk.zip" -d "$tempDir/jdk/"
Write-Host "Expanded JDK to $tempDir"
Write-Host "Installing JDK to $installDir"
Move-Item "$tempDir/jdk/jdk-${JdkVersion}/*" $installDir
Write-Host "Done installing JDK to $installDir"
if ($env:TF_BUILD) {
Write-Host "##vso[task.prependpath]$installDir\bin"
}