mirror of
https://github.com/actions/setup-java
synced 2024-12-22 13:12:43 +00:00
Merge pull request #507 from akv-platform/update-oracle-jdk-url-calculation
Update Oracle JDK download URL calculation
This commit is contained in:
commit
4fb397523b
3 changed files with 76 additions and 40 deletions
|
@ -27,6 +27,11 @@ describe('findPackageForDownload', () => {
|
||||||
'20',
|
'20',
|
||||||
'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'18',
|
||||||
|
'18',
|
||||||
|
'https://download.oracle.com/java/18/archive/jdk-18_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'20.0.1',
|
'20.0.1',
|
||||||
'20.0.1',
|
'20.0.1',
|
||||||
|
@ -43,7 +48,7 @@ describe('findPackageForDownload', () => {
|
||||||
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
||||||
]
|
]
|
||||||
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
||||||
/* Needed only for this particular test because /latest/ urls tend to change */
|
/* Needed only for this particular test because some urls might change */
|
||||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
|
||||||
spyHttpClient.mockReturnValue(
|
spyHttpClient.mockReturnValue(
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
|
@ -53,6 +58,19 @@ describe('findPackageForDownload', () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NOTE - Should fail to retrieve 18 from latest and check archive instead
|
||||||
|
*/
|
||||||
|
if (input === '18') {
|
||||||
|
spyHttpClient.mockReturnValueOnce(
|
||||||
|
Promise.resolve({
|
||||||
|
message: {
|
||||||
|
statusCode: 404
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const result = await distribution['findPackageForDownload'](input);
|
const result = await distribution['findPackageForDownload'](input);
|
||||||
|
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
|
@ -75,7 +93,7 @@ describe('findPackageForDownload', () => {
|
||||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||||
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
||||||
|
|
||||||
const version = '17';
|
const version = '18';
|
||||||
const distro = new OracleDistribution({
|
const distro = new OracleDistribution({
|
||||||
version,
|
version,
|
||||||
architecture: '', // to get default value
|
architecture: '', // to get default value
|
||||||
|
@ -89,7 +107,7 @@ describe('findPackageForDownload', () => {
|
||||||
}
|
}
|
||||||
const archiveType = getDownloadArchiveExtension();
|
const archiveType = getDownloadArchiveExtension();
|
||||||
const result = await distro['findPackageForDownload'](version);
|
const result = await distro['findPackageForDownload'](version);
|
||||||
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`;
|
const expectedUrl = `https://download.oracle.com/java/18/archive/jdk-18_${osType}-${distroArch}_bin.${archiveType}`;
|
||||||
|
|
||||||
expect(result.url).toBe(expectedUrl);
|
expect(result.url).toBe(expectedUrl);
|
||||||
}
|
}
|
||||||
|
@ -102,8 +120,5 @@ describe('findPackageForDownload', () => {
|
||||||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
||||||
/Oracle JDK is only supported for JDK 17 and later/
|
/Oracle JDK is only supported for JDK 17 and later/
|
||||||
);
|
);
|
||||||
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
|
|
||||||
/Could not find Oracle JDK for SemVer */
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
34
dist/setup/index.js
vendored
34
dist/setup/index.js
vendored
|
@ -103092,27 +103092,33 @@ class OracleDistribution extends base_installer_1.JavaBase {
|
||||||
}
|
}
|
||||||
const platform = this.getPlatform();
|
const platform = this.getPlatform();
|
||||||
const extension = util_1.getDownloadArchiveExtension();
|
const extension = util_1.getDownloadArchiveExtension();
|
||||||
let major;
|
const isOnlyMajorProvided = !range.includes('.');
|
||||||
let fileUrl;
|
const major = isOnlyMajorProvided ? range : range.split('.')[0];
|
||||||
if (range.includes('.')) {
|
const possibleUrls = [];
|
||||||
major = range.split('.')[0];
|
/**
|
||||||
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
* NOTE
|
||||||
}
|
* If only major version was provided we will check it under /latest first
|
||||||
else {
|
* in order to retrieve the latest possible version if possible,
|
||||||
major = range;
|
* otherwise we will fall back to /archive where we are guaranteed to
|
||||||
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
* 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) {
|
if (parseInt(major) < 17) {
|
||||||
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
||||||
}
|
}
|
||||||
const response = yield this.http.head(fileUrl);
|
for (const url of possibleUrls) {
|
||||||
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
const response = yield this.http.head(url);
|
||||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
if (response.message.statusCode === http_client_1.HttpCodes.OK) {
|
||||||
|
return { url, version: range };
|
||||||
}
|
}
|
||||||
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
|
if (response.message.statusCode !== http_client_1.HttpCodes.NotFound) {
|
||||||
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
|
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) {
|
getPlatform(platform = process.platform) {
|
||||||
|
|
|
@ -65,33 +65,48 @@ export class OracleDistribution extends JavaBase {
|
||||||
|
|
||||||
const platform = this.getPlatform();
|
const platform = this.getPlatform();
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
let major;
|
|
||||||
let fileUrl;
|
const isOnlyMajorProvided = !range.includes('.');
|
||||||
if (range.includes('.')) {
|
const major = isOnlyMajorProvided ? range : range.split('.')[0];
|
||||||
major = range.split('.')[0];
|
|
||||||
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
const possibleUrls: string[] = [];
|
||||||
} else {
|
|
||||||
major = range;
|
/**
|
||||||
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
* 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) {
|
if (parseInt(major) < 17) {
|
||||||
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.http.head(fileUrl);
|
for (const url of possibleUrls) {
|
||||||
|
const response = await this.http.head(url);
|
||||||
|
|
||||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
if (response.message.statusCode === HttpCodes.OK) {
|
||||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
return {url, version: range};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.message.statusCode !== HttpCodes.OK) {
|
if (response.message.statusCode !== HttpCodes.NotFound) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
|
`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}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||||
|
|
Loading…
Reference in a new issue