mirror of
https://github.com/actions/setup-java.git
synced 2026-07-28 07:04:32 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
333d9ce35a | ||
|
|
cb48866ec3 | ||
|
|
2c4a2dda70 | ||
|
|
a7c4828ceb | ||
|
|
d9cbbc45bb |
@@ -56,8 +56,6 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
||||||
|
|
||||||
- `force-download`: Set to `true` to always download Java and replace any matching version in the tool cache. This can help make builds reproducible when a runner image has modified a pre-installed JDK, such as its `cacerts` file. Default value: `false`.
|
|
||||||
|
|
||||||
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
|
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
|
||||||
|
|
||||||
- `problem-matcher`: Set to `false` to disable Java problem matcher annotations (compiler diagnostics and uncaught exceptions). Default value: `true`. See [Java problem matcher](docs/advanced-usage.md#java-problem-matcher-compiler-annotations) for details and annotation limits.
|
- `problem-matcher`: Set to `false` to disable Java problem matcher annotations (compiler diagnostics and uncaught exceptions). Default value: `true`. See [Java problem matcher](docs/advanced-usage.md#java-problem-matcher-compiler-annotations) for details and annotation limits.
|
||||||
@@ -148,6 +146,7 @@ Currently, the following distributions are supported:
|
|||||||
| `corretto` | [Amazon Corretto Build of OpenJDK](https://aws.amazon.com/corretto/) | [`corretto` license](https://aws.amazon.com/corretto/faqs/)
|
| `corretto` | [Amazon Corretto Build of OpenJDK](https://aws.amazon.com/corretto/) | [`corretto` license](https://aws.amazon.com/corretto/faqs/)
|
||||||
| `semeru` | [IBM Semeru Runtime Open Edition](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [`semeru` license](https://openjdk.java.net/legal/gplv2+ce.html) |
|
| `semeru` | [IBM Semeru Runtime Open Edition](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [`semeru` license](https://openjdk.java.net/legal/gplv2+ce.html) |
|
||||||
| `oracle` | [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) | [`oracle` license](https://java.com/freeuselicense)
|
| `oracle` | [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) | [`oracle` license](https://java.com/freeuselicense)
|
||||||
|
| `openjdk` | [OpenJDK](https://jdk.java.net/) | [`openjdk` license](https://openjdk.org/legal/gplv2+ce.html)
|
||||||
| `dragonwell` | [Alibaba Dragonwell JDK](https://dragonwell-jdk.io/) | [`dragonwell` license](https://www.aliyun.com/product/dragonwell/)
|
| `dragonwell` | [Alibaba Dragonwell JDK](https://dragonwell-jdk.io/) | [`dragonwell` license](https://www.aliyun.com/product/dragonwell/)
|
||||||
| `sapmachine` | [SAP SapMachine JDK/JRE](https://sapmachine.io/) | [`sapmachine` license](https://github.com/SAP/SapMachine/blob/sapmachine/LICENSE)
|
| `sapmachine` | [SAP SapMachine JDK/JRE](https://sapmachine.io/) | [`sapmachine` license](https://github.com/SAP/SapMachine/blob/sapmachine/LICENSE)
|
||||||
| `graalvm` | [Oracle GraalVM](https://www.graalvm.org/) | [`graalvm` license](https://www.oracle.com/downloads/licenses/graal-free-license.html)
|
| `graalvm` | [Oracle GraalVM](https://www.graalvm.org/) | [`graalvm` license](https://www.oracle.com/downloads/licenses/graal-free-license.html)
|
||||||
|
|||||||
@@ -443,35 +443,6 @@ describe('setupJava', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should download java when force-download is enabled, even if the version is cached', async () => {
|
|
||||||
mockJavaBase = new EmptyJavaBase({
|
|
||||||
version: actualJavaVersion,
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false,
|
|
||||||
forceDownload: true
|
|
||||||
});
|
|
||||||
const findInToolcache = jest.fn(() => ({
|
|
||||||
version: actualJavaVersion,
|
|
||||||
path: javaPathInstalled
|
|
||||||
}));
|
|
||||||
mockJavaBase['findInToolcache'] = findInToolcache;
|
|
||||||
|
|
||||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
|
||||||
version: actualJavaVersion,
|
|
||||||
path: javaPathInstalled
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(findInToolcache).not.toHaveBeenCalled();
|
|
||||||
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
|
|
||||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
|
||||||
`Java ${actualJavaVersion} was downloaded`
|
|
||||||
);
|
|
||||||
expect(spyCoreInfo).not.toHaveBeenCalledWith(
|
|
||||||
`Resolved Java ${actualJavaVersion} from tool-cache`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -166,29 +166,6 @@ describe('GraalVMDistribution', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setJavaDefault', () => {
|
|
||||||
it('should set GRAALVM_HOME for Oracle GraalVM', () => {
|
|
||||||
(distribution as any).setJavaDefault('17.0.5', '/cached/java/path');
|
|
||||||
|
|
||||||
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
||||||
'GRAALVM_HOME',
|
|
||||||
'/cached/java/path'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set GRAALVM_HOME for GraalVM Community', () => {
|
|
||||||
(communityDistribution as any).setJavaDefault(
|
|
||||||
'17.0.5',
|
|
||||||
'/cached/java/path'
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
||||||
'GRAALVM_HOME',
|
|
||||||
'/cached/java/path'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('downloadTool', () => {
|
describe('downloadTool', () => {
|
||||||
const javaRelease = {
|
const javaRelease = {
|
||||||
version: '17.0.5',
|
version: '17.0.5',
|
||||||
|
|||||||
@@ -208,29 +208,6 @@ describe('setupJava', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('java is unpacked from jdkfile when force-download is enabled', async () => {
|
|
||||||
const inputs = {
|
|
||||||
version: actualJavaVersion,
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false,
|
|
||||||
forceDownload: true
|
|
||||||
};
|
|
||||||
|
|
||||||
mockJavaBase = new LocalDistribution(inputs, expectedJdkFile);
|
|
||||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
|
||||||
version: actualJavaVersion,
|
|
||||||
path: javaPath
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(spyGetToolcachePath).not.toHaveBeenCalled();
|
|
||||||
expect(spyUtilsExtractJdkFile).toHaveBeenCalledWith(expectedJdkFile);
|
|
||||||
expect(spyTcCacheDir).toHaveBeenCalled();
|
|
||||||
expect(spyCoreInfo).not.toHaveBeenCalledWith(
|
|
||||||
`Resolved Java ${actualJavaVersion} from tool-cache`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("java is resolved from toolcache, jdkfile doesn't exist", async () => {
|
it("java is resolved from toolcache, jdkfile doesn't exist", async () => {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
version: actualJavaVersion,
|
version: actualJavaVersion,
|
||||||
|
|||||||
@@ -0,0 +1,211 @@
|
|||||||
|
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||||
|
import {HttpClient} from '@actions/http-client';
|
||||||
|
|
||||||
|
jest.unstable_mockModule('@actions/core', () => ({
|
||||||
|
info: jest.fn(),
|
||||||
|
warning: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
notice: jest.fn(),
|
||||||
|
setFailed: jest.fn(),
|
||||||
|
setOutput: jest.fn(),
|
||||||
|
getInput: jest.fn(),
|
||||||
|
getBooleanInput: jest.fn(),
|
||||||
|
getMultilineInput: jest.fn(),
|
||||||
|
addPath: jest.fn(),
|
||||||
|
exportVariable: jest.fn(),
|
||||||
|
saveState: jest.fn(),
|
||||||
|
getState: jest.fn(),
|
||||||
|
setSecret: jest.fn(),
|
||||||
|
isDebug: jest.fn(() => false),
|
||||||
|
startGroup: jest.fn(),
|
||||||
|
endGroup: jest.fn(),
|
||||||
|
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
||||||
|
toPlatformPath: jest.fn((value: string) => value),
|
||||||
|
toWin32Path: jest.fn((value: string) => value),
|
||||||
|
toPosixPath: jest.fn((value: string) => value)
|
||||||
|
}));
|
||||||
|
|
||||||
|
const {OpenJdkDistribution} =
|
||||||
|
await import('../../src/distributions/openjdk/installer.js');
|
||||||
|
const {getJavaDistribution} =
|
||||||
|
await import('../../src/distributions/distribution-factory.js');
|
||||||
|
|
||||||
|
const homePage = `
|
||||||
|
<a href="/26/">JDK 26</a>
|
||||||
|
<a href="/27/">JDK
|
||||||
|
27</a>
|
||||||
|
`;
|
||||||
|
const currentPage = `
|
||||||
|
<a href="https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
<a href="https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-aarch64_bin.tar.gz">tar.gz</a>
|
||||||
|
`;
|
||||||
|
const earlyAccessPage = `
|
||||||
|
<a href="https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
`;
|
||||||
|
const archivePage = `
|
||||||
|
<a href="https://download.java.net/java/GA/jdk26.0.1/hash/8/GPL/openjdk-26.0.1_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
<a href="https://download.java.net/java/GA/jdk25/hash/36/GPL/openjdk-25_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
<a href="https://download.java.net/java/GA/jdk18.0.1.1/hash/2/GPL/openjdk-18.0.1.1_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
<th>9.0.4 (build 9.0.4+11)</th>
|
||||||
|
<a href="https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz">tar.gz</a>
|
||||||
|
`;
|
||||||
|
|
||||||
|
function createDistribution(
|
||||||
|
version = '26',
|
||||||
|
architecture = 'x64',
|
||||||
|
packageType = 'jdk'
|
||||||
|
) {
|
||||||
|
return new OpenJdkDistribution({
|
||||||
|
version,
|
||||||
|
architecture,
|
||||||
|
packageType,
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('OpenJdkDistribution', () => {
|
||||||
|
let getSpy: jest.SpiedFunction<HttpClient['get']>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
getSpy = jest
|
||||||
|
.spyOn(HttpClient.prototype, 'get')
|
||||||
|
.mockImplementation(async url => {
|
||||||
|
const pages: Record<string, string> = {
|
||||||
|
'https://jdk.java.net/': homePage,
|
||||||
|
'https://jdk.java.net/26/': currentPage,
|
||||||
|
'https://jdk.java.net/27/': earlyAccessPage,
|
||||||
|
'https://jdk.java.net/archive/': archivePage
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
readBody: async () => pages[url] ?? ''
|
||||||
|
} as Awaited<ReturnType<HttpClient['get']>>;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves the newest matching GA release', async () => {
|
||||||
|
const result = await createDistribution()['findPackageForDownload']('26');
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
version: '26.0.2+10',
|
||||||
|
url: 'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves an archived GA release', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('26.0.1')['findPackageForDownload']('26.0.1');
|
||||||
|
|
||||||
|
expect(result.version).toBe('26.0.1+8');
|
||||||
|
expect(result.url).toContain('/openjdk-26.0.1_linux-x64_bin.tar.gz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves an exact GA build', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('26.0.2+10')['findPackageForDownload'](
|
||||||
|
'26.0.2+10'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.version).toBe('26.0.2+10');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves an exact build from a legacy archive heading', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('9.0.4+11')['findPackageForDownload'](
|
||||||
|
'9.0.4+11'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.version).toBe('9.0.4+11');
|
||||||
|
expect(result.url).toContain('/binaries/openjdk-9.0.4_linux-x64_bin');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves a four-field Java version', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('18.0.1.1')['findPackageForDownload'](
|
||||||
|
'18.0.1+1'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.version).toBe('18.0.1+1');
|
||||||
|
expect(result.url).toContain('/openjdk-18.0.1.1_linux-x64_bin.tar.gz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves an early-access release without requesting the archive', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('27-ea')['findPackageForDownload']('27');
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
version: '27.0.0+32',
|
||||||
|
url: 'https://download.java.net/java/early_access/jdk27/32/GPL/openjdk-27-ea+32_linux-x64_bin.tar.gz'
|
||||||
|
});
|
||||||
|
expect(getSpy).not.toHaveBeenCalledWith('https://jdk.java.net/archive/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports available versions when no release matches', async () => {
|
||||||
|
await expect(
|
||||||
|
createDistribution()['findPackageForDownload']('24')
|
||||||
|
).rejects.toThrow(
|
||||||
|
"No matching version found for SemVer '24'.\nDistribution: OpenJDK"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['jre', 'OpenJDK provides only the `jdk` package type'],
|
||||||
|
['jdk+fx', 'OpenJDK provides only the `jdk` package type']
|
||||||
|
])('rejects the %s package type', async (packageType, message) => {
|
||||||
|
await expect(
|
||||||
|
createDistribution('26', 'x64', packageType)['findPackageForDownload'](
|
||||||
|
'26'
|
||||||
|
)
|
||||||
|
).rejects.toThrow(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects unsupported architectures', async () => {
|
||||||
|
await expect(
|
||||||
|
createDistribution('26', 'x86')['findPackageForDownload']('26')
|
||||||
|
).rejects.toThrow('Unsupported architecture: x86');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('maps supported platforms', () => {
|
||||||
|
const distribution = createDistribution();
|
||||||
|
|
||||||
|
expect(distribution['getPlatform']('linux')).toBe('linux');
|
||||||
|
expect(distribution['getPlatform']('darwin')).toBe('macos');
|
||||||
|
expect(distribution['getPlatform']('win32')).toBe('windows');
|
||||||
|
expect(() => distribution['getPlatform']('freebsd')).toThrow(
|
||||||
|
"Platform 'freebsd' is not supported"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses legacy platform names and archive formats', () => {
|
||||||
|
const distribution = createDistribution();
|
||||||
|
const macRelease = distribution['parseReleases'](
|
||||||
|
'<a href="https://download.java.net/java/GA/jdk16/hash/7/GPL/openjdk-16_osx-x64_bin.tar.gz">tar.gz</a>',
|
||||||
|
'macos',
|
||||||
|
'x64'
|
||||||
|
);
|
||||||
|
const windowsRelease = distribution['parseReleases'](
|
||||||
|
'<a href="https://download.java.net/java/GA/jdk10/hash/13/openjdk-10.0.2_windows-x64_bin.tar.gz">tar.gz</a>',
|
||||||
|
'windows',
|
||||||
|
'x64'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(macRelease[0].version).toBe('16.0.0+7');
|
||||||
|
expect(windowsRelease[0].version).toBe('10.0.2+13');
|
||||||
|
expect(windowsRelease[0].url.endsWith('.tar.gz')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is registered in the distribution factory', () => {
|
||||||
|
const distribution = getJavaDistribution('openjdk', {
|
||||||
|
version: '26',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(distribution).toBeInstanceOf(OpenJdkDistribution);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -30,10 +30,6 @@ inputs:
|
|||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
force-download:
|
|
||||||
description: 'Set this option to always download Java and replace any matching version in the tool cache'
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
set-default:
|
set-default:
|
||||||
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
|
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
Vendored
-1
@@ -97311,7 +97311,6 @@ const INPUT_DISTRIBUTION = 'distribution';
|
|||||||
const INPUT_JDK_FILE = 'jdk-file';
|
const INPUT_JDK_FILE = 'jdk-file';
|
||||||
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||||
const INPUT_CHECK_LATEST = 'check-latest';
|
const INPUT_CHECK_LATEST = 'check-latest';
|
||||||
const INPUT_FORCE_DOWNLOAD = 'force-download';
|
|
||||||
const INPUT_SET_DEFAULT = 'set-default';
|
const INPUT_SET_DEFAULT = 'set-default';
|
||||||
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
||||||
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
|
|||||||
Vendored
+111
-16
@@ -72088,7 +72088,6 @@ const INPUT_DISTRIBUTION = 'distribution';
|
|||||||
const INPUT_JDK_FILE = 'jdk-file';
|
const INPUT_JDK_FILE = 'jdk-file';
|
||||||
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||||
const INPUT_CHECK_LATEST = 'check-latest';
|
const INPUT_CHECK_LATEST = 'check-latest';
|
||||||
const INPUT_FORCE_DOWNLOAD = 'force-download';
|
|
||||||
const INPUT_SET_DEFAULT = 'set-default';
|
const INPUT_SET_DEFAULT = 'set-default';
|
||||||
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
||||||
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
@@ -129291,7 +129290,6 @@ class JavaBase {
|
|||||||
stable;
|
stable;
|
||||||
latest;
|
latest;
|
||||||
checkLatest;
|
checkLatest;
|
||||||
forceDownload;
|
|
||||||
setDefault;
|
setDefault;
|
||||||
verifySignature;
|
verifySignature;
|
||||||
verifySignaturePublicKey;
|
verifySignaturePublicKey;
|
||||||
@@ -129309,7 +129307,6 @@ class JavaBase {
|
|||||||
this.architecture = installerOptions.architecture || external_os_default().arch();
|
this.architecture = installerOptions.architecture || external_os_default().arch();
|
||||||
this.packageType = installerOptions.packageType;
|
this.packageType = installerOptions.packageType;
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
this.forceDownload = installerOptions.forceDownload ?? false;
|
|
||||||
this.setDefault =
|
this.setDefault =
|
||||||
installerOptions.setDefault !== undefined
|
installerOptions.setDefault !== undefined
|
||||||
? installerOptions.setDefault
|
? installerOptions.setDefault
|
||||||
@@ -129321,7 +129318,7 @@ class JavaBase {
|
|||||||
if (this.verifySignature && !this.supportsSignatureVerification()) {
|
if (this.verifySignature && !this.supportsSignatureVerification()) {
|
||||||
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
|
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
|
||||||
}
|
}
|
||||||
let foundJava = this.forceDownload ? null : this.findInToolcache();
|
let foundJava = this.findInToolcache();
|
||||||
if (foundJava && !this.checkLatest && !this.latest) {
|
if (foundJava && !this.checkLatest && !this.latest) {
|
||||||
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
}
|
}
|
||||||
@@ -129345,8 +129342,7 @@ class JavaBase {
|
|||||||
}
|
}
|
||||||
const javaRelease = await this.findPackageForDownload(this.version);
|
const javaRelease = await this.findPackageForDownload(this.version);
|
||||||
info(`Resolved latest version as ${javaRelease.version}`);
|
info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
if (!this.forceDownload &&
|
if (foundJava?.version === javaRelease.version) {
|
||||||
foundJava?.version === javaRelease.version) {
|
|
||||||
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -129621,7 +129617,7 @@ class LocalDistribution extends JavaBase {
|
|||||||
if (this.latest) {
|
if (this.latest) {
|
||||||
throw new Error("The 'latest' version alias is not supported for the 'jdkfile' distribution. Please specify a concrete version.");
|
throw new Error("The 'latest' version alias is not supported for the 'jdkfile' distribution. Please specify a concrete version.");
|
||||||
}
|
}
|
||||||
let foundJava = this.forceDownload ? null : this.findInToolcache();
|
let foundJava = this.findInToolcache();
|
||||||
if (foundJava) {
|
if (foundJava) {
|
||||||
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
}
|
}
|
||||||
@@ -131332,10 +131328,6 @@ class GraalVMDistribution extends JavaBase {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setJavaDefault(version, toolPath) {
|
|
||||||
super.setJavaDefault(version, toolPath);
|
|
||||||
exportVariable('GRAALVM_HOME', toolPath);
|
|
||||||
}
|
|
||||||
async findPackageForDownload(range) {
|
async findPackageForDownload(range) {
|
||||||
this.validateVersionRange(range);
|
this.validateVersionRange(range);
|
||||||
const arch = this.getSupportedArchitecture();
|
const arch = this.getSupportedArchitecture();
|
||||||
@@ -131882,6 +131874,109 @@ class KonaDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: ./src/distributions/openjdk/installer.ts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const OPENJDK_BASE_URL = 'https://jdk.java.net';
|
||||||
|
class OpenJdkDistribution extends JavaBase {
|
||||||
|
constructor(installerOptions) {
|
||||||
|
super('OpenJDK', installerOptions);
|
||||||
|
}
|
||||||
|
async findPackageForDownload(range) {
|
||||||
|
if (this.packageType !== 'jdk') {
|
||||||
|
throw new Error('OpenJDK provides only the `jdk` package type');
|
||||||
|
}
|
||||||
|
const arch = this.distributionArchitecture();
|
||||||
|
if (!['x64', 'aarch64'].includes(arch)) {
|
||||||
|
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||||
|
}
|
||||||
|
const platform = this.getPlatform();
|
||||||
|
const releases = await this.getAvailableVersions(platform, arch);
|
||||||
|
const matchingReleases = releases
|
||||||
|
.filter(release => isVersionSatisfies(range, release.version))
|
||||||
|
.sort((left, right) => -semver_default().compareBuild(left.version, right.version));
|
||||||
|
if (!matchingReleases.length) {
|
||||||
|
throw this.createVersionNotFoundError(range, releases.map(release => release.version), `Platform: ${platform}`);
|
||||||
|
}
|
||||||
|
return matchingReleases[0];
|
||||||
|
}
|
||||||
|
async downloadTool(javaRelease) {
|
||||||
|
info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||||
|
let javaArchivePath = await downloadTool(javaRelease.url);
|
||||||
|
info(`Extracting Java archive...`);
|
||||||
|
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||||
|
if (extension === 'zip') {
|
||||||
|
javaArchivePath = renameWinArchive(javaArchivePath);
|
||||||
|
}
|
||||||
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
|
const archiveName = external_fs_default().readdirSync(extractedJavaPath)[0];
|
||||||
|
const archivePath = external_path_default().join(extractedJavaPath, archiveName);
|
||||||
|
const javaPath = await cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaRelease.version), this.architecture);
|
||||||
|
return { version: javaRelease.version, path: javaPath };
|
||||||
|
}
|
||||||
|
async getAvailableVersions(platform, arch) {
|
||||||
|
const homePage = await this.fetchPage(`${OPENJDK_BASE_URL}/`);
|
||||||
|
const releasePageUrls = Array.from(homePage.matchAll(/href="\/(\d+)\/">JDK\s+\d+/g), match => `${OPENJDK_BASE_URL}/${match[1]}/`);
|
||||||
|
const pages = await Promise.all(releasePageUrls.map(url => this.fetchPage(url)));
|
||||||
|
if (this.stable) {
|
||||||
|
pages.push(await this.fetchPage(`${OPENJDK_BASE_URL}/archive/`));
|
||||||
|
}
|
||||||
|
const releases = pages.flatMap(page => this.parseReleases(page, platform, arch));
|
||||||
|
return releases.filter(release => release.url.includes('/early_access/') !== this.stable);
|
||||||
|
}
|
||||||
|
async fetchPage(url) {
|
||||||
|
const response = await this.http.get(url);
|
||||||
|
return response.readBody();
|
||||||
|
}
|
||||||
|
parseReleases(html, platform, arch) {
|
||||||
|
const platformPattern = platform === 'macos' ? '(?:macos|osx)' : platform;
|
||||||
|
const extensionPattern = platform === 'windows' ? '(?:zip|tar\\.gz)' : 'tar\\.gz';
|
||||||
|
const pattern = new RegExp(`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platformPattern}-${arch}_bin\\.${extensionPattern})"`, 'g');
|
||||||
|
return Array.from(html.matchAll(pattern), match => {
|
||||||
|
const url = match[1];
|
||||||
|
const build = url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1] ??
|
||||||
|
this.findBuildInArchiveHeading(html, match.index, match[2]);
|
||||||
|
return {
|
||||||
|
version: this.toSemver(match[2], build),
|
||||||
|
url
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
findBuildInArchiveHeading(html, assetIndex, version) {
|
||||||
|
const headings = Array.from(html.slice(0, assetIndex).matchAll(/\(build\s+([^)]+)\)/g));
|
||||||
|
const headingVersion = headings.at(-1)?.[1];
|
||||||
|
if (!headingVersion) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const [javaVersion, build] = headingVersion.split('+');
|
||||||
|
return javaVersion === version ? build : undefined;
|
||||||
|
}
|
||||||
|
toSemver(version, urlBuild) {
|
||||||
|
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||||
|
const versionParts = javaVersion.split('.');
|
||||||
|
const normalizedVersion = convertVersionToSemver(versionParts.length === 1 ? `${javaVersion}.0.0` : javaVersion);
|
||||||
|
const build = filenameBuild ?? (versionParts.length <= 3 ? urlBuild : undefined);
|
||||||
|
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
||||||
|
}
|
||||||
|
getPlatform(platform = process.platform) {
|
||||||
|
switch (platform) {
|
||||||
|
case 'darwin':
|
||||||
|
return 'macos';
|
||||||
|
case 'linux':
|
||||||
|
return 'linux';
|
||||||
|
case 'win32':
|
||||||
|
return 'windows';
|
||||||
|
default:
|
||||||
|
throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./src/distributions/distribution-factory.ts
|
;// CONCATENATED MODULE: ./src/distributions/distribution-factory.ts
|
||||||
|
|
||||||
|
|
||||||
@@ -131898,6 +131993,7 @@ class KonaDistribution extends JavaBase {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var JavaDistribution;
|
var JavaDistribution;
|
||||||
(function (JavaDistribution) {
|
(function (JavaDistribution) {
|
||||||
JavaDistribution["Adopt"] = "adopt";
|
JavaDistribution["Adopt"] = "adopt";
|
||||||
@@ -131918,6 +132014,7 @@ var JavaDistribution;
|
|||||||
JavaDistribution["GraalVMCommunity"] = "graalvm-community";
|
JavaDistribution["GraalVMCommunity"] = "graalvm-community";
|
||||||
JavaDistribution["JetBrains"] = "jetbrains";
|
JavaDistribution["JetBrains"] = "jetbrains";
|
||||||
JavaDistribution["Kona"] = "kona";
|
JavaDistribution["Kona"] = "kona";
|
||||||
|
JavaDistribution["OpenJdk"] = "openjdk";
|
||||||
})(JavaDistribution || (JavaDistribution = {}));
|
})(JavaDistribution || (JavaDistribution = {}));
|
||||||
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
||||||
switch (distributionName) {
|
switch (distributionName) {
|
||||||
@@ -131956,6 +132053,8 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
|||||||
return new JetBrainsDistribution(installerOptions);
|
return new JetBrainsDistribution(installerOptions);
|
||||||
case JavaDistribution.Kona:
|
case JavaDistribution.Kona:
|
||||||
return new KonaDistribution(installerOptions);
|
return new KonaDistribution(installerOptions);
|
||||||
|
case JavaDistribution.OpenJdk:
|
||||||
|
return new OpenJdkDistribution(installerOptions);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -132045,7 +132144,6 @@ async function run() {
|
|||||||
const cache = getInput(INPUT_CACHE);
|
const cache = getInput(INPUT_CACHE);
|
||||||
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
|
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
|
||||||
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
|
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
|
||||||
const forceDownload = util_getBooleanInput(INPUT_FORCE_DOWNLOAD, false);
|
|
||||||
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
|
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
|
||||||
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
|
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
|
||||||
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||||
@@ -132077,7 +132175,6 @@ async function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -132096,7 +132193,6 @@ async function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -132131,12 +132227,11 @@ function getJdkFileInput() {
|
|||||||
return jdkFile || deprecatedJdkFile;
|
return jdkFile || deprecatedJdkFile;
|
||||||
}
|
}
|
||||||
async function installVersion(version, options, toolchainId = 0) {
|
async function installVersion(version, options, toolchainId = 0) {
|
||||||
const { distributionName, jdkFile, architecture, packageType, checkLatest, forceDownload, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
||||||
const installerOptions = {
|
const installerOptions = {
|
||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export const INPUT_DISTRIBUTION = 'distribution';
|
|||||||
export const INPUT_JDK_FILE = 'jdk-file';
|
export const INPUT_JDK_FILE = 'jdk-file';
|
||||||
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||||
export const INPUT_FORCE_DOWNLOAD = 'force-download';
|
|
||||||
export const INPUT_SET_DEFAULT = 'set-default';
|
export const INPUT_SET_DEFAULT = 'set-default';
|
||||||
export const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
export const INPUT_PROBLEM_MATCHER = 'problem-matcher';
|
||||||
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ export abstract class JavaBase {
|
|||||||
protected stable: boolean;
|
protected stable: boolean;
|
||||||
protected latest: boolean;
|
protected latest: boolean;
|
||||||
protected checkLatest: boolean;
|
protected checkLatest: boolean;
|
||||||
protected forceDownload: boolean;
|
|
||||||
protected setDefault: boolean;
|
protected setDefault: boolean;
|
||||||
protected verifySignature: boolean;
|
protected verifySignature: boolean;
|
||||||
protected verifySignaturePublicKey: string | undefined;
|
protected verifySignaturePublicKey: string | undefined;
|
||||||
@@ -47,7 +46,6 @@ export abstract class JavaBase {
|
|||||||
this.architecture = installerOptions.architecture || os.arch();
|
this.architecture = installerOptions.architecture || os.arch();
|
||||||
this.packageType = installerOptions.packageType;
|
this.packageType = installerOptions.packageType;
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
this.forceDownload = installerOptions.forceDownload ?? false;
|
|
||||||
this.setDefault =
|
this.setDefault =
|
||||||
installerOptions.setDefault !== undefined
|
installerOptions.setDefault !== undefined
|
||||||
? installerOptions.setDefault
|
? installerOptions.setDefault
|
||||||
@@ -70,7 +68,7 @@ export abstract class JavaBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let foundJava = this.forceDownload ? null : this.findInToolcache();
|
let foundJava = this.findInToolcache();
|
||||||
if (foundJava && !this.checkLatest && !this.latest) {
|
if (foundJava && !this.checkLatest && !this.latest) {
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
} else {
|
} else {
|
||||||
@@ -93,10 +91,7 @@ export abstract class JavaBase {
|
|||||||
}
|
}
|
||||||
const javaRelease = await this.findPackageForDownload(this.version);
|
const javaRelease = await this.findPackageForDownload(this.version);
|
||||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||||
if (
|
if (foundJava?.version === javaRelease.version) {
|
||||||
!this.forceDownload &&
|
|
||||||
foundJava?.version === javaRelease.version
|
|
||||||
) {
|
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
} else {
|
} else {
|
||||||
core.info('Trying to download...');
|
core.info('Trying to download...');
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ export interface JavaInstallerOptions {
|
|||||||
architecture: string;
|
architecture: string;
|
||||||
packageType: string;
|
packageType: string;
|
||||||
checkLatest: boolean;
|
checkLatest: boolean;
|
||||||
forceDownload?: boolean;
|
|
||||||
setDefault?: boolean;
|
setDefault?: boolean;
|
||||||
verifySignature?: boolean;
|
verifySignature?: boolean;
|
||||||
verifySignaturePublicKey?: string;
|
verifySignaturePublicKey?: string;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
} from './graalvm/installer.js';
|
} from './graalvm/installer.js';
|
||||||
import {JetBrainsDistribution} from './jetbrains/installer.js';
|
import {JetBrainsDistribution} from './jetbrains/installer.js';
|
||||||
import {KonaDistribution} from './kona/installer.js';
|
import {KonaDistribution} from './kona/installer.js';
|
||||||
|
import {OpenJdkDistribution} from './openjdk/installer.js';
|
||||||
|
|
||||||
enum JavaDistribution {
|
enum JavaDistribution {
|
||||||
Adopt = 'adopt',
|
Adopt = 'adopt',
|
||||||
@@ -40,7 +41,8 @@ enum JavaDistribution {
|
|||||||
GraalVM = 'graalvm',
|
GraalVM = 'graalvm',
|
||||||
GraalVMCommunity = 'graalvm-community',
|
GraalVMCommunity = 'graalvm-community',
|
||||||
JetBrains = 'jetbrains',
|
JetBrains = 'jetbrains',
|
||||||
Kona = 'kona'
|
Kona = 'kona',
|
||||||
|
OpenJdk = 'openjdk'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getJavaDistribution(
|
export function getJavaDistribution(
|
||||||
@@ -93,6 +95,8 @@ export function getJavaDistribution(
|
|||||||
return new JetBrainsDistribution(installerOptions);
|
return new JetBrainsDistribution(installerOptions);
|
||||||
case JavaDistribution.Kona:
|
case JavaDistribution.Kona:
|
||||||
return new KonaDistribution(installerOptions);
|
return new KonaDistribution(installerOptions);
|
||||||
|
case JavaDistribution.OpenJdk:
|
||||||
|
return new OpenJdkDistribution(installerOptions);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,11 +110,6 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setJavaDefault(version: string, toolPath: string): void {
|
|
||||||
super.setJavaDefault(version, toolPath);
|
|
||||||
core.exportVariable('GRAALVM_HOME', toolPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async findPackageForDownload(
|
protected async findPackageForDownload(
|
||||||
range: string
|
range: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export class LocalDistribution extends JavaBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let foundJava = this.forceDownload ? null : this.findInToolcache();
|
let foundJava = this.findInToolcache();
|
||||||
|
|
||||||
if (foundJava) {
|
if (foundJava) {
|
||||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import * as tc from '@actions/tool-cache';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
|
import {JavaBase} from '../base-installer.js';
|
||||||
|
import {
|
||||||
|
JavaDownloadRelease,
|
||||||
|
JavaInstallerOptions,
|
||||||
|
JavaInstallerResults
|
||||||
|
} from '../base-models.js';
|
||||||
|
import {
|
||||||
|
convertVersionToSemver,
|
||||||
|
extractJdkFile,
|
||||||
|
isVersionSatisfies,
|
||||||
|
renameWinArchive
|
||||||
|
} from '../../util.js';
|
||||||
|
|
||||||
|
const OPENJDK_BASE_URL = 'https://jdk.java.net';
|
||||||
|
|
||||||
|
export class OpenJdkDistribution extends JavaBase {
|
||||||
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
|
super('OpenJDK', installerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async findPackageForDownload(
|
||||||
|
range: string
|
||||||
|
): Promise<JavaDownloadRelease> {
|
||||||
|
if (this.packageType !== 'jdk') {
|
||||||
|
throw new Error('OpenJDK provides only the `jdk` package type');
|
||||||
|
}
|
||||||
|
|
||||||
|
const arch = this.distributionArchitecture();
|
||||||
|
if (!['x64', 'aarch64'].includes(arch)) {
|
||||||
|
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const platform = this.getPlatform();
|
||||||
|
const releases = await this.getAvailableVersions(platform, arch);
|
||||||
|
const matchingReleases = releases
|
||||||
|
.filter(release => isVersionSatisfies(range, release.version))
|
||||||
|
.sort((left, right) => -semver.compareBuild(left.version, right.version));
|
||||||
|
|
||||||
|
if (!matchingReleases.length) {
|
||||||
|
throw this.createVersionNotFoundError(
|
||||||
|
range,
|
||||||
|
releases.map(release => release.version),
|
||||||
|
`Platform: ${platform}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchingReleases[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async downloadTool(
|
||||||
|
javaRelease: JavaDownloadRelease
|
||||||
|
): Promise<JavaInstallerResults> {
|
||||||
|
core.info(
|
||||||
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
|
);
|
||||||
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
|
core.info(`Extracting Java archive...`);
|
||||||
|
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||||
|
if (extension === 'zip') {
|
||||||
|
javaArchivePath = renameWinArchive(javaArchivePath);
|
||||||
|
}
|
||||||
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
|
|
||||||
|
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||||
|
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||||
|
const javaPath = await tc.cacheDir(
|
||||||
|
archivePath,
|
||||||
|
this.toolcacheFolderName,
|
||||||
|
this.getToolcacheVersionName(javaRelease.version),
|
||||||
|
this.architecture
|
||||||
|
);
|
||||||
|
|
||||||
|
return {version: javaRelease.version, path: javaPath};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getAvailableVersions(
|
||||||
|
platform: string,
|
||||||
|
arch: string
|
||||||
|
): Promise<JavaDownloadRelease[]> {
|
||||||
|
const homePage = await this.fetchPage(`${OPENJDK_BASE_URL}/`);
|
||||||
|
const releasePageUrls = Array.from(
|
||||||
|
homePage.matchAll(/href="\/(\d+)\/">JDK\s+\d+/g),
|
||||||
|
match => `${OPENJDK_BASE_URL}/${match[1]}/`
|
||||||
|
);
|
||||||
|
|
||||||
|
const pages = await Promise.all(
|
||||||
|
releasePageUrls.map(url => this.fetchPage(url))
|
||||||
|
);
|
||||||
|
if (this.stable) {
|
||||||
|
pages.push(await this.fetchPage(`${OPENJDK_BASE_URL}/archive/`));
|
||||||
|
}
|
||||||
|
|
||||||
|
const releases = pages.flatMap(page =>
|
||||||
|
this.parseReleases(page, platform, arch)
|
||||||
|
);
|
||||||
|
|
||||||
|
return releases.filter(
|
||||||
|
release => release.url.includes('/early_access/') !== this.stable
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchPage(url: string): Promise<string> {
|
||||||
|
const response = await this.http.get(url);
|
||||||
|
return response.readBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseReleases(
|
||||||
|
html: string,
|
||||||
|
platform: string,
|
||||||
|
arch: string
|
||||||
|
): JavaDownloadRelease[] {
|
||||||
|
const platformPattern = platform === 'macos' ? '(?:macos|osx)' : platform;
|
||||||
|
const extensionPattern =
|
||||||
|
platform === 'windows' ? '(?:zip|tar\\.gz)' : 'tar\\.gz';
|
||||||
|
const pattern = new RegExp(
|
||||||
|
`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platformPattern}-${arch}_bin\\.${extensionPattern})"`,
|
||||||
|
'g'
|
||||||
|
);
|
||||||
|
|
||||||
|
return Array.from(html.matchAll(pattern), match => {
|
||||||
|
const url = match[1];
|
||||||
|
const build =
|
||||||
|
url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1] ??
|
||||||
|
this.findBuildInArchiveHeading(html, match.index, match[2]);
|
||||||
|
return {
|
||||||
|
version: this.toSemver(match[2], build),
|
||||||
|
url
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private findBuildInArchiveHeading(
|
||||||
|
html: string,
|
||||||
|
assetIndex: number,
|
||||||
|
version: string
|
||||||
|
): string | undefined {
|
||||||
|
const headings = Array.from(
|
||||||
|
html.slice(0, assetIndex).matchAll(/\(build\s+([^)]+)\)/g)
|
||||||
|
);
|
||||||
|
const headingVersion = headings.at(-1)?.[1];
|
||||||
|
if (!headingVersion) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [javaVersion, build] = headingVersion.split('+');
|
||||||
|
return javaVersion === version ? build : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private toSemver(version: string, urlBuild?: string): string {
|
||||||
|
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||||
|
const versionParts = javaVersion.split('.');
|
||||||
|
const normalizedVersion = convertVersionToSemver(
|
||||||
|
versionParts.length === 1 ? `${javaVersion}.0.0` : javaVersion
|
||||||
|
);
|
||||||
|
const build =
|
||||||
|
filenameBuild ?? (versionParts.length <= 3 ? urlBuild : undefined);
|
||||||
|
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPlatform(platform: NodeJS.Platform = process.platform): string {
|
||||||
|
switch (platform) {
|
||||||
|
case 'darwin':
|
||||||
|
return 'macos';
|
||||||
|
case 'linux':
|
||||||
|
return 'linux';
|
||||||
|
case 'win32':
|
||||||
|
return 'windows';
|
||||||
|
default:
|
||||||
|
throw new Error(
|
||||||
|
`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,10 +29,6 @@ async function run() {
|
|||||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||||
);
|
);
|
||||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||||
const forceDownload = getBooleanInput(
|
|
||||||
constants.INPUT_FORCE_DOWNLOAD,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
|
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
|
||||||
const verifySignature = getBooleanInput(
|
const verifySignature = getBooleanInput(
|
||||||
constants.INPUT_VERIFY_SIGNATURE,
|
constants.INPUT_VERIFY_SIGNATURE,
|
||||||
@@ -87,7 +83,6 @@ async function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -107,7 +102,6 @@ async function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -165,7 +159,6 @@ async function installVersion(
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -176,7 +169,6 @@ async function installVersion(
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
forceDownload,
|
|
||||||
setDefault,
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
@@ -220,7 +212,6 @@ interface installerInputsOptions {
|
|||||||
architecture: string;
|
architecture: string;
|
||||||
packageType: string;
|
packageType: string;
|
||||||
checkLatest: boolean;
|
checkLatest: boolean;
|
||||||
forceDownload: boolean;
|
|
||||||
setDefault: boolean;
|
setDefault: boolean;
|
||||||
verifySignature: boolean;
|
verifySignature: boolean;
|
||||||
verifySignaturePublicKey: string | undefined;
|
verifySignaturePublicKey: string | undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user