Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Java installation to AdoptOpenJDK on Windows #1067

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions images/win/scripts/Installers/Install-JavaTools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ Import-Module -Name ImageHelpers -Force
function Set-JavaPath {
param (
[string] $Version,
[string] $JavaRootPath,
[switch] $Default
)

$filter = "*azure-jdk_${version}.*"
$javaPath = (Get-ChildItem -Path 'C:\Program Files\Java' -Filter $filter | Sort-Object -Property Name -Descending | Select-Object -First 1).FullName
if ($Version -eq 7) {
$matchedString = "azure-jdk_7"
} else {
$matchedString = "jdk-?$Version"
}
$javaPath = (Get-ChildItem -Path $JavaRootPath | Where-Object { $_ -match $matchedString}).FullName

if ([string]::IsNullOrEmpty($javaPath)) {
Write-Host "Not found path to Java $Version"
exit 1
}

Write-Host "Set JAVA_HOME_${Version}_X64 environmental variable as $javaPath"
setx JAVA_HOME_${Version}_X64 $javaPath /M
Expand Down Expand Up @@ -43,26 +53,49 @@ function Set-JavaPath {
}
}

# Download the Azul Systems Zulu JDKs
# See https://www.azul.com/downloads/azure-only/zulu/
$azulJDKURLs = @(
'https://repos.azul.com/azure-only/zulu/packages/zulu-7/7u232/zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64.zip',
'https://repos.azul.com/azure-only/zulu/packages/zulu-8/8u222/zulu-8-azure-jdk_8.40.0.25-8.0.222-win_x64.zip',
'https://repos.azul.com/azure-only/zulu/packages/zulu-11/11.0.4/zulu-11-azure-jdk_11.33.15-11.0.4-win_x64.zip',
'https://repos.azul.com/azure-only/zulu/packages/zulu-13/13.0.3/zulu-13-azure-jdk_13.31.11-13.0.3-win_x64.zip'
)

foreach ($azulJDKURL in $azulJDKURLs)
{
$archivePath = Start-DownloadWithRetry -Url $azulJDKURL -Name $([IO.Path]::GetFileName($azulJDKURL))
Extract-7Zip -Path $archivePath -DestinationPath "C:\Program Files\Java\"
function Install-Java7FromAzul {
param(
[string] $DestinationPath
)
$azulJDK7URL = 'https://repos.azul.com/azure-only/zulu/packages/zulu-7/7u232/zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64.zip'
$archivePath = Start-DownloadWithRetry -Url $azulJDK7URL -Name $([IO.Path]::GetFileName($azulJDK7URL))
Extract-7Zip -Path $archivePath -DestinationPath $DestinationPath
}

function Install-JavaFromAdoptOpenJDK {
param(
[string] $JDKVersion,
[string] $DestinationPath
)

$assets = Invoke-RestMethod -Uri "https://api.adoptopenjdk.net/v3/assets/latest/$JDKVersion/hotspot"
$downloadUrl = ($assets | Where-Object {
$_.binary.os -eq "windows" `
-and $_.binary.architecture -eq "x64" `
-and $_.binary.image_type -eq "jdk"
}).binary.package.link

$archivePath = Start-DownloadWithRetry -Url $downloadUrl -Name $([IO.Path]::GetFileName($downloadUrl))
Extract-7Zip -Path $archivePath -DestinationPath $DestinationPath
}

# Set PATH and env variables
Set-JavaPath -Version 7
Set-JavaPath -Version 8 -Default
Set-JavaPath -Version 11
Set-JavaPath -Version 13
$jdkVersions = @(7, 8, 11, 13)
$defaultVersion = 8
$javaRootPath = "C:\Program Files\Java\"

foreach ($jdkVersion in $jdkVersions) {
if ($jdkVersion -eq 7) {
Install-Java7FromAzul -DestinationPath $javaRootPath
} else {
Install-JavaFromAdoptOpenJDK -JDKVersion $jdkVersion -DestinationPath $javaRootPath
}

if ($jdkVersion -eq $defaultVersion) {
Set-JavaPath -Version $jdkVersion -JavaRootPath $javaRootPath -Default
} else {
Set-JavaPath -Version $jdkVersion -JavaRootPath $javaRootPath
}
}

# Install Java tools
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
Expand Down
13 changes: 12 additions & 1 deletion images/win/scripts/Installers/Validate-JavaTools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ Function Validate-JavaVersion {
# Take 7 & 8 for versions 1.7 and 1.8
$versionNumber = $version.Split(".") | Select-Object -Last 1

$javaBin = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64") + "\bin;"
$javaPath = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64")
if ([string]::IsNullOrEmpty($javaPath))
{
Write-Host "Environment variable 'JAVA_HOME_${versionNumber}_X64' is null"
exit 1
}

$javaBin = "$javaPath\bin;"
$env:Path = $javaBin + $env:Path
}
else
{
Validate-JavaVersion -Version $Version
}

$isJavaExists = $($(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*'

Expand Down