2019-07-26 16:05:54 +03:00
|
|
|
Param(
|
2022-03-02 10:24:47 +03:00
|
|
|
[string] $Version = '11.0.14.9.1',
|
2019-07-26 16:05:54 +03:00
|
|
|
[string] $InstallDestination = $null
|
|
|
|
)
|
|
|
|
|
2019-05-24 08:14:37 +03:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2019-05-01 03:19:56 +03:00
|
|
|
|
2019-12-23 15:35:43 +03:00
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
|
|
|
|
|
2019-05-01 03:19:56 +03:00
|
|
|
if ($IsMacOS) {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "tar.gz"
|
2022-03-02 10:24:47 +03:00
|
|
|
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-macOS-x64.tar.gz"
|
2019-05-01 03:19:56 +03:00
|
|
|
} elseif ($IsLinux) {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "tar.gz"
|
2022-03-02 10:24:47 +03:00
|
|
|
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-linux-x64.tar.gz"
|
2019-05-01 03:19:56 +03:00
|
|
|
} else {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "zip"
|
2022-03-02 10:24:47 +03:00
|
|
|
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-windows-x64.zip"
|
2019-05-01 03:19:56 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$jdk = Join-Path "$HOME_DIR" "openjdk"
|
2019-07-26 16:05:54 +03:00
|
|
|
if ($InstallDestination) {
|
|
|
|
$jdk = $InstallDestination
|
|
|
|
}
|
2019-09-24 02:34:44 +03:00
|
|
|
Write-Host "Install destination is '$jdk'..."
|
2019-07-26 16:05:54 +03:00
|
|
|
|
2020-07-07 20:15:40 +03:00
|
|
|
$jdkTemp = Join-Path "$HOME_DIR" "openjdk-temp"
|
2019-12-23 15:35:43 +03:00
|
|
|
$archive = Join-Path "$jdkTemp" "openjdk.$ext"
|
2019-05-01 03:19:56 +03:00
|
|
|
|
|
|
|
# download
|
|
|
|
Write-Host "Downloading OpenJDK to '$archive'..."
|
|
|
|
New-Item -ItemType Directory -Force -Path "$jdkTemp" | Out-Null
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile("$url", "$archive")
|
|
|
|
|
|
|
|
# install
|
|
|
|
Write-Host "Extracting OpenJDK to '$jdk'..."
|
|
|
|
New-Item -ItemType Directory -Force -Path "$jdk" | Out-Null
|
|
|
|
if ($IsMacOS -or $IsLinux) {
|
|
|
|
tar -vxzf "$archive" -C "$jdk"
|
|
|
|
} else {
|
2019-12-23 15:35:43 +03:00
|
|
|
[System.IO.Compression.ZipFile]::ExtractToDirectory("$archive", "$jdk")
|
2019-05-01 03:19:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# set the JAVA_HOME
|
2022-03-02 10:24:47 +03:00
|
|
|
$VersionParts = $Version.Split(".")
|
|
|
|
$FolderVersion = "$($VersionParts[0]).$($VersionParts[1]).$($VersionParts[2])+$($VersionParts[3])"
|
2019-05-01 03:19:56 +03:00
|
|
|
if ($IsMacOS) {
|
2022-03-02 10:24:47 +03:00
|
|
|
$java_home = Join-Path "$jdk" "jdk-$FolderVersion/Contents/Home"
|
2019-05-01 03:19:56 +03:00
|
|
|
} else {
|
2022-03-02 10:24:47 +03:00
|
|
|
$java_home = Join-Path "$jdk" "jdk-$FolderVersion"
|
2019-05-01 03:19:56 +03:00
|
|
|
}
|
|
|
|
Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$java_home"
|
2022-03-02 10:24:47 +03:00
|
|
|
$env:JAVA_HOME = "$java_home"
|
2019-05-01 03:19:56 +03:00
|
|
|
|
2019-06-25 10:10:09 +03:00
|
|
|
# make sure that JAVA_HOME/bin is in the PATH
|
|
|
|
$javaBin = Join-Path "$java_home" "bin"
|
2022-04-05 06:17:23 +03:00
|
|
|
if (-not $env:PATH.Contains($javaBin)) {
|
|
|
|
$env:PATH = "$javaBin" + [IO.Path]::PathSeparator + "$env:PATH"
|
|
|
|
Write-Host "##vso[task.setvariable variable=PATH;]$env:PATH"
|
|
|
|
}
|
2022-03-02 10:24:47 +03:00
|
|
|
|
|
|
|
java -version
|
2019-06-25 10:10:09 +03:00
|
|
|
|
2019-05-01 03:19:56 +03:00
|
|
|
exit $LASTEXITCODE
|