Skip to content

Commit 33b10b6

Browse files
Use archive as fallback only when dealing with major version
1 parent ebe05e0 commit 33b10b6

File tree

3 files changed

+78
-24
lines changed

3 files changed

+78
-24
lines changed

__tests__/distributors/oracle-installer.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ describe('findPackageForDownload', () => {
2525
[
2626
'20',
2727
'20',
28-
'https://download.oracle.com/java/20/archive/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
28+
'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
29+
],
30+
[
31+
'18',
32+
'18',
33+
'https://download.oracle.com/java/18/archive/jdk-18_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
2934
],
3035
[
3136
'20.0.1',
@@ -35,7 +40,7 @@ describe('findPackageForDownload', () => {
3540
[
3641
'17',
3742
'17',
38-
'https://download.oracle.com/java/17/archive/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
43+
'https://download.oracle.com/java/17/latest/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
3944
],
4045
[
4146
'17.0.1',
@@ -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/archive/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
}

dist/setup/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102973,19 +102973,33 @@ class OracleDistribution extends base_installer_1.JavaBase {
102973102973
}
102974102974
const platform = this.getPlatform();
102975102975
const extension = util_1.getDownloadArchiveExtension();
102976-
const major = range.includes('.') ? range.split('.')[0] : range;
102977-
const fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
102976+
const isOnlyMajorProvided = !range.includes('.');
102977+
const major = isOnlyMajorProvided ? range : range.split('.')[0];
102978+
const possibleUrls = [];
102979+
/**
102980+
* NOTE
102981+
* If only major version was provided we will check it under /latest first
102982+
* in order to retrieve the latest possible version if possible,
102983+
* otherwise we will fall back to /archive where we are guaranteed to
102984+
* find any version if it exists
102985+
*/
102986+
if (isOnlyMajorProvided) {
102987+
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`);
102988+
}
102989+
possibleUrls.push(`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`);
102978102990
if (parseInt(major) < 17) {
102979102991
throw new Error('Oracle JDK is only supported for JDK 17 and later');
102980102992
}
102981-
const response = yield this.http.head(fileUrl);
102982-
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
102983-
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
102984-
}
102985-
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
102986-
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
102993+
for (const url of possibleUrls) {
102994+
const response = yield this.http.head(url);
102995+
if (response.message.statusCode === http_client_1.HttpCodes.OK) {
102996+
return { url, version: range };
102997+
}
102998+
if (response.message.statusCode !== http_client_1.HttpCodes.NotFound) {
102999+
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
103000+
}
102987103001
}
102988-
return { url: fileUrl, version: range };
103002+
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
102989103003
});
102990103004
}
102991103005
getPlatform(platform = process.platform) {

src/distributions/oracle/installer.ts

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

6666
const platform = this.getPlatform();
6767
const extension = getDownloadArchiveExtension();
68-
const major = range.includes('.') ? range.split('.')[0] : range;
69-
const fileUrl = `${ORACLE_DL_BASE}/${major}/archive/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+
);
85+
}
86+
87+
possibleUrls.push(
88+
`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`
89+
);
7090

7191
if (parseInt(major) < 17) {
7292
throw new Error('Oracle JDK is only supported for JDK 17 and later');
7393
}
7494

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

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

81-
if (response.message.statusCode !== HttpCodes.OK) {
82-
throw new Error(
83-
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
84-
);
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+
}
85107
}
86108

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

90112
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