$JAVA_PATH = "$Env:JAVA_DIR\jdk-${Env:JAVA_VERSION}+${Env:JAVA_REVISION}"

# Check and install java if it is missing
if (!(Test-Path $Env:JAVA_DIR) -or !(Test-Path $JAVA_PATH))
{
    if (!(Test-Path $Env:JAVA_DIR))
    {
        New-Item -ItemType Directory -Path "$Env:JAVA_DIR" -Force
    }
    # Invoke-WebRequest is WAY too slow, use the web client
    $webClient = new-Object System.Net.WebClient
    $webClient.DownloadFile("${Env:JAVA_FILENAME}", "$Env:JAVA_DIR\jdk-${Env:JAVA_VERSION}+${Env:JAVA_REVISION}.zip")
    Expand-Archive -Path "$Env:JAVA_DIR\jdk-${Env:JAVA_VERSION}+${Env:JAVA_REVISION}.zip" -DestinationPath $Env:JAVA_DIR
    Remove-Item "$Env:JAVA_DIR\jdk-${Env:JAVA_VERSION}+${Env:JAVA_REVISION}.zip"
}
