Skip to content

Commit 3f07048

Browse files
Revert "Revert "Add support for Oracle JDK (actions#401)" (actions#421)" (actions#450)
This reverts commit c3ac5dd.
1 parent 9b86bbe commit 3f07048

File tree

9 files changed

+359
-2
lines changed

9 files changed

+359
-2
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ jobs:
2626
exclude:
2727
- distribution: microsoft
2828
version: 8
29+
include:
30+
- distribution: oracle
31+
os: macos-latest
32+
version: 17
33+
- distribution: oracle
34+
os: windows-latest
35+
version: 19
36+
- distribution: oracle
37+
os: ubuntu-latest
38+
version: 19
2939
steps:
3040
- name: Checkout
3141
uses: actions/checkout@v3
@@ -52,6 +62,10 @@ jobs:
5262
- '11.0'
5363
- '8.0.302'
5464
- '16.0.2+7'
65+
include:
66+
- distribution: oracle
67+
os: ubuntu-latest
68+
version: '19.0.1'
5569
steps:
5670
- name: Checkout
5771
uses: actions/checkout@v3

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Currently, the following distributions are supported:
103103
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
104104
| `microsoft` | Microsoft Build of OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
105105
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
106+
| `oracle` | Oracle JDK | [Link](https://www.oracle.com/java/technologies/downloads/) | [Link](https://java.com/freeuselicense)
106107

107108
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
108109

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { OracleDistribution } from '../../src/distributions/oracle/installer';
2+
import os from 'os';
3+
import * as core from '@actions/core';
4+
import { getDownloadArchiveExtension } from '../../src/util';
5+
6+
describe('findPackageForDownload', () => {
7+
let distribution: OracleDistribution;
8+
let spyDebug: jest.SpyInstance;
9+
10+
beforeEach(() => {
11+
distribution = new OracleDistribution({
12+
version: '',
13+
architecture: 'x64',
14+
packageType: 'jdk',
15+
checkLatest: false
16+
});
17+
18+
spyDebug = jest.spyOn(core, 'debug');
19+
spyDebug.mockImplementation(() => {});
20+
});
21+
22+
it.each([
23+
[
24+
'19',
25+
'19',
26+
'https://download.oracle.com/java/19/latest/jdk-19_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
27+
],
28+
[
29+
'19.0.1',
30+
'19.0.1',
31+
'https://download.oracle.com/java/19/archive/jdk-19.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
32+
],
33+
[
34+
'18.0.2.1',
35+
'18.0.2.1',
36+
'https://download.oracle.com/java/18/archive/jdk-18.0.2.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
37+
],
38+
[
39+
'17',
40+
'17',
41+
'https://download.oracle.com/java/17/latest/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
42+
],
43+
[
44+
'17.0.1',
45+
'17.0.1',
46+
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
47+
]
48+
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
49+
const result = await distribution['findPackageForDownload'](input);
50+
expect(result.version).toBe(expectedVersion);
51+
const osType = distribution.getPlatform();
52+
const archiveType = getDownloadArchiveExtension();
53+
const url = expectedUrl.replace('{{OS_TYPE}}', osType).replace('{{ARCHIVE_TYPE}}', archiveType);
54+
expect(result.url).toBe(url);
55+
});
56+
57+
it.each([
58+
['amd64', 'x64'],
59+
['arm64', 'aarch64']
60+
])(
61+
'defaults to os.arch(): %s mapped to distro arch: %s',
62+
async (osArch: string, distroArch: string) => {
63+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
64+
jest.spyOn(os, 'platform').mockReturnValue('linux');
65+
66+
const version = '17';
67+
const distro = new OracleDistribution({
68+
version,
69+
architecture: '', // to get default value
70+
packageType: 'jdk',
71+
checkLatest: false
72+
});
73+
74+
const osType = distribution.getPlatform();
75+
if (osType === 'windows' && distroArch == 'aarch64') {
76+
return; // skip, aarch64 is not available for Windows
77+
}
78+
const archiveType = getDownloadArchiveExtension();
79+
const result = await distro['findPackageForDownload'](version);
80+
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`;
81+
82+
expect(result.url).toBe(expectedUrl);
83+
}
84+
);
85+
86+
it('should throw an error', async () => {
87+
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
88+
/Oracle JDK is only supported for JDK 17 and later/
89+
);
90+
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
91+
/Oracle JDK is only supported for JDK 17 and later/
92+
);
93+
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
94+
/Could not find Oracle JDK for SemVer */
95+
);
96+
});
97+
});

__tests__/verify-java.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424
ACTUAL_JAVA_VERSION="$(java -version 2>&1)"
2525
echo "Found java version: $ACTUAL_JAVA_VERSION"
2626

27-
GREP_RESULT=$(echo $ACTUAL_JAVA_VERSION | grep "^openjdk version \"$EXPECTED_JAVA_VERSION")
27+
GREP_RESULT=$(echo $ACTUAL_JAVA_VERSION | grep -E "^(openjdk|java) version \"$EXPECTED_JAVA_VERSION")
2828
if [ -z "$GREP_RESULT" ]; then
2929
echo "::error::Unexpected version"
3030
echo "Expected version: $EXPECTED_JAVA_VERSION"

dist/setup/index.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104159,6 +104159,7 @@ const installer_4 = __nccwpck_require__(8579);
104159104159
const installer_5 = __nccwpck_require__(883);
104160104160
const installer_6 = __nccwpck_require__(3613);
104161104161
const installer_7 = __nccwpck_require__(4750);
104162+
const installer_8 = __nccwpck_require__(4298);
104162104163
var JavaDistribution;
104163104164
(function (JavaDistribution) {
104164104165
JavaDistribution["Adopt"] = "adopt";
@@ -104170,6 +104171,7 @@ var JavaDistribution;
104170104171
JavaDistribution["JdkFile"] = "jdkfile";
104171104172
JavaDistribution["Microsoft"] = "microsoft";
104172104173
JavaDistribution["Corretto"] = "corretto";
104174+
JavaDistribution["Oracle"] = "oracle";
104173104175
})(JavaDistribution || (JavaDistribution = {}));
104174104176
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
104175104177
switch (distributionName) {
@@ -104190,6 +104192,8 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
104190104192
return new installer_6.MicrosoftDistributions(installerOptions);
104191104193
case JavaDistribution.Corretto:
104192104194
return new installer_7.CorrettoDistribution(installerOptions);
104195+
case JavaDistribution.Oracle:
104196+
return new installer_8.OracleDistribution(installerOptions);
104193104197
default:
104194104198
return null;
104195104199
}
@@ -104597,6 +104601,125 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
104597104601
exports.MicrosoftDistributions = MicrosoftDistributions;
104598104602

104599104603

104604+
/***/ }),
104605+
104606+
/***/ 4298:
104607+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
104608+
104609+
"use strict";
104610+
104611+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
104612+
if (k2 === undefined) k2 = k;
104613+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
104614+
}) : (function(o, m, k, k2) {
104615+
if (k2 === undefined) k2 = k;
104616+
o[k2] = m[k];
104617+
}));
104618+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
104619+
Object.defineProperty(o, "default", { enumerable: true, value: v });
104620+
}) : function(o, v) {
104621+
o["default"] = v;
104622+
});
104623+
var __importStar = (this && this.__importStar) || function (mod) {
104624+
if (mod && mod.__esModule) return mod;
104625+
var result = {};
104626+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
104627+
__setModuleDefault(result, mod);
104628+
return result;
104629+
};
104630+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
104631+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
104632+
return new (P || (P = Promise))(function (resolve, reject) {
104633+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
104634+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
104635+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
104636+
step((generator = generator.apply(thisArg, _arguments || [])).next());
104637+
});
104638+
};
104639+
var __importDefault = (this && this.__importDefault) || function (mod) {
104640+
return (mod && mod.__esModule) ? mod : { "default": mod };
104641+
};
104642+
Object.defineProperty(exports, "__esModule", ({ value: true }));
104643+
exports.OracleDistribution = void 0;
104644+
const core = __importStar(__nccwpck_require__(2186));
104645+
const tc = __importStar(__nccwpck_require__(7784));
104646+
const fs_1 = __importDefault(__nccwpck_require__(7147));
104647+
const path_1 = __importDefault(__nccwpck_require__(1017));
104648+
const base_installer_1 = __nccwpck_require__(9741);
104649+
const util_1 = __nccwpck_require__(2629);
104650+
const http_client_1 = __nccwpck_require__(9925);
104651+
const ORACLE_DL_BASE = 'https://download.oracle.com/java';
104652+
class OracleDistribution extends base_installer_1.JavaBase {
104653+
constructor(installerOptions) {
104654+
super('Oracle', installerOptions);
104655+
}
104656+
downloadTool(javaRelease) {
104657+
return __awaiter(this, void 0, void 0, function* () {
104658+
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
104659+
const javaArchivePath = yield tc.downloadTool(javaRelease.url);
104660+
core.info(`Extracting Java archive...`);
104661+
let extension = util_1.getDownloadArchiveExtension();
104662+
let extractedJavaPath = yield util_1.extractJdkFile(javaArchivePath, extension);
104663+
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
104664+
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
104665+
const version = this.getToolcacheVersionName(javaRelease.version);
104666+
let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
104667+
return { version: javaRelease.version, path: javaPath };
104668+
});
104669+
}
104670+
findPackageForDownload(range) {
104671+
return __awaiter(this, void 0, void 0, function* () {
104672+
const arch = this.distributionArchitecture();
104673+
if (arch !== 'x64' && arch !== 'aarch64') {
104674+
throw new Error(`Unsupported architecture: ${this.architecture}`);
104675+
}
104676+
if (!this.stable) {
104677+
throw new Error('Early access versions are not supported');
104678+
}
104679+
if (this.packageType !== 'jdk') {
104680+
throw new Error('Oracle JDK provides only the `jdk` package type');
104681+
}
104682+
const platform = this.getPlatform();
104683+
const extension = util_1.getDownloadArchiveExtension();
104684+
let major;
104685+
let fileUrl;
104686+
if (range.includes('.')) {
104687+
major = range.split('.')[0];
104688+
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
104689+
}
104690+
else {
104691+
major = range;
104692+
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
104693+
}
104694+
if (parseInt(major) < 17) {
104695+
throw new Error('Oracle JDK is only supported for JDK 17 and later');
104696+
}
104697+
const response = yield this.http.head(fileUrl);
104698+
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
104699+
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
104700+
}
104701+
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
104702+
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
104703+
}
104704+
return { url: fileUrl, version: range };
104705+
});
104706+
}
104707+
getPlatform(platform = process.platform) {
104708+
switch (platform) {
104709+
case 'darwin':
104710+
return 'macos';
104711+
case 'win32':
104712+
return 'windows';
104713+
case 'linux':
104714+
return 'linux';
104715+
default:
104716+
throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`);
104717+
}
104718+
}
104719+
}
104720+
exports.OracleDistribution = OracleDistribution;
104721+
104722+
104600104723
/***/ }),
104601104724

