Deprecated/Get-AdoptOpenJDK.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$MajorVersions = @(8,11,16)
$JvmTypes = @('HotSpot', 'OpenJ9')
$HeapSizes = @('Normal', 'Large')
$ImageTypes = @('JDK', 'JRE')
$Architectures = @('x32','x64')

foreach ($MajorVersion in $MajorVersions) {
    foreach ($JvmType in $JvmTypes) {

        $ReleasesURL = "https://api.adoptopenjdk.net/v3/assets/latest/$MajorVersion/$($JvmType.ToLower())?release=latest&jvm_impl=$($JvmType.ToLower())&vendor=adoptopenjdk&"

        try {

            $Releases = Invoke-RestMethod -Uri $ReleasesURL -DisableKeepAlive -ErrorAction Stop

            foreach ($HeapSize in $HeapSizes) {
                foreach ($ImageType in $ImageTypes) {
                    foreach ($Architecture in $Architectures) {

                        $Release = $Releases | Where-Object { $_.binary.os -eq 'windows' -and $_.binary.heap_size -eq $HeapSize -and $_.binary.image_type -eq $ImageType -and $_.binary.architecture -eq $Architecture }

                        if ($Release) {
                            if ($Release.Count -gt 1) {
                                Write-Warning "Unexpected multiple releases returned for AdoptOpenJDK $MajorVersion $JvmType $HeapSize $ImageType $Architecture"
                            }

                            if ($Architecture -eq 'x32') {
                                $Architecture = 'x86'
                            }

                            $Release | ForEach-Object {
                                $Version = ($_.version.openjdk_version.Replace('_','.').Replace('+','.') -Replace '-[a-z]','.') -Replace '^1\.8\.','8.'
                                New-NevergreenApp -Name "AdoptOpenJDK$MajorVersion" -Version $Version -Uri $_.binary.installer.link -Platform "$JvmType $HeapSize $ImageType" -Architecture $Architecture -Type 'Msi'
                                New-NevergreenApp -Name "AdoptOpenJDK$MajorVersion" -Version $Version -Uri $_.binary.package.link -Platform "$JvmType $HeapSize $ImageType" -Architecture $Architecture -Type 'Zip'
                            }
                        }

                    }
                }
            }
        }
        catch {
            Write-Error "$($MyInvocation.MyCommand): Error querying REST API $($ReleasesURL): $($_.Exception.Message)"
        }
    }
}