mirror of
https://github.com/actions/setup-java.git
synced 2025-04-22 02:46:46 +00:00
Add support for Oracle GraalVM
This commit is contained in:
parent
2dfa2011c5
commit
bbbb45e1c5
8 changed files with 386 additions and 5 deletions
|
@ -11,6 +11,7 @@ import {CorrettoDistribution} from './corretto/installer';
|
|||
import {OracleDistribution} from './oracle/installer';
|
||||
import {DragonwellDistribution} from './dragonwell/installer';
|
||||
import {SapMachineDistribution} from './sapmachine/installer';
|
||||
import {GraalVMDistribution} from './graalvm/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
Adopt = 'adopt',
|
||||
|
@ -25,7 +26,8 @@ enum JavaDistribution {
|
|||
Corretto = 'corretto',
|
||||
Oracle = 'oracle',
|
||||
Dragonwell = 'dragonwell',
|
||||
SapMachine = 'sapmachine'
|
||||
SapMachine = 'sapmachine',
|
||||
GraalVM = 'graalvm'
|
||||
}
|
||||
|
||||
export function getJavaDistribution(
|
||||
|
@ -68,6 +70,8 @@ export function getJavaDistribution(
|
|||
return new DragonwellDistribution(installerOptions);
|
||||
case JavaDistribution.SapMachine:
|
||||
return new SapMachineDistribution(installerOptions);
|
||||
case JavaDistribution.GraalVM:
|
||||
return new GraalVMDistribution(installerOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
111
src/distributions/graalvm/installer.ts
Normal file
111
src/distributions/graalvm/installer.ts
Normal file
|
@ -0,0 +1,111 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
|
||||
import {HttpCodes} from '@actions/http-client';
|
||||
|
||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||
|
||||
export class GraalVMDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('GraalVM', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error('Early access versions are not supported');
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('GraalVM JDK provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
let major;
|
||||
let fileUrl;
|
||||
if (range.includes('.')) {
|
||||
major = range.split('.')[0];
|
||||
fileUrl = `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
} else {
|
||||
major = range;
|
||||
fileUrl = `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
}
|
||||
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('GraalVM JDK is only supported for JDK 17 and later');
|
||||
}
|
||||
|
||||
const response = await this.http.head(fileUrl);
|
||||
|
||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
||||
throw new Error(`Could not find GraalVM JDK for SemVer ${range}`);
|
||||
}
|
||||
|
||||
if (response.message.statusCode !== HttpCodes.OK) {
|
||||
throw new Error(
|
||||
`Http request for GraalVM JDK failed with status code: ${response.message.statusCode}`
|
||||
);
|
||||
}
|
||||
|
||||
return {url: fileUrl, version: range};
|
||||
}
|
||||
|
||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
case 'linux':
|
||||
return 'linux';
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
1
src/distributions/graalvm/models.ts
Normal file
1
src/distributions/graalvm/models.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export type OsVersions = 'linux' | 'macos' | 'windows';
|
Loading…
Add table
Add a link
Reference in a new issue