104602104725
/***/ 8579:

docs/advanced-usage.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Liberica](#Liberica)
77
- [Microsoft](#Microsoft)
88
- [Amazon Corretto](#Amazon-Corretto)
9+
- [Oracle](#Oracle)
910
- [Installing custom Java package type](#Installing-custom-Java-package-type)
1011
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
1112
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
@@ -110,6 +111,19 @@ steps:
110111
- run: java -cp java HelloWorldApp
111112
```
112113

114+
### Oracle
115+
**NOTE:** Oracle Java SE Development Kit is only available for version 17 and later.
116+
117+
```yaml
118+
steps:
119+
- uses: actions/checkout@v3
120+
- uses: actions/setup-java@v3
121+
with:
122+
distribution: 'oracle'
123+
java-version: '17'
124+
- run: java -cp java HelloWorldApp
125+
```
126+
113127
## Installing custom Java package type
114128
```yaml
115129
steps:

src/distributions/distribution-factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TemurinDistribution, TemurinImplementation } from './temurin/installer'
77
import { LibericaDistributions } from './liberica/installer';
88
import { MicrosoftDistributions } from './microsoft/installer';
99
import { CorrettoDistribution } from './corretto/installer';
10+
import { OracleDistribution } from './oracle/installer';
1011

1112
enum JavaDistribution {
1213
Adopt = 'adopt',
@@ -17,7 +18,8 @@ enum JavaDistribution {
1718
Liberica = 'liberica',
1819
JdkFile = 'jdkfile',
1920
Microsoft = 'microsoft',
20-
Corretto = 'corretto'
21+
Corretto = 'corretto',
22+
Oracle = 'oracle'
2123
}
2224

2325
export function getJavaDistribution(
@@ -43,6 +45,8 @@ export function getJavaDistribution(
4345
return new MicrosoftDistributions(installerOptions);
4446
case JavaDistribution.Corretto:
4547
return new CorrettoDistribution(installerOptions);
48+
case JavaDistribution.Oracle:
49+
return new OracleDistribution(installerOptions);
4650
default:
4751
return null;
4852
}

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