mirror of
https://github.com/actions/setup-java.git
synced 2026-07-30 17:19:27 +08:00
Support Temurin JDKs with JMOD files (#1149)
* Initial plan * Add Temurin JMOD installation support * Rebuild action bundles * Use java-package for Temurin JMODs Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7d8c581-2d14-4ccc-aeca-afc0f3b0c2bc * Fix Temurin JMOD test paths on Windows Use platform-aware path construction for the JMOD copy and cache assertions so the Windows test expects backslash-normalized paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Bruno Borges <brborges@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e7d8c581-2d14-4ccc-aeca-afc0f3b0c2bc
This commit is contained in:
@@ -48,7 +48,7 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).
|
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).
|
||||||
|
|
||||||
- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. For Azul Zulu, `jdk+crac` and `jre+crac` are also supported. Default value: `jdk`.
|
- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. For Azul Zulu, `jdk+crac` and `jre+crac` are also supported. For Eclipse Temurin 24 and later, `jdk+jmods` includes the separately packaged JMOD files. Default value: `jdk`.
|
||||||
|
|
||||||
- `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: Derived from the runner machine.
|
- `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: Derived from the runner machine.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import {getJavaDistribution} from '../../src/distributions/distribution-factory.js';
|
||||||
|
|
||||||
|
describe('getJavaDistribution', () => {
|
||||||
|
it("rejects java-package 'jdk+jmods' for non-Temurin distributions", () => {
|
||||||
|
expect(() =>
|
||||||
|
getJavaDistribution('zulu', {
|
||||||
|
version: '25',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk+jmods',
|
||||||
|
checkLatest: false
|
||||||
|
})
|
||||||
|
).toThrow(
|
||||||
|
"java-package 'jdk+jmods' is only supported for distribution 'temurin'."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -13,6 +13,7 @@ import type {TemurinImplementation as TemurinImplementationType} from '../../src
|
|||||||
import {HttpClient} from '@actions/http-client';
|
import {HttpClient} from '@actions/http-client';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
import manifestData from '../data/temurin.json' with {type: 'json'};
|
import manifestData from '../data/temurin.json' with {type: 'json'};
|
||||||
|
|
||||||
@@ -119,6 +120,16 @@ describe('getAvailableVersions', () => {
|
|||||||
TemurinImplementation.Hotspot,
|
TemurinImplementation.Hotspot,
|
||||||
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
|
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
version: '25',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk+jmods',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
TemurinImplementation.Hotspot,
|
||||||
|
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
|
||||||
|
],
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
version: '16',
|
version: '16',
|
||||||
@@ -169,6 +180,27 @@ describe('getAvailableVersions', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('requests the JMOD image type', async () => {
|
||||||
|
const distribution = new TemurinDistribution(
|
||||||
|
{
|
||||||
|
version: '25',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk+jmods',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
TemurinImplementation.Hotspot
|
||||||
|
);
|
||||||
|
distribution['getPlatformOption'] = () => 'linux';
|
||||||
|
|
||||||
|
await distribution['getAvailableVersions']('jmods');
|
||||||
|
|
||||||
|
expect(spyHttpClient).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
'os=linux&architecture=x64&image_type=jmods&release_type=ga'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('load available versions', async () => {
|
it('load available versions', async () => {
|
||||||
const nextPageUrl =
|
const nextPageUrl =
|
||||||
'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?page=1&page_size=20';
|
'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?page=1&page_size=20';
|
||||||
@@ -229,7 +261,12 @@ describe('getAvailableVersions', () => {
|
|||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[TemurinImplementation.Hotspot, 'jdk', 'Java_Temurin-Hotspot_jdk'],
|
[TemurinImplementation.Hotspot, 'jdk', 'Java_Temurin-Hotspot_jdk'],
|
||||||
[TemurinImplementation.Hotspot, 'jre', 'Java_Temurin-Hotspot_jre']
|
[TemurinImplementation.Hotspot, 'jre', 'Java_Temurin-Hotspot_jre'],
|
||||||
|
[
|
||||||
|
TemurinImplementation.Hotspot,
|
||||||
|
'jdk+jmods',
|
||||||
|
'Java_Temurin-Hotspot_jdk+jmods'
|
||||||
|
]
|
||||||
])(
|
])(
|
||||||
'find right toolchain folder',
|
'find right toolchain folder',
|
||||||
(
|
(
|
||||||
@@ -386,6 +423,7 @@ describe('downloadTool', () => {
|
|||||||
let spyCacheDir: any;
|
let spyCacheDir: any;
|
||||||
let spyReadDirSync: any;
|
let spyReadDirSync: any;
|
||||||
let spyRenameWinArchive: any;
|
let spyRenameWinArchive: any;
|
||||||
|
let spyCopySync: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyDownloadTool = tc.downloadTool as jest.Mock;
|
spyDownloadTool = tc.downloadTool as jest.Mock;
|
||||||
@@ -400,6 +438,8 @@ describe('downloadTool', () => {
|
|||||||
spyReadDirSync.mockReturnValue(['jdk-17'] as any);
|
spyReadDirSync.mockReturnValue(['jdk-17'] as any);
|
||||||
spyRenameWinArchive = util.renameWinArchive as jest.Mock;
|
spyRenameWinArchive = util.renameWinArchive as jest.Mock;
|
||||||
spyRenameWinArchive.mockReturnValue('/tmp/jdk.tar.gz.zip');
|
spyRenameWinArchive.mockReturnValue('/tmp/jdk.tar.gz.zip');
|
||||||
|
spyCopySync = jest.spyOn(fs, 'cpSync');
|
||||||
|
spyCopySync.mockImplementation(() => undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -433,6 +473,60 @@ describe('downloadTool', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('downloads and adds matching JMODs to the JDK', async () => {
|
||||||
|
spyDownloadTool
|
||||||
|
.mockResolvedValueOnce('/tmp/jdk.tar.gz')
|
||||||
|
.mockResolvedValueOnce('/tmp/jmods.tar.gz');
|
||||||
|
spyExtractJdkFile
|
||||||
|
.mockResolvedValueOnce('/tmp/extracted')
|
||||||
|
.mockResolvedValueOnce('/tmp/extracted-jmods');
|
||||||
|
spyReadDirSync
|
||||||
|
.mockReturnValueOnce(['jdk-25'] as any)
|
||||||
|
.mockReturnValueOnce(['jdk-25-jmods'] as any);
|
||||||
|
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
|
||||||
|
|
||||||
|
const distribution = new TemurinDistribution(
|
||||||
|
{
|
||||||
|
version: '25',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk+jmods',
|
||||||
|
checkLatest: false
|
||||||
|
},
|
||||||
|
TemurinImplementation.Hotspot
|
||||||
|
);
|
||||||
|
distribution['resolvePackage'] = jest.fn().mockResolvedValue({
|
||||||
|
version: '25.0.3+9',
|
||||||
|
url: 'https://example.com/jmods.tar.gz'
|
||||||
|
});
|
||||||
|
|
||||||
|
await distribution['downloadTool']({
|
||||||
|
version: '25.0.3+9',
|
||||||
|
url: 'https://example.com/jdk.tar.gz'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(distribution['resolvePackage']).toHaveBeenCalledWith(
|
||||||
|
'25.0.3+9',
|
||||||
|
'jmods'
|
||||||
|
);
|
||||||
|
expect(spyDownloadTool).toHaveBeenNthCalledWith(
|
||||||
|
2,
|
||||||
|
'https://example.com/jmods.tar.gz'
|
||||||
|
);
|
||||||
|
expect(spyCopySync).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp/extracted-jmods', 'jdk-25-jmods'),
|
||||||
|
process.platform === 'darwin'
|
||||||
|
? path.join('/tmp/extracted', 'jdk-25', 'Contents', 'Home', 'jmods')
|
||||||
|
: path.join('/tmp/extracted', 'jdk-25', 'jmods'),
|
||||||
|
{recursive: true}
|
||||||
|
);
|
||||||
|
expect(spyCacheDir).toHaveBeenCalledWith(
|
||||||
|
path.join('/tmp/extracted', 'jdk-25'),
|
||||||
|
'Java_Temurin-Hotspot_jdk+jmods',
|
||||||
|
'25.0.3-9',
|
||||||
|
'x64'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('fails when signature is missing and verification is enabled', async () => {
|
it('fails when signature is missing and verification is enabled', async () => {
|
||||||
const distribution = new TemurinDistribution(
|
const distribution = new TemurinDistribution(
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ inputs:
|
|||||||
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
|
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
|
||||||
required: false
|
required: false
|
||||||
java-package:
|
java-package:
|
||||||
description: 'The package type (jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac)'
|
description: 'The package type (jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac, jdk+jmods)'
|
||||||
required: false
|
required: false
|
||||||
default: 'jdk'
|
default: 'jdk'
|
||||||
architecture:
|
architecture:
|
||||||
|
|||||||
Vendored
+46
-19
@@ -129873,21 +129873,27 @@ wI4qF/KKq9BfyfucAs0ykA==
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var TemurinImplementation;
|
var TemurinImplementation;
|
||||||
(function (TemurinImplementation) {
|
(function (TemurinImplementation) {
|
||||||
TemurinImplementation["Hotspot"] = "Hotspot";
|
TemurinImplementation["Hotspot"] = "Hotspot";
|
||||||
})(TemurinImplementation || (TemurinImplementation = {}));
|
})(TemurinImplementation || (TemurinImplementation = {}));
|
||||||
class TemurinDistribution extends JavaBase {
|
class TemurinDistribution extends JavaBase {
|
||||||
jvmImpl;
|
jvmImpl;
|
||||||
|
includeJmods;
|
||||||
constructor(installerOptions, jvmImpl) {
|
constructor(installerOptions, jvmImpl) {
|
||||||
super(`Temurin-${jvmImpl}`, installerOptions);
|
super(`Temurin-${jvmImpl}`, installerOptions);
|
||||||
this.jvmImpl = jvmImpl;
|
this.jvmImpl = jvmImpl;
|
||||||
|
this.includeJmods = this.packageType === 'jdk+jmods';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @internal For cross-distribution reuse only. Not intended as a public API.
|
* @internal For cross-distribution reuse only. Not intended as a public API.
|
||||||
*/
|
*/
|
||||||
async findPackageForDownload(version) {
|
async findPackageForDownload(version) {
|
||||||
const availableVersionsRaw = await this.getAvailableVersions();
|
return this.resolvePackage(version, this.includeJmods ? 'jdk' : this.packageType);
|
||||||
|
}
|
||||||
|
async resolvePackage(version, imageType) {
|
||||||
|
const availableVersionsRaw = await this.getAvailableVersions(imageType);
|
||||||
const availableVersionsWithBinaries = availableVersionsRaw
|
const availableVersionsWithBinaries = availableVersionsRaw
|
||||||
.filter(item => item.binaries.length > 0)
|
.filter(item => item.binaries.length > 0)
|
||||||
.map(item => {
|
.map(item => {
|
||||||
@@ -129915,19 +129921,7 @@ class TemurinDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
async downloadTool(javaRelease) {
|
async downloadTool(javaRelease) {
|
||||||
info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||||
let javaArchivePath = await downloadTool(javaRelease.url);
|
let javaArchivePath = await this.downloadPackage(javaRelease);
|
||||||
if (this.verifySignature) {
|
|
||||||
if (!javaRelease.signatureUrl) {
|
|
||||||
throw new Error(`Input 'verify-signature' is enabled, but no signature URL was found for Temurin version ${javaRelease.version}.`);
|
|
||||||
}
|
|
||||||
info(`Verifying Java package signature...`);
|
|
||||||
try {
|
|
||||||
await verifyPackageSignature(javaArchivePath, javaRelease.signatureUrl, this.verifySignaturePublicKey ?? ADOPTIUM_PUBLIC_KEY);
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
throw new Error(`Failed to verify signature for Temurin version ${javaRelease.version} from ${javaRelease.signatureUrl}: ${error.message}`, { cause: error });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info(`Extracting Java archive...`);
|
info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@@ -129936,20 +129930,49 @@ class TemurinDistribution extends JavaBase {
|
|||||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
const archiveName = external_fs_default().readdirSync(extractedJavaPath)[0];
|
const archiveName = external_fs_default().readdirSync(extractedJavaPath)[0];
|
||||||
const archivePath = external_path_default().join(extractedJavaPath, archiveName);
|
const archivePath = external_path_default().join(extractedJavaPath, archiveName);
|
||||||
|
const javaHome = process.platform === 'darwin'
|
||||||
|
? external_path_default().join(archivePath, MACOS_JAVA_CONTENT_POSTFIX)
|
||||||
|
: archivePath;
|
||||||
|
if (this.includeJmods && !external_fs_default().existsSync(external_path_default().join(javaHome, 'jmods'))) {
|
||||||
|
await this.installJmods(javaRelease.version, javaHome);
|
||||||
|
}
|
||||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||||
const javaPath = await cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
const javaPath = await cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||||
return { version: javaRelease.version, path: javaPath };
|
return { version: javaRelease.version, path: javaPath };
|
||||||
}
|
}
|
||||||
get toolcacheFolderName() {
|
|
||||||
return super.toolcacheFolderName;
|
|
||||||
}
|
|
||||||
supportsSignatureVerification() {
|
supportsSignatureVerification() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
async getAvailableVersions() {
|
async downloadPackage(release) {
|
||||||
|
const archivePath = await downloadTool(release.url);
|
||||||
|
if (this.verifySignature) {
|
||||||
|
if (!release.signatureUrl) {
|
||||||
|
throw new Error(`Input 'verify-signature' is enabled, but no signature URL was found for Temurin version ${release.version}.`);
|
||||||
|
}
|
||||||
|
info(`Verifying Java package signature...`);
|
||||||
|
try {
|
||||||
|
await verifyPackageSignature(archivePath, release.signatureUrl, this.verifySignaturePublicKey ?? ADOPTIUM_PUBLIC_KEY);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
throw new Error(`Failed to verify signature for Temurin version ${release.version} from ${release.signatureUrl}: ${error.message}`, { cause: error });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return archivePath;
|
||||||
|
}
|
||||||
|
async installJmods(version, javaHome) {
|
||||||
|
const jmodsRelease = await this.resolvePackage(version, 'jmods');
|
||||||
|
info(`Downloading JMODs ${jmodsRelease.version} (${this.distribution}) from ${jmodsRelease.url} ...`);
|
||||||
|
let jmodsArchivePath = await this.downloadPackage(jmodsRelease);
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
jmodsArchivePath = renameWinArchive(jmodsArchivePath);
|
||||||
|
}
|
||||||
|
const extractedJmodsPath = await extractJdkFile(jmodsArchivePath, getDownloadArchiveExtension());
|
||||||
|
const jmodsDirectory = external_path_default().join(extractedJmodsPath, external_fs_default().readdirSync(extractedJmodsPath)[0]);
|
||||||
|
external_fs_default().cpSync(jmodsDirectory, external_path_default().join(javaHome, 'jmods'), { recursive: true });
|
||||||
|
}
|
||||||
|
async getAvailableVersions(imageType = this.includeJmods ? 'jdk' : this.packageType) {
|
||||||
const platform = this.getPlatformOption();
|
const platform = this.getPlatformOption();
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
const imageType = this.packageType;
|
|
||||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||||
const releaseType = this.stable ? 'ga' : 'ea';
|
const releaseType = this.stable ? 'ga' : 'ea';
|
||||||
if (isDebug()) {
|
if (isDebug()) {
|
||||||
@@ -132025,6 +132048,10 @@ var JavaDistribution;
|
|||||||
JavaDistribution["OracleOpenJdk"] = "oracle-openjdk";
|
JavaDistribution["OracleOpenJdk"] = "oracle-openjdk";
|
||||||
})(JavaDistribution || (JavaDistribution = {}));
|
})(JavaDistribution || (JavaDistribution = {}));
|
||||||
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
||||||
|
if (installerOptions.packageType === 'jdk+jmods' &&
|
||||||
|
distributionName !== JavaDistribution.Temurin) {
|
||||||
|
throw new Error("java-package 'jdk+jmods' is only supported for distribution 'temurin'.");
|
||||||
|
}
|
||||||
switch (distributionName) {
|
switch (distributionName) {
|
||||||
case JavaDistribution.JdkFile:
|
case JavaDistribution.JdkFile:
|
||||||
return new LocalDistribution(installerOptions, jdkFile);
|
return new LocalDistribution(installerOptions, jdkFile);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ steps:
|
|||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '25'
|
java-version: '25'
|
||||||
|
java-package: 'jdk+jmods' # optional, includes JMOD files with JDK 24 and later
|
||||||
- run: java --version
|
- run: java --version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ export function getJavaDistribution(
|
|||||||
installerOptions: JavaInstallerOptions,
|
installerOptions: JavaInstallerOptions,
|
||||||
jdkFile?: string
|
jdkFile?: string
|
||||||
): JavaBase | null {
|
): JavaBase | null {
|
||||||
|
if (
|
||||||
|
installerOptions.packageType === 'jdk+jmods' &&
|
||||||
|
distributionName !== JavaDistribution.Temurin
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"java-package 'jdk+jmods' is only supported for distribution 'temurin'."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
switch (distributionName) {
|
switch (distributionName) {
|
||||||
case JavaDistribution.JdkFile:
|
case JavaDistribution.JdkFile:
|
||||||
return new LocalDistribution(installerOptions, jdkFile);
|
return new LocalDistribution(installerOptions, jdkFile);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as gpg from '../../gpg.js';
|
|||||||
import {ADOPTIUM_PUBLIC_KEY} from './adoptium-key.js';
|
import {ADOPTIUM_PUBLIC_KEY} from './adoptium-key.js';
|
||||||
import {JavaBase} from '../base-installer.js';
|
import {JavaBase} from '../base-installer.js';
|
||||||
import {ITemurinAvailableVersions} from './models.js';
|
import {ITemurinAvailableVersions} from './models.js';
|
||||||
|
import {MACOS_JAVA_CONTENT_POSTFIX} from '../../constants.js';
|
||||||
import {
|
import {
|
||||||
JavaDownloadRelease,
|
JavaDownloadRelease,
|
||||||
JavaInstallerOptions,
|
JavaInstallerOptions,
|
||||||
@@ -31,11 +32,14 @@ export enum TemurinImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TemurinDistribution extends JavaBase {
|
export class TemurinDistribution extends JavaBase {
|
||||||
|
private readonly includeJmods: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
installerOptions: JavaInstallerOptions,
|
installerOptions: JavaInstallerOptions,
|
||||||
private readonly jvmImpl: TemurinImplementation
|
private readonly jvmImpl: TemurinImplementation
|
||||||
) {
|
) {
|
||||||
super(`Temurin-${jvmImpl}`, installerOptions);
|
super(`Temurin-${jvmImpl}`, installerOptions);
|
||||||
|
this.includeJmods = this.packageType === 'jdk+jmods';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +48,17 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
public async findPackageForDownload(
|
public async findPackageForDownload(
|
||||||
version: string
|
version: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
const availableVersionsRaw = await this.getAvailableVersions();
|
return this.resolvePackage(
|
||||||
|
version,
|
||||||
|
this.includeJmods ? 'jdk' : this.packageType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async resolvePackage(
|
||||||
|
version: string,
|
||||||
|
imageType: string
|
||||||
|
): Promise<JavaDownloadRelease> {
|
||||||
|
const availableVersionsRaw = await this.getAvailableVersions(imageType);
|
||||||
const availableVersionsWithBinaries = availableVersionsRaw
|
const availableVersionsWithBinaries = availableVersionsRaw
|
||||||
.filter(item => item.binaries.length > 0)
|
.filter(item => item.binaries.length > 0)
|
||||||
.map(item => {
|
.map(item => {
|
||||||
@@ -83,30 +97,7 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
core.info(
|
core.info(
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
);
|
);
|
||||||
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
let javaArchivePath = await this.downloadPackage(javaRelease);
|
||||||
|
|
||||||
if (this.verifySignature) {
|
|
||||||
if (!javaRelease.signatureUrl) {
|
|
||||||
throw new Error(
|
|
||||||
`Input 'verify-signature' is enabled, but no signature URL was found for Temurin version ${javaRelease.version}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
core.info(`Verifying Java package signature...`);
|
|
||||||
try {
|
|
||||||
await gpg.verifyPackageSignature(
|
|
||||||
javaArchivePath,
|
|
||||||
javaRelease.signatureUrl,
|
|
||||||
this.verifySignaturePublicKey ?? ADOPTIUM_PUBLIC_KEY
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(
|
|
||||||
`Failed to verify signature for Temurin version ${javaRelease.version} from ${javaRelease.signatureUrl}: ${
|
|
||||||
(error as Error).message
|
|
||||||
}`,
|
|
||||||
{cause: error}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = getDownloadArchiveExtension();
|
||||||
@@ -117,6 +108,13 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
|
|
||||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||||
|
const javaHome =
|
||||||
|
process.platform === 'darwin'
|
||||||
|
? path.join(archivePath, MACOS_JAVA_CONTENT_POSTFIX)
|
||||||
|
: archivePath;
|
||||||
|
if (this.includeJmods && !fs.existsSync(path.join(javaHome, 'jmods'))) {
|
||||||
|
await this.installJmods(javaRelease.version, javaHome);
|
||||||
|
}
|
||||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||||
|
|
||||||
const javaPath = await tc.cacheDir(
|
const javaPath = await tc.cacheDir(
|
||||||
@@ -129,18 +127,64 @@ export class TemurinDistribution extends JavaBase {
|
|||||||
return {version: javaRelease.version, path: javaPath};
|
return {version: javaRelease.version, path: javaPath};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get toolcacheFolderName(): string {
|
|
||||||
return super.toolcacheFolderName;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected supportsSignatureVerification(): boolean {
|
protected supportsSignatureVerification(): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getAvailableVersions(): Promise<ITemurinAvailableVersions[]> {
|
private async downloadPackage(release: JavaDownloadRelease): Promise<string> {
|
||||||
|
const archivePath = await tc.downloadTool(release.url);
|
||||||
|
|
||||||
|
if (this.verifySignature) {
|
||||||
|
if (!release.signatureUrl) {
|
||||||
|
throw new Error(
|
||||||
|
`Input 'verify-signature' is enabled, but no signature URL was found for Temurin version ${release.version}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
core.info(`Verifying Java package signature...`);
|
||||||
|
try {
|
||||||
|
await gpg.verifyPackageSignature(
|
||||||
|
archivePath,
|
||||||
|
release.signatureUrl,
|
||||||
|
this.verifySignaturePublicKey ?? ADOPTIUM_PUBLIC_KEY
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to verify signature for Temurin version ${release.version} from ${release.signatureUrl}: ${
|
||||||
|
(error as Error).message
|
||||||
|
}`,
|
||||||
|
{cause: error}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return archivePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async installJmods(version: string, javaHome: string): Promise<void> {
|
||||||
|
const jmodsRelease = await this.resolvePackage(version, 'jmods');
|
||||||
|
core.info(
|
||||||
|
`Downloading JMODs ${jmodsRelease.version} (${this.distribution}) from ${jmodsRelease.url} ...`
|
||||||
|
);
|
||||||
|
let jmodsArchivePath = await this.downloadPackage(jmodsRelease);
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
jmodsArchivePath = renameWinArchive(jmodsArchivePath);
|
||||||
|
}
|
||||||
|
const extractedJmodsPath = await extractJdkFile(
|
||||||
|
jmodsArchivePath,
|
||||||
|
getDownloadArchiveExtension()
|
||||||
|
);
|
||||||
|
const jmodsDirectory = path.join(
|
||||||
|
extractedJmodsPath,
|
||||||
|
fs.readdirSync(extractedJmodsPath)[0]
|
||||||
|
);
|
||||||
|
fs.cpSync(jmodsDirectory, path.join(javaHome, 'jmods'), {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getAvailableVersions(
|
||||||
|
imageType = this.includeJmods ? 'jdk' : this.packageType
|
||||||
|
): Promise<ITemurinAvailableVersions[]> {
|
||||||
const platform = this.getPlatformOption();
|
const platform = this.getPlatformOption();
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
const imageType = this.packageType;
|
|
||||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||||
const releaseType = this.stable ? 'ga' : 'ea';
|
const releaseType = this.stable ? 'ga' : 'ea';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user