Skip to content

Commit 4fb3975

Browse files
Merge pull request actions#507 from akv-platform/update-oracle-jdk-url-calculation
Update Oracle JDK download URL calculation
2 parents 75c6561 + 33b10b6 commit 4fb3975

File tree

3 files changed

+75
-39
lines changed

3 files changed

+75
-39
lines changed

__tests__/distributors/oracle-installer.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ describe('findPackageForDownload', () => {
2727
'20',
2828
'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
2929
],
30+
[
31+
'18',
32+
'18',
33+
'https://download.oracle.com/java/18/archive/jdk-18_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
34+
],
3035
[
3136
'20.0.1',
3237
'20.0.1',
@@ -43,7 +48,7 @@ describe('findPackageForDownload', () => {
4348
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
4449
]
4550
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
46-
/* Needed only for this particular test because /latest/ urls tend to change */
51+
/* Needed only for this particular test because some urls might change */
4752
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
4853
spyHttpClient.mockReturnValue(
4954
Promise.resolve({
@@ -53,6 +58,19 @@ describe('findPackageForDownload', () => {
5358
})
5459
);
5560

61+
/**
62+
* NOTE - Should fail to retrieve 18 from latest and check archive instead
63+
*/
64+
if (input === '18') {
65+
spyHttpClient.mockReturnValueOnce(
66+
Promise.resolve({
67+
message: {
68+
statusCode: 404
69+
}
70+
})
71+
);
72+
}
73+
5674
const result = await distribution['findPackageForDownload'](input);
5775

5876
jest.restoreAllMocks();
@@ -75,7 +93,7 @@ describe('findPackageForDownload', () => {
7593
jest.spyOn(os, 'arch').mockReturnValue(osArch);
7694
jest.spyOn(os, 'platform').mockReturnValue('linux');
7795

78-
const version = '17';
96+
const version = '18';
7997
const distro = new OracleDistribution({
8098
version,
8199
architecture: '', // to get default value
@@ -89,7 +107,7 @@ describe('findPackageForDownload', () => {
89107
}
90108
const archiveType = getDownloadArchiveExtension();
91109
const result = await distro['findPackageForDownload'](version);
92-
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`;
110+
const expectedUrl = `https://download.oracle.com/java/18/archive/jdk-18_${osType}-${distroArch}_bin.${archiveType}`;
93111

94112
expect(result.url).toBe(expectedUrl);
95113
}
@@ -102,8 +120,5 @@ describe('findPackageForDownload', () => {
102120
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
103121
/Oracle JDK is only supported for JDK 17 and later/
104122
);
105-
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
106-
/Could not find Oracle JDK for SemVer */
107-
);
108123
});
109124
});

dist/setup/index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103092,27 +103092,33 @@ class OracleDistribution extends base_installer_1.JavaBase {
103092103092
}
103093103093
const platform = this.getPlatform();
103094103094
const extension = util_1.getDownloadArchiveExtension();
103095-
let major;
103096-
let fileUrl;
103097-
if (range.includes('.')) {
103098-
major = range.split('.')[0];
103099-
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
103100-
}
103101-
else {
103102-
major = range;
103103-
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
103095+
const isOnlyMajorProvided = !range.includes('.');
103096+
const major = isOnlyMajorProvided ? range : range.split('.')[0];
103097+
const possibleUrls = [];
103098+
/**
103099+
* NOTE
103100+
* If only major version was provided we will check it under /latest first
103101+
* in order to retrieve the latest possible version if possible,
103102+
* otherwise we will fall back to /archive where we are guaranteed to
103103+
* find any version if it exists
103104+
*/
103105+
if (isOnlyMajorProvided) {
103106+
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`);
103104103107
}
103108+
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`);
103105103109
if (parseInt(major) < 17) {
103106103110
throw new Error('Oracle JDK is only supported for JDK 17 and later');
103107103111
}
103108-
const response = yield this.http.head(fileUrl);
103109-
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
103110-
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
103111-
}
103112-
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
103113-
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
103112+
for (const url of possibleUrls) {
103113+
const response = yield this.http.head(url);
103114+
if (response.message.statusCode === http_client_1.HttpCodes.OK) {
103115+
return { url, version: range };
103116+
}
103117+
if (response.message.statusCode !== http_client_1.HttpCodes.NotFound) {
103118+
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
103119+
}
103114103120
}
103115-
return { url: fileUrl, version: range };
103121+
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
103116103122
});
103117103123
}
103118103124
getPlatform(platform = process.platform) {

src/distributions/oracle/installer.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,48 @@ export class OracleDistribution extends JavaBase {
6565

6666
const platform = this.getPlatform();
6767
const extension = getDownloadArchiveExtension();
68-
let major;
69-
let fileUrl;
70-
if (range.includes('.')) {
71-
major = range.split('.')[0];
72-
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
73-
} else {
74-
major = range;
75-
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
68+
69+
const isOnlyMajorProvided = !range.includes('.');
70+
const major = isOnlyMajorProvided ? range : range.split('.')[0];
71+
72+
const possibleUrls: string[] = [];
73+
74+
/**
75+
* NOTE
76+
* If only major version was provided we will check it under /latest first
77+
* in order to retrieve the latest possible version if possible,
78+
* otherwise we will fall back to /archive where we are guaranteed to
79+
* find any version if it exists
80+
*/
81+
if (isOnlyMajorProvided) {
82+
possibleUrls.push(
83+
`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`
84+
);
7685
}
7786

87+
possibleUrls.push(
88+
`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`
89+
);
90+
7891
if (parseInt(major) < 17) {
7992
throw new Error('Oracle JDK is only supported for JDK 17 and later');
8093
}
8194

82-
const response = await this.http.head(fileUrl);
95+
for (const url of possibleUrls) {
96+
const response = await this.http.head(url);
8397

84-
if (response.message.statusCode === HttpCodes.NotFound) {
85-
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
86-
}
98+
if (response.message.statusCode === HttpCodes.OK) {
99+
return {url, version: range};
100+
}
87101

88-
if (response.message.statusCode !== HttpCodes.OK) {
89-
throw new Error(
90-
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
91-
);
102+
if (response.message.statusCode !== HttpCodes.NotFound) {
103+
throw new Error(
104+
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
105+
);
106+
}
92107
}
93108

94-
return {url: fileUrl, version: range};
109+
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
95110
}
96111

97112
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy