mirror of
https://github.com/actions/setup-java.git
synced 2025-11-07 09:44:10 +00:00
update with enhance code and test
This commit is contained in:
parent
ba6d7216a9
commit
bcde537b63
3 changed files with 441 additions and 96 deletions
110
dist/setup/index.js
vendored
110
dist/setup/index.js
vendored
|
|
@ -130530,31 +130530,51 @@ const util_1 = __nccwpck_require__(92629);
|
|||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||
const GRAALVM_MIN_VERSION = 17;
|
||||
const SUPPORTED_ARCHITECTURES = ['x64', 'aarch64'];
|
||||
class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||
constructor(installerOptions) {
|
||||
super('GraalVM', installerOptions);
|
||||
}
|
||||
downloadTool(javaRelease) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||
let javaArchivePath = yield tc.downloadTool(javaRelease.url);
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
if (IS_WINDOWS) {
|
||||
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
|
||||
try {
|
||||
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||
let javaArchivePath = yield tc.downloadTool(javaRelease.url);
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
if (IS_WINDOWS) {
|
||||
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
|
||||
}
|
||||
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
|
||||
// Add validation for extracted path
|
||||
if (!fs_1.default.existsSync(extractedJavaPath)) {
|
||||
throw new Error(`Extraction failed: path ${extractedJavaPath} does not exist`);
|
||||
}
|
||||
const dirContents = fs_1.default.readdirSync(extractedJavaPath);
|
||||
if (dirContents.length === 0) {
|
||||
throw new Error('Extraction failed: no files found in extracted directory');
|
||||
}
|
||||
const archivePath = path_1.default.join(extractedJavaPath, dirContents[0]);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
}
|
||||
catch (error) {
|
||||
core.error(`Failed to download and extract GraalVM: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
|
||||
const archivePath = path_1.default.join(extractedJavaPath, fs_1.default.readdirSync(extractedJavaPath)[0]);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
});
|
||||
}
|
||||
findPackageForDownload(range) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Add input validation
|
||||
if (!range || typeof range !== 'string') {
|
||||
throw new Error('Version range is required and must be a string');
|
||||
}
|
||||
const arch = this.distributionArchitecture();
|
||||
if (!['x64', 'aarch64'].includes(arch)) {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
if (!SUPPORTED_ARCHITECTURES.includes(arch)) {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`);
|
||||
}
|
||||
if (!this.stable) {
|
||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||
|
|
@ -130565,10 +130585,14 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
const platform = this.getPlatform();
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
const major = range.includes('.') ? range.split('.')[0] : range;
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('GraalVM is only supported for JDK 17 and later');
|
||||
const majorVersion = parseInt(major);
|
||||
if (isNaN(majorVersion)) {
|
||||
throw new Error(`Invalid version format: ${range}`);
|
||||
}
|
||||
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||
throw new Error(`GraalVM is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`);
|
||||
}
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
const response = yield this.http.head(fileUrl);
|
||||
this.handleHttpResponse(response, range);
|
||||
return { url: fileUrl, version: range };
|
||||
|
|
@ -130580,43 +130604,71 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
: `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
}
|
||||
handleHttpResponse(response, range) {
|
||||
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
||||
throw new Error(`Could not find GraalVM for SemVer ${range}`);
|
||||
const statusCode = response.message.statusCode;
|
||||
if (statusCode === http_client_1.HttpCodes.NotFound) {
|
||||
throw new Error(`Could not find GraalVM for SemVer ${range}. Please check if this version is available at ${GRAALVM_DL_BASE}`);
|
||||
}
|
||||
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
|
||||
throw new Error(`Http request for GraalVM failed with status code: ${response.message.statusCode}`);
|
||||
if (statusCode === http_client_1.HttpCodes.Unauthorized ||
|
||||
statusCode === http_client_1.HttpCodes.Forbidden) {
|
||||
throw new Error(`Access denied when downloading GraalVM. Status code: ${statusCode}. Please check your credentials or permissions.`);
|
||||
}
|
||||
if (statusCode !== http_client_1.HttpCodes.OK) {
|
||||
throw new Error(`HTTP request for GraalVM failed with status code: ${statusCode} (${response.message.statusMessage || 'Unknown error'})`);
|
||||
}
|
||||
}
|
||||
findEABuildDownloadUrl(javaEaVersion) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.debug(`Searching for EA build: ${javaEaVersion}`);
|
||||
const versions = yield this.fetchEAJson(javaEaVersion);
|
||||
core.debug(`Found ${versions.length} EA versions`);
|
||||
const latestVersion = versions.find(v => v.latest);
|
||||
if (!latestVersion) {
|
||||
core.error(`Available versions: ${versions.map(v => v.version).join(', ')}`);
|
||||
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
||||
}
|
||||
core.debug(`Latest version found: ${latestVersion.version}`);
|
||||
const arch = this.distributionArchitecture();
|
||||
const file = latestVersion.files.find(f => f.arch === arch && f.platform === GRAALVM_PLATFORM);
|
||||
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
|
||||
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
|
||||
if (!file) {
|
||||
core.error(`Available files for architecture ${arch}: ${JSON.stringify(latestVersion.files)}`);
|
||||
throw new Error(`Unable to find file for architecture '${arch}' and platform '${GRAALVM_PLATFORM}'`);
|
||||
}
|
||||
if (!file.filename.startsWith('graalvm-jdk-')) {
|
||||
throw new Error(`Invalid filename format: ${file.filename}. Expected to start with 'graalvm-jdk-'`);
|
||||
}
|
||||
const downloadUrl = `${latestVersion.download_base_url}${file.filename}`;
|
||||
core.debug(`Download URL: ${downloadUrl}`);
|
||||
return {
|
||||
url: `${latestVersion.download_base_url}${file.filename}`,
|
||||
url: downloadUrl,
|
||||
version: latestVersion.version
|
||||
};
|
||||
});
|
||||
}
|
||||
fetchEAJson(javaEaVersion) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = `https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/${javaEaVersion}.json?ref=main`;
|
||||
const headers = (0, util_1.getGitHubHttpHeaders)();
|
||||
core.debug(`Trying to fetch available version info for GraalVM EA builds from '${url}'`);
|
||||
const fetchedJson = yield this.http
|
||||
.getJson(url, headers)
|
||||
.then(res => res.result);
|
||||
if (!fetchedJson) {
|
||||
throw new Error(`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`);
|
||||
try {
|
||||
const response = yield this.http.getJson(url, headers);
|
||||
if (!response.result) {
|
||||
throw new Error(`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`);
|
||||
}
|
||||
return response.result;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
// Check if it's a 404 error (file not found)
|
||||
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('404')) {
|
||||
throw new Error(`GraalVM EA version '${javaEaVersion}' not found. Please verify the version exists in the EA builds repository.`);
|
||||
}
|
||||
// Re-throw with more context
|
||||
throw new Error(`Failed to fetch GraalVM EA version information for '${javaEaVersion}': ${error.message}`);
|
||||
}
|
||||
// If it's not an Error instance, throw a generic error
|
||||
throw new Error(`Failed to fetch GraalVM EA version information for '${javaEaVersion}'`);
|
||||
}
|
||||
return fetchedJson;
|
||||
});
|
||||
}
|
||||
getPlatform(platform = process.platform) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue