add support for dragonwell

This commit is contained in:
lvfei.lv 2023-01-10 16:28:53 +08:00
parent 5ffc13f417
commit 57d158e10c
8 changed files with 1757 additions and 1 deletions

View File

@ -105,6 +105,7 @@ Currently, the following distributions are supported:
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
| `semeru` | IBM Semeru Runtime Open Edition | [Link](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [Link](https://openjdk.java.net/legal/gplv2+ce.html) |
| `oracle` | Oracle JDK | [Link](https://www.oracle.com/java/technologies/downloads/) | [Link](https://java.com/freeuselicense)
| `dragonwell` | Alibaba Dragonwell JDK | [Link](https://dragonwell-jdk.io/) | [Link](https://www.aliyun.com/product/dragonwell/)
**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.
@ -227,6 +228,7 @@ In the example above multiple JDKs are installed for the same job. The result af
- [Microsoft](docs/advanced-usage.md#Microsoft)
- [Amazon Corretto](docs/advanced-usage.md#Amazon-Corretto)
- [Oracle](docs/advanced-usage.md#Oracle)
- [Alibaba Dragonwell](docs/advanced-usage.md#Alibaba-Dragonwell)
- [Installing custom Java package type](docs/advanced-usage.md#Installing-custom-Java-package-type)
- [Installing custom Java architecture](docs/advanced-usage.md#Installing-custom-Java-architecture)
- [Installing custom Java distribution from local file](docs/advanced-usage.md#Installing-Java-from-local-file)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,227 @@
import {HttpClient} from '@actions/http-client';
import * as semver from 'semver';
import {DragonwellDistribution} from '../../src/distributions/dragonwell/installer';
import {IDragonwellAllVersions} from '../../src/distributions/dragonwell/models';
import * as utils from '../../src/util';
import os from 'os';
import manifestData from '../data/dragonwell.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: manifestData
});
spyUtilGetDownloadArchiveExtension = jest.spyOn(
utils,
'getDownloadArchiveExtension'
);
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});
const mockPlatform = (
distribution: DragonwellDistribution,
platform: string
) => {
distribution['getPlatformOption'] = () => platform;
const mockedExtension = platform == 'windows' ? 'zip' : 'tar.gz';
spyUtilGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
};
describe('getAvailableVersions', () => {
it.each([
['8', 'x86', 'linux', 0],
['8', 'aarch64', 'linux', 33],
['8.6.6', 'x64', 'linux', 36],
['8', 'x86', 'anolis', 0],
['8', 'x86', 'windows', 0],
['8', 'x86', 'mac', 0],
['11', 'x64', 'linux', 36],
['11', 'aarch64', 'linux', 33],
['17', 'riscv', 'linux', 0]
])(
'load available versions',
async (
jdkVersion: string,
arch: string,
platform: string,
len: number
) => {
const distribution = new DragonwellDistribution({
version: jdkVersion,
architecture: arch,
packageType: 'jdk',
checkLatest: false
});
mockPlatform(distribution, platform);
const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).not.toBeNull();
expect(availableVersions.length).toBe(len);
}
);
it.each(['16', '16.0.1', '19'])(
'load unsupported versions',
async (jdkVersion: string) => {
const distribution = new DragonwellDistribution({
version: jdkVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
mockPlatform(distribution, 'linux');
await expect(distribution['getAvailableVersions']()).rejects.toThrow(
'Support dragonwell versions: 8, 11, 17'
);
}
);
});
describe('findPackageForDownload', () => {
it.each([
[
'8',
'linux',
'x64',
'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_linux.tar.gz'
],
[
'8',
'linux',
'aarch64',
'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_aarch64_linux.tar.gz'
],
[
'8',
'windows',
'x64',
'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_windows.zip'
],
[
'8.13.14',
'linux',
'x64',
'https://github.com/alibaba/dragonwell8/releases/download/dragonwell-extended-8.13.14_jdk8u352-ga/Alibaba_Dragonwell_Extended_8.13.14_x64_linux.tar.gz'
],
[
'11',
'linux',
'x64',
'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_linux.tar.gz'
],
[
'11',
'linux',
'aarch64',
'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_aarch64_linux.tar.gz'
],
[
'11',
'windows',
'x64',
'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_windows.zip'
],
[
'11',
'alpine-linux',
'x64',
'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_alpine-linux.tar.gz'
],
[
'11.0.17',
'linux',
'x64',
'https://github.com/alibaba/dragonwell11/releases/download/dragonwell-extended-11.0.17.13_jdk-11.0.17-ga/Alibaba_Dragonwell_Extended_11.0.17.13.8_x64_linux.tar.gz'
],
[
'17',
'linux',
'x64',
'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_linux.tar.gz'
],
[
'17',
'linux',
'aarch64',
'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_aarch64_linux.tar.gz'
],
[
'17',
'windows',
'x64',
'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_windows.zip'
],
[
'17',
'alpine-linux',
'x64',
'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.5.0.5%2B8_jdk-17.0.5-ga/Alibaba_Dragonwell_Standard_17.0.5.0.5.8_x64_alpine-linux.tar.gz'
],
[
'17.0.4',
'linux',
'x64',
'https://github.com/alibaba/dragonwell17/releases/download/dragonwell-standard-17.0.4.0.4%2B8_jdk-17.0.4-ga/Alibaba_Dragonwell_Standard_17.0.4.0.4%2B8_x64_linux.tar.gz'
]
])(
'test for download link',
async (
jdkVersion: string,
platform: string,
arch: string,
expectedLink: string
) => {
const distribution = new DragonwellDistribution({
version: jdkVersion,
architecture: arch,
packageType: 'jdk',
checkLatest: false
});
mockPlatform(distribution, platform);
const availableVersion = await distribution['findPackageForDownload'](
jdkVersion
);
expect(availableVersion).not.toBeNull();
expect(availableVersion.url).toBe(expectedLink);
}
);
it.each([
['8', 'alpine-linux', 'x64'],
['8', 'macos', 'aarch64'],
['11', 'macos', 'aarch64'],
['17', 'linux', 'riscv']
])(
'test for unsupported version',
async (jdkVersion: string, platform: string, arch: string) => {
const distribution = new DragonwellDistribution({
version: jdkVersion,
architecture: arch,
packageType: 'jdk',
checkLatest: false
});
mockPlatform(distribution, platform);
await expect(
distribution['findPackageForDownload'](jdkVersion)
).rejects.toThrow(`Cannot find satisfied version for ${jdkVersion}.`);
}
);
});
});

173
dist/setup/index.js vendored
View File

@ -104319,6 +104319,7 @@ const installer_6 = __nccwpck_require__(3613);
const installer_7 = __nccwpck_require__(1121);
const installer_8 = __nccwpck_require__(4750);
const installer_9 = __nccwpck_require__(4298);
const installer_10 = __nccwpck_require__(6132);
var JavaDistribution;
(function (JavaDistribution) {
JavaDistribution["Adopt"] = "adopt";
@ -104332,6 +104333,7 @@ var JavaDistribution;
JavaDistribution["Semeru"] = "semeru";
JavaDistribution["Corretto"] = "corretto";
JavaDistribution["Oracle"] = "oracle";
JavaDistribution["Dragonwell"] = "dragonwell";
})(JavaDistribution || (JavaDistribution = {}));
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
switch (distributionName) {
@ -104356,6 +104358,8 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
return new installer_8.CorrettoDistribution(installerOptions);
case JavaDistribution.Oracle:
return new installer_9.OracleDistribution(installerOptions);
case JavaDistribution.Dragonwell:
return new installer_10.DragonwellDistribution(installerOptions);
default:
return null;
}
@ -104363,6 +104367,175 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
exports.getJavaDistribution = getJavaDistribution;
/***/ }),
/***/ 6132:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DragonwellDistribution = void 0;
const core = __importStar(__nccwpck_require__(2186));
const tc = __importStar(__nccwpck_require__(7784));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
const base_installer_1 = __nccwpck_require__(9741);
const util_1 = __nccwpck_require__(2629);
class DragonwellDistribution extends base_installer_1.JavaBase {
constructor(installerOptions) {
super('Dragonwell', installerOptions);
}
findPackageForDownload(version) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.stable) {
throw new Error('Early access versions are not supported');
}
let majorVersion = version;
if (version.includes('.')) {
const splits = version.split('.');
majorVersion = splits[0];
version = splits.length >= 3 ? splits.slice(0, 3).join('.') : version;
}
const edition = majorVersion == '17' ? 'Standard' : 'Extended';
const availableVersions = yield this.getAvailableVersions();
const matchedVersions = availableVersions
.filter(item => item.jdk_version == version && item.edition == edition)
.map(item => {
return {
version: item.jdk_version,
url: item.download_link
};
});
const resolvedVersion = matchedVersions.length > 0 ? matchedVersions[0] : null;
if (!resolvedVersion) {
const versionsMsg = core.isDebug()
? `Available versions: ${availableVersions}`
: '';
throw new Error(`Cannot find satisfied version for ${version}.${versionsMsg}`);
}
return resolvedVersion;
});
}
getAvailableVersions() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const platform = this.getPlatformOption();
let arch = this.distributionArchitecture();
const majorVersion = this.version.includes('.')
? this.version.split('.')[0]
: this.version;
if (['8', '11', '17'].includes(majorVersion) != true) {
throw new Error('Support dragonwell versions: 8, 11, 17');
}
const availableVersionsUrl = 'https://dragonwell-jdk.io/map_with_checksum.json';
const fetchedDragonwellVersions = (_a = (yield this.http.getJson(availableVersionsUrl))
.result) !== null && _a !== void 0 ? _a : {};
if (Object.keys(fetchedDragonwellVersions).length == 0) {
throw Error(`Could fetch any dragonwell versions from ${availableVersionsUrl}`);
}
const availableVersions = this.getEligibleAvailableVersions(platform, arch, fetchedDragonwellVersions);
if (core.isDebug()) {
core.startGroup('Print information about available versions');
core.debug(availableVersions.map(item => item.jdk_version).join(', '));
core.endGroup();
}
return availableVersions;
});
}
downloadTool(javaRelease) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
const javaArchivePath = yield tc.downloadTool(javaRelease.url);
core.info(`Extracting Java archive...`);
const extractedJavaPath = yield util_1.extractJdkFile(javaArchivePath, util_1.getDownloadArchiveExtension());
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
const version = this.getToolcacheVersionName(javaRelease.version);
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
return { version: javaRelease.version, path: javaPath };
});
}
getEligibleAvailableVersions(platform, arch, dragonwellVersions) {
const eligibleVersions = [];
for (const majorVersion in dragonwellVersions) {
const majorVersionMap = dragonwellVersions[majorVersion];
for (let jdkVersion in majorVersionMap) {
const jdkVersionMap = majorVersionMap[jdkVersion];
if (!(platform in jdkVersionMap)) {
continue;
}
const platformMap = jdkVersionMap[platform];
if (!(arch in platformMap)) {
continue;
}
const archMap = platformMap[arch];
if (jdkVersion === 'latest') {
jdkVersion = majorVersion;
}
if (jdkVersion.includes('.')) {
const splits = jdkVersion.split('.');
jdkVersion =
splits.length >= 3 ? splits.slice(0, 3).join('.') : jdkVersion;
}
for (const edition in archMap) {
eligibleVersions.push({
os: platform,
architecture: arch,
jdk_version: jdkVersion,
checksum: archMap[edition].sha256,
download_link: archMap[edition].download_url,
edition: edition,
image_type: 'jdk'
});
}
}
}
return eligibleVersions;
}
getPlatformOption() {
switch (process.platform) {
case 'win32':
return 'windows';
default:
return process.platform;
}
}
}
exports.DragonwellDistribution = DragonwellDistribution;
/***/ }),
/***/ 883:

