Skip to content

Commit

Permalink
Installing Java is troublesome, so avoid it (#2815)
Browse files Browse the repository at this point in the history
There are some sort of weird corruption issues on macOS
  • Loading branch information
mattleibow committed Mar 29, 2024
1 parent 4f87c3a commit 510e738
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions scripts/install-openjdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,56 @@ Param(

$ErrorActionPreference = 'Stop'

Add-Type -AssemblyName System.IO.Compression.FileSystem
if (Test-Path (Join-Path "$env:JAVA_HOME_17_X64" "bin")) {
Write-Host "Java is already installed to '$env:JAVA_HOME_17_X64'..."
$java_home = $env:JAVA_HOME_17_X64
} else {
Add-Type -AssemblyName System.IO.Compression.FileSystem

$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
$HOME_DIR = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }

if ($IsMacOS) {
$ext = "tar.gz"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-macOS-x64.tar.gz"
} elseif ($IsLinux) {
$ext = "tar.gz"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-linux-x64.tar.gz"
} else {
$ext = "zip"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-windows-x64.zip"
}
if ($IsMacOS) {
$ext = "tar.gz"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-macOS-x64.tar.gz"
} elseif ($IsLinux) {
$ext = "tar.gz"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-linux-x64.tar.gz"
} else {
$ext = "zip"
$url = "https://aka.ms/download-jdk/microsoft-jdk-$Version-windows-x64.zip"
}

$jdk = Join-Path "$HOME_DIR" "openjdk"
if ($InstallDestination) {
$jdk = $InstallDestination
}
Write-Host "Install destination is '$jdk'..."
$jdk = Join-Path "$HOME_DIR" "openjdk"
if ($InstallDestination) {
$jdk = $InstallDestination
}
Write-Host "Install destination is '$jdk'..."

$jdkTemp = Join-Path "$HOME_DIR" "openjdk-temp"
$archive = Join-Path "$jdkTemp" "openjdk.$ext"
$jdkTemp = Join-Path "$HOME_DIR" "openjdk-temp"
$archive = Join-Path "$jdkTemp" "openjdk.$ext"

# download
Write-Host "Downloading OpenJDK to '$archive'..."
New-Item -ItemType Directory -Force -Path "$jdkTemp" | Out-Null
(New-Object System.Net.WebClient).DownloadFile("$url", "$archive")
# 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 {
[System.IO.Compression.ZipFile]::ExtractToDirectory("$archive", "$jdk")
}
# 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 {
[System.IO.Compression.ZipFile]::ExtractToDirectory("$archive", "$jdk")
}

# set the JAVA_HOME
if ($IsMacOS) {
$java_home = Join-Path "$jdk" "jdk-$FolderVersion/Contents/Home"
} else {
$java_home = Join-Path "$jdk" "jdk-$FolderVersion"
# set the JAVA_HOME
if ($IsMacOS) {
$java_home = Join-Path "$jdk" "jdk-$FolderVersion/Contents/Home"
} else {
$java_home = Join-Path "$jdk" "jdk-$FolderVersion"
}
}

Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$java_home"
$env:JAVA_HOME = "$java_home"

Expand Down

0 comments on commit 510e738

Please sign in to comment.