2
0
mirror of https://gitea.com/actions/setup-java.git synced 2025-04-08 00:09:38 +00:00

Merge pull request from akv-platform/update-oracle-jdk-url-calculation

Update Oracle JDK download URL calculation
This commit is contained in:
Nikolai Laevskii
2023-07-18 11:04:49 +02:00
committed by GitHub
3 changed files with 76 additions and 40 deletions
__tests__/distributors
dist/setup
src/distributions/oracle

38
dist/setup/index.js vendored

@ -103092,27 +103092,33 @@ class OracleDistribution extends base_installer_1.JavaBase {
}
const platform = this.getPlatform();
const extension = util_1.getDownloadArchiveExtension();
let major;
let fileUrl;
if (range.includes('.')) {
major = range.split('.')[0];
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
}
else {
major = range;
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
const isOnlyMajorProvided = !range.includes('.');
const major = isOnlyMajorProvided ? range : range.split('.')[0];
const possibleUrls = [];
/**
* NOTE
* If only major version was provided we will check it under /latest first
* in order to retrieve the latest possible version if possible,
* otherwise we will fall back to /archive where we are guaranteed to
* find any version if it exists
*/
if (isOnlyMajorProvided) {
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`);
}
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`);
if (parseInt(major) < 17) {
throw new Error('Oracle JDK is only supported for JDK 17 and later');
}
const response = yield this.http.head(fileUrl);
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
for (const url of possibleUrls) {
const response = yield this.http.head(url);
if (response.message.statusCode === http_client_1.HttpCodes.OK) {
return { url, version: range };
}
if (response.message.statusCode !== http_client_1.HttpCodes.NotFound) {
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
}
}
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
}
return { url: fileUrl, version: range };
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
});
}
getPlatform(platform = process.platform) {