View File

@ -7,6 +7,7 @@
- [Microsoft](#Microsoft)
- [Amazon Corretto](#Amazon-Corretto)
- [Oracle](#Oracle)
- [Alibaba Dragonwell](#Alibaba-Dragonwell)
- [Installing custom Java package type](#Installing-custom-Java-package-type)
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
@ -124,6 +125,18 @@ steps:
- run: java -cp java HelloWorldApp
```
### Alibaba Dragonwell
**NOTE:** Alibaba Dragonwell only provides jdk.
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'dragonwell'
java-version: '8'
- run: java -cp java HelloWorldApp
```
## Installing custom Java package type
```yaml
steps:

View File

@ -9,6 +9,7 @@ import {MicrosoftDistributions} from './microsoft/installer';
import {SemeruDistribution} from './semeru/installer';
import {CorrettoDistribution} from './corretto/installer';
import {OracleDistribution} from './oracle/installer';
import {DragonwellDistribution} from './dragonwell/installer';
enum JavaDistribution {
Adopt = 'adopt',
@ -21,7 +22,8 @@ enum JavaDistribution {
Microsoft = 'microsoft',
Semeru = 'semeru',
Corretto = 'corretto',
Oracle = 'oracle'
Oracle = 'oracle',
Dragonwell = 'dragonwell'
}
export function getJavaDistribution(
@ -60,6 +62,8 @@ export function getJavaDistribution(
return new CorrettoDistribution(installerOptions);
case JavaDistribution.Oracle:
return new OracleDistribution(installerOptions);
case JavaDistribution.Dragonwell:
return new DragonwellDistribution(installerOptions);
default:
return null;
}

View File

@ -0,0 +1,173 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import fs from 'fs';
import path from 'path';
import {JavaBase} from '../base-installer';
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
import {IDragonwellVersions, IDragonwellAllVersions} from './models';
import {
JavaDownloadRelease,
JavaInstallerOptions,
JavaInstallerResults
} from '../base-models';
export class DragonwellDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
super('Dragonwell', installerOptions);
}
protected async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
if (!this.stable) {
throw new Error('Early access versions are not supported');
}
let majorVersion = version;
if (version.includes('.')) {
const splits = version.split('.');
majorVersion = splits[0];
version = splits.length >= 3 ? splits.slice(0, 3).join('.') : version;
}
const edition = majorVersion == '17' ? 'Standard' : 'Extended';
const availableVersions = await this.getAvailableVersions();
const matchedVersions = availableVersions
.filter(item => item.jdk_version == version && item.edition == edition)
.map(item => {
return {
version: item.jdk_version,
url: item.download_link
} as JavaDownloadRelease;
});
const resolvedVersion =
matchedVersions.length > 0 ? matchedVersions[0] : null;
if (!resolvedVersion) {
const versionsMsg = core.isDebug()
? `Available versions: ${availableVersions}`
: '';
throw new Error(
`Cannot find satisfied version for ${version}.${versionsMsg}`
);
}
return resolvedVersion;
}
private async getAvailableVersions(): Promise<IDragonwellVersions[]> {
const platform = this.getPlatformOption();
let arch = this.distributionArchitecture();
const majorVersion = this.version.includes('.')
? this.version.split('.')[0]
: this.version;
if (['8', '11', '17'].includes(majorVersion) != true) {
throw new Error('Support dragonwell versions: 8, 11, 17');
}
const availableVersionsUrl =
'https://dragonwell-jdk.io/map_with_checksum.json';
const fetchedDragonwellVersions =
(await this.http.getJson<IDragonwellAllVersions>(availableVersionsUrl))
.result ?? {};
if (Object.keys(fetchedDragonwellVersions).length == 0) {
throw Error(
`Could fetch any dragonwell versions from ${availableVersionsUrl}`
);
}
const availableVersions = this.getEligibleAvailableVersions(
platform,
arch,
fetchedDragonwellVersions
);
if (core.isDebug()) {
core.startGroup('Print information about available versions');
core.debug(availableVersions.map(item => item.jdk_version).join(', '));
core.endGroup();
}
return availableVersions;
}
protected async downloadTool(
javaRelease: JavaDownloadRelease
): Promise<JavaInstallerResults> {
core.info(
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
);
const javaArchivePath = await tc.downloadTool(javaRelease.url);
core.info(`Extracting Java archive...`);
const extractedJavaPath = await extractJdkFile(
javaArchivePath,
getDownloadArchiveExtension()
);
const archiveName = fs.readdirSync(extractedJavaPath)[0];
const archivePath = path.join(extractedJavaPath, archiveName);
const version = this.getToolcacheVersionName(javaRelease.version);
const javaPath = await tc.cacheDir(
archivePath,
this.toolcacheFolderName,
version,
this.architecture
);
return {version: javaRelease.version, path: javaPath};
}
private getEligibleAvailableVersions(
platform: string,
arch: string,
dragonwellVersions: IDragonwellAllVersions
): IDragonwellVersions[] {
const eligibleVersions: IDragonwellVersions[] = [];
for (const majorVersion in dragonwellVersions) {
const majorVersionMap = dragonwellVersions[majorVersion];
for (let jdkVersion in majorVersionMap) {
const jdkVersionMap = majorVersionMap[jdkVersion];
if (!(platform in jdkVersionMap)) {
continue;
}
const platformMap = jdkVersionMap[platform];
if (!(arch in platformMap)) {
continue;
}
const archMap = platformMap[arch];
if (jdkVersion === 'latest') {
jdkVersion = majorVersion;
}
if (jdkVersion.includes('.')) {
const splits = jdkVersion.split('.');
jdkVersion =
splits.length >= 3 ? splits.slice(0, 3).join('.') : jdkVersion;
}
for (const edition in archMap) {
eligibleVersions.push({
os: platform,
architecture: arch,
jdk_version: jdkVersion,
checksum: archMap[edition].sha256,
download_link: archMap[edition].download_url,
edition: edition,
image_type: 'jdk'
});
}
}
}
return eligibleVersions;
}
private getPlatformOption(): string {
switch (process.platform) {
case 'win32':
return 'windows';
default:
return process.platform;
}
}
}

View File

@ -0,0 +1,26 @@
export interface IDragonwellAllVersions {
[major: string]: {
[jdk_version: string]: {
[os: string]: {
[arch: string]: {
[edition: string]: {
content_type: string;
sha256: string;
name: string;
download_url: string;
};
};
};
};
};
}
export interface IDragonwellVersions {
os: string;
architecture: string;
jdk_version: string;
checksum: string;
download_link: string;
edition: string;
image_type: string;
}