parameters:
  - name: LatestJdkFeatureVersion
    type: string
    default: $(LatestJdkFeatureVersion)

steps:
  # Non-standard JDK versions are only supported in Linux.
  # Make the assumption here Linux is being used, if it's not it's a configuration issue that needs to be fixed there.
  - task: Cache@2
    inputs:
      key: 'jdk | "1.${{ parameters.LatestJdkFeatureVersion }}" | "$(CacheSalt)" | "$(Agent.OS)"'
      path: $(Agent.BuildDirectory)/jdk-${{ parameters.LatestJdkFeatureVersion }}
    displayName: 'Cache Latest JDK'

  - task: PowerShell@2
    displayName: 'Install Latest JDK'
    inputs:
      pwsh: true
      arguments: >
        -JdkFeatureVersion ${{ parameters.LatestJdkFeatureVersion }}
      workingDirectory: $(Agent.BuildDirectory)
      filePath: eng/scripts/Install-Latest-JDK.ps1

  - pwsh: |
      Write-Host "Java 8 JDK: $Env:JAVA_HOME_8_X64"
      Write-Host "Java 11 JDK: $Env:JAVA_HOME_11_X64"
      Write-Host "Java 17 JDK: $Env:JAVA_HOME_17_X64"
      Write-Host "Latest JDK: $Env:JAVA_HOME_${{ parameters.LatestJdkFeatureVersion }}_X64"
    displayName: 'Verify Latest JDK Install'