Improve detection of JDK on Windows (#10294)

This commit is contained in:
Nate McMaster 2019-05-16 12:41:50 -07:00 committed by GitHub
parent 7db16f174d
commit fa73edb9bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 5 deletions

View File

@ -23,7 +23,6 @@ jobs:
jobName: Code_check
jobDisplayName: Code check
agentOs: Windows
installJdk: false
steps:
- powershell: ./eng/scripts/CodeCheck.ps1 -ci
displayName: Run eng/scripts/CodeCheck.ps1

View File

@ -120,7 +120,7 @@ jobs:
BuildDirectory: ${{ parameters.buildDirectory }}
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
TeamName: AspNetCore
${{ if eq(parameters.agentOs, 'Windows') }}:
${{ if and(eq(parameters.installJdk, 'true'), eq(parameters.agentOs, 'Windows')) }}:
JAVA_HOME: $(Agent.BuildDirectory)\.tools\jdk
${{ if or(ne(parameters.codeSign, true), ne(variables['System.TeamProject'], 'internal')) }}:
_SignType: ''

View File

@ -303,6 +303,44 @@ $MSBuildArguments += "/p:_RunSign=$Sign"
$MSBuildArguments += "/p:TargetArchitecture=$Architecture"
$MSBuildArguments += "/p:TargetOsName=win"
if (($All -or $BuildJava) -and -not $NoBuildJava) {
$foundJdk = $false
$javac = Get-Command javac -ErrorAction Ignore -CommandType Application
if ($env:JAVA_HOME) {
if (-not (Test-Path "${env:JAVA_HOME}\bin\javac.exe")) {
Write-Error "The environment variable JAVA_HOME was set, but ${env:JAVA_HOME}\bin\javac.exe does not exist. Remove JAVA_HOME or update it to the correct location for the JDK. See https://www.bing.com/search?q=java_home for details."
}
else {
Write-Host -f Magenta "Detected JDK in ${env:JAVA_HOME} (via JAVA_HOME)"
$foundJdk = $true
}
}
elseif ($javac) {
$foundJdk = $true
$javaHome = Split-Path -Parent (Split-Path -Parent $javac.Path)
$env:JAVA_HOME = $javaHome
Write-Host -f Magenta "Detected JDK in $javaHome (via PATH)"
}
else {
try {
$jdkVersion = (Get-Item HKLM:\SOFTWARE\JavaSoft\JDK | Get-ItemProperty -name CurrentVersion).CurrentVersion
$javaHome = (Get-Item HKLM:\SOFTWARE\JavaSoft\JDK\$jdkVersion | Get-ItemProperty -Name JavaHome).JavaHome
if (Test-Path "${env:JAVA_HOME}\bin\java.exe") {
$env:JAVA_HOME = $javaHome
Write-Host -f Magenta "Detected JDK $jdkVersion in $env:JAVA_HOME (via registry)"
$foundJdk = $true
}
}
catch {
Write-Verbose "Failed to detect Java: $_"
}
}
if (-not $foundJdk) {
Write-Error "Could not find the JDK. See $PSScriptRoot\docs\BuildFromSource.md for details on this requirement."
}
}
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
try {

View File

@ -20,7 +20,9 @@ Building ASP.NET Core on Windows requires:
```
* Git. <https://git-scm.org>
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
* Java Development Kit (JDK) v8 with Java Runtime Environment (JRE) v8. See https://www.oracle.com/technetwork/java/javase/downloads/index.html
* Java Development Kit 11 or newer. Either:
* OpenJDK <https://jdk.java.net/>
* Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
### macOS/Linux
@ -31,8 +33,8 @@ Building ASP.NET Core on macOS or Linux requires:
* At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
* Git <https://git-scm.org>
* NodeJS. LTS version of 10.14.2 or newer <https://nodejs.org>
* Java Development Kit 10 or newer. Either:
* OpenJDK <http://jdk.java.net/10/>
* Java Development Kit 11 or newer. Either:
* OpenJDK <https://jdk.java.net/>
* Oracle's JDK <https://www.oracle.com/technetwork/java/javase/downloads/index.html>
## Clone the source code