| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | import * as core from '@actions/core'; | 
					
						
							|  |  |  | import * as tc from '@actions/tool-cache'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import path from 'path'; | 
					
						
							|  |  |  | import fs from 'fs'; | 
					
						
							|  |  |  | import semver from 'semver'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  | import {JavaBase} from '../base-installer'; | 
					
						
							|  |  |  | import {IZuluVersions} from './models'; | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   extractJdkFile, | 
					
						
							|  |  |  |   getDownloadArchiveExtension, | 
					
						
							| 
									
										
										
										
											2023-04-10 10:29:19 +02:00
										 |  |  |   convertVersionToSemver, | 
					
						
							| 
									
										
										
										
											2024-10-11 03:02:25 +05:30
										 |  |  |   isVersionSatisfies, | 
					
						
							|  |  |  |   renameWinArchive | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  | } from '../../util'; | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   JavaDownloadRelease, | 
					
						
							|  |  |  |   JavaInstallerOptions, | 
					
						
							|  |  |  |   JavaInstallerResults | 
					
						
							|  |  |  | } from '../base-models'; | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class ZuluDistribution extends JavaBase { | 
					
						
							|  |  |  |   constructor(installerOptions: JavaInstallerOptions) { | 
					
						
							|  |  |  |     super('Zulu', installerOptions); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |   protected async findPackageForDownload( | 
					
						
							|  |  |  |     version: string | 
					
						
							|  |  |  |   ): Promise<JavaDownloadRelease> { | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     const availableVersionsRaw = await this.getAvailableVersions(); | 
					
						
							|  |  |  |     const availableVersions = availableVersionsRaw.map(item => { | 
					
						
							|  |  |  |       return { | 
					
						
							| 
									
										
										
										
											2023-04-10 10:29:19 +02:00
										 |  |  |         version: convertVersionToSemver(item.jdk_version), | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |         url: item.url, | 
					
						
							| 
									
										
										
										
											2023-04-10 10:29:19 +02:00
										 |  |  |         zuluVersion: convertVersionToSemver(item.zulu_version) | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const satisfiedVersions = availableVersions | 
					
						
							|  |  |  |       .filter(item => isVersionSatisfies(version, item.version)) | 
					
						
							|  |  |  |       .sort((a, b) => { | 
					
						
							|  |  |  |         // Azul provides two versions: jdk_version and azul_version
 | 
					
						
							|  |  |  |         // we should sort by both fields by descending
 | 
					
						
							|  |  |  |         return ( | 
					
						
							|  |  |  |           -semver.compareBuild(a.version, b.version) || | 
					
						
							|  |  |  |           -semver.compareBuild(a.zuluVersion, b.zuluVersion) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .map(item => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           version: item.version, | 
					
						
							|  |  |  |           url: item.url | 
					
						
							|  |  |  |         } as JavaDownloadRelease; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |     const resolvedFullVersion = | 
					
						
							|  |  |  |       satisfiedVersions.length > 0 ? satisfiedVersions[0] : null; | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     if (!resolvedFullVersion) { | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |       const availableOptions = availableVersions | 
					
						
							|  |  |  |         .map(item => item.version) | 
					
						
							|  |  |  |         .join(', '); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |       const availableOptionsMessage = availableOptions | 
					
						
							|  |  |  |         ? `\nAvailable versions: ${availableOptions}` | 
					
						
							|  |  |  |         : ''; | 
					
						
							|  |  |  |       throw new Error( | 
					
						
							|  |  |  |         `Could not find satisfied version for semver ${version}. ${availableOptionsMessage}` | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return resolvedFullVersion; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |   protected async downloadTool( | 
					
						
							|  |  |  |     javaRelease: JavaDownloadRelease | 
					
						
							|  |  |  |   ): Promise<JavaInstallerResults> { | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     core.info( | 
					
						
							|  |  |  |       `Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...` | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2024-02-28 10:41:33 +05:30
										 |  |  |     let javaArchivePath = await tc.downloadTool(javaRelease.url); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     core.info(`Extracting Java archive...`); | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |     const extension = getDownloadArchiveExtension(); | 
					
						
							| 
									
										
										
										
											2024-10-11 03:02:25 +05:30
										 |  |  |     if (process.platform === 'win32') { | 
					
						
							|  |  |  |       javaArchivePath = renameWinArchive(javaArchivePath); | 
					
						
							| 
									
										
										
										
											2024-02-28 10:41:33 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |     const extractedJavaPath = await extractJdkFile(javaArchivePath, extension); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const archiveName = fs.readdirSync(extractedJavaPath)[0]; | 
					
						
							|  |  |  |     const archivePath = path.join(extractedJavaPath, archiveName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const javaPath = await tc.cacheDir( | 
					
						
							|  |  |  |       archivePath, | 
					
						
							|  |  |  |       this.toolcacheFolderName, | 
					
						
							|  |  |  |       this.getToolcacheVersionName(javaRelease.version), | 
					
						
							|  |  |  |       this.architecture | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |     return {version: javaRelease.version, path: javaPath}; | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private async getAvailableVersions(): Promise<IZuluVersions[]> { | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |     const {arch, hw_bitness, abi} = this.getArchitectureOptions(); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     const [bundleType, features] = this.packageType.split('+'); | 
					
						
							|  |  |  |     const platform = this.getPlatformOption(); | 
					
						
							|  |  |  |     const extension = getDownloadArchiveExtension(); | 
					
						
							|  |  |  |     const javafx = features?.includes('fx') ?? false; | 
					
						
							|  |  |  |     const releaseStatus = this.stable ? 'ga' : 'ea'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 15:26:54 +02:00
										 |  |  |     if (core.isDebug()) { | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |       console.time('Retrieving available versions for Zulu took'); // eslint-disable-line no-console
 | 
					
						
							| 
									
										
										
										
											2022-09-08 15:26:54 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     const requestArguments = [ | 
					
						
							|  |  |  |       `os=${platform}`, | 
					
						
							|  |  |  |       `ext=${extension}`, | 
					
						
							|  |  |  |       `bundle_type=${bundleType}`, | 
					
						
							|  |  |  |       `javafx=${javafx}`, | 
					
						
							|  |  |  |       `arch=${arch}`, | 
					
						
							|  |  |  |       `hw_bitness=${hw_bitness}`, | 
					
						
							|  |  |  |       `release_status=${releaseStatus}`, | 
					
						
							|  |  |  |       abi ? `abi=${abi}` : null, | 
					
						
							|  |  |  |       features ? `features=${features}` : null | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |       .filter(Boolean) | 
					
						
							|  |  |  |       .join('&'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const availableVersionsUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?${requestArguments}`; | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     core.debug(`Gathering available versions from '${availableVersionsUrl}'`); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const availableVersions = | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |       (await this.http.getJson<Array<IZuluVersions>>(availableVersionsUrl)) | 
					
						
							|  |  |  |         .result ?? []; | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (core.isDebug()) { | 
					
						
							|  |  |  |       core.startGroup('Print information about available versions'); | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |       console.timeEnd('Retrieving available versions for Zulu took'); // eslint-disable-line no-console
 | 
					
						
							|  |  |  |       core.debug(`Available versions: [${availableVersions.length}]`); | 
					
						
							|  |  |  |       core.debug( | 
					
						
							|  |  |  |         availableVersions.map(item => item.jdk_version.join('.')).join(', ') | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |       core.endGroup(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return availableVersions; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private getArchitectureOptions(): { | 
					
						
							|  |  |  |     arch: string; | 
					
						
							|  |  |  |     hw_bitness: string; | 
					
						
							|  |  |  |     abi: string; | 
					
						
							|  |  |  |   } { | 
					
						
							| 
									
										
										
										
											2022-10-10 17:47:17 -06:00
										 |  |  |     const arch = this.distributionArchitecture(); | 
					
						
							|  |  |  |     switch (arch) { | 
					
						
							|  |  |  |       case 'x64': | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |         return {arch: 'x86', hw_bitness: '64', abi: ''}; | 
					
						
							| 
									
										
										
										
											2022-10-10 17:47:17 -06:00
										 |  |  |       case 'x86': | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |         return {arch: 'x86', hw_bitness: '32', abi: ''}; | 
					
						
							| 
									
										
										
										
											2022-10-10 17:47:17 -06:00
										 |  |  |       case 'aarch64': | 
					
						
							|  |  |  |       case 'arm64': | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |         return {arch: 'arm', hw_bitness: '64', abi: ''}; | 
					
						
							| 
									
										
										
										
											2022-10-10 17:47:17 -06:00
										 |  |  |       default: | 
					
						
							| 
									
										
										
										
											2023-03-09 14:49:35 +02:00
										 |  |  |         return {arch: arch, hw_bitness: '', abi: ''}; | 
					
						
							| 
									
										
										
										
											2021-04-05 13:02:27 +03:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private getPlatformOption(): string { | 
					
						
							|  |  |  |     // Azul has own platform names so need to map them
 | 
					
						
							|  |  |  |     switch (process.platform) { | 
					
						
							|  |  |  |       case 'darwin': | 
					
						
							|  |  |  |         return 'macos'; | 
					
						
							|  |  |  |       case 'win32': | 
					
						
							|  |  |  |         return 'windows'; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         return process.platform; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |