InstallJdk.ps1 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <#
  2. .SYNOPSIS
  3. Installs JDK into a folder in this repo.
  4. .DESCRIPTION
  5. This script downloads an extracts the JDK.
  6. .PARAMETER JdkVersion
  7. The version of the JDK to install. If not set, the default value is read from global.json
  8. .PARAMETER Force
  9. Overwrite the existing installation
  10. #>
  11. param(
  12. [string]$JdkVersion,
  13. [switch]$Force
  14. )
  15. $ErrorActionPreference = 'Stop'
  16. $ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
  17. Set-StrictMode -Version 1
  18. $repoRoot = Resolve-Path "$PSScriptRoot\..\.."
  19. $installDir = "$repoRoot\.tools\jdk\win-x64\"
  20. $tempDir = "$repoRoot\obj"
  21. if (-not $JdkVersion) {
  22. $globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json
  23. $JdkVersion = $globalJson.tools.jdk
  24. }
  25. if (Test-Path $installDir) {
  26. if ($Force) {
  27. Remove-Item -Force -Recurse $installDir
  28. }
  29. else {
  30. Write-Host "The JDK already installed to $installDir. Exiting without action. Call this script again with -Force to overwrite."
  31. exit 0
  32. }
  33. }
  34. Remove-Item -Force -Recurse $tempDir -ErrorAction Ignore | out-null
  35. mkdir $tempDir -ea Ignore | out-null
  36. mkdir $installDir -ea Ignore | out-null
  37. Write-Host "Starting download of JDK ${JdkVersion}"
  38. Invoke-WebRequest -UseBasicParsing -Uri "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/java/jdk-${JdkVersion}_windows-x64_bin.zip" -Out "$tempDir/jdk.zip"
  39. Write-Host "Done downloading JDK ${JdkVersion}"
  40. Expand-Archive "$tempDir/jdk.zip" -d "$tempDir/jdk/"
  41. Write-Host "Expanded JDK to $tempDir"
  42. Write-Host "Installing JDK to $installDir"
  43. Move-Item "$tempDir/jdk/jdk-${JdkVersion}/*" $installDir
  44. Write-Host "Done installing JDK to $installDir"
  45. if ($env:TF_BUILD) {
  46. Write-Host "##vso[task.prependpath]$installDir\bin"
  47. }