2019-07-26 16:05:54 +03:00
|
|
|
Param(
|
|
|
|
[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-03-14 04:24:10 +03:00
|
|
|
$version = "13.0.2"
|
2019-05-01 03:19:56 +03:00
|
|
|
if ($IsMacOS) {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "tar.gz"
|
2020-03-14 04:24:10 +03:00
|
|
|
$url = "https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_osx-x64_bin.tar.gz"
|
2019-05-01 03:19:56 +03:00
|
|
|
} elseif ($IsLinux) {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "tar.gz"
|
2020-04-23 00:36:42 +03:00
|
|
|
$url = "https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz"
|
2019-05-01 03:19:56 +03:00
|
|
|
} else {
|
2019-12-23 15:35:43 +03:00
|
|
|
$ext = "zip"
|
2020-03-14 04:24:10 +03:00
|
|
|
$url = "https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_windows-x64_bin.zip"
|
2019-05-01 03:19:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$jdk = Join-Path "$HOME" "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
|
|
|
|
2019-05-01 03:19:56 +03:00
|
|
|
$jdkTemp = Join-Path "$HOME" "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
|
|
|
|
if ($IsMacOS) {
|
2019-12-23 15:35:43 +03:00
|
|
|
$java_home = Join-Path "$jdk" "jdk-$version.jdk/Contents/Home"
|
2019-05-01 03:19:56 +03:00
|
|
|
} else {
|
2019-12-23 15:35:43 +03:00
|
|
|
$java_home = Join-Path "$jdk" "jdk-$version"
|
2019-05-01 03:19:56 +03:00
|
|
|
}
|
|
|
|
Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$java_home"
|
|
|
|
|
2019-06-25 10:10:09 +03:00
|
|
|
# make sure that JAVA_HOME/bin is in the PATH
|
|
|
|
$javaBin = Join-Path "$java_home" "bin"
|
|
|
|
Write-Host "##vso[task.setvariable variable=PATH;]$javaBin;$env:PATH";
|
|
|
|
|
2019-05-01 03:19:56 +03:00
|
|
|
exit $LASTEXITCODE
|