mirror of
https://github.com/actions/setup-java.git
synced 2025-03-13 09:37:03 +00:00
eliminate duplication in version numbers
This commit is contained in:
parent
bf48000b8b
commit
ef8955b635
3 changed files with 28 additions and 44 deletions
34
dist/setup/index.js
vendored
34
dist/setup/index.js
vendored
|
@ -13864,7 +13864,6 @@ const core = __importStar(__webpack_require__(470));
|
|||
const tc = __importStar(__webpack_require__(139));
|
||||
const fs_1 = __importDefault(__webpack_require__(747));
|
||||
const path_1 = __importDefault(__webpack_require__(622));
|
||||
const supportedPlatform = `'linux', 'macos', 'windows'`;
|
||||
class MicrosoftDistributions extends base_installer_1.JavaBase {
|
||||
constructor(installerOptions) {
|
||||
super('Microsoft', installerOptions);
|
||||
|
@ -13884,13 +13883,13 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
|
|||
}
|
||||
findPackageForDownload(range) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (this.architecture !== 'x64' && this.architecture != 'aarch64') {
|
||||
if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
const availableVersionsRaw = yield this.getAvailableVersions();
|
||||
const opts = this.getPlatformOption();
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion.join('.')}-${opts.os}-${this.architecture}.${opts.archive}`,
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${this.architecture}.${opts.archive}`,
|
||||
version: this.convertVersionToSemver(item)
|
||||
}));
|
||||
const satisfiedVersion = availableVersions
|
||||
|
@ -13909,34 +13908,26 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
|
|||
getAvailableVersions() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// TODO get these dynamically!
|
||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||
const jdkVersions = [
|
||||
{
|
||||
majorVersion: 17,
|
||||
minorVersion: 0,
|
||||
patchVersion: 1,
|
||||
fullVersion: [17, 0, 1, 12, 1],
|
||||
version: [17, 0, 1, 12, 1]
|
||||
},
|
||||
{
|
||||
majorVersion: 16,
|
||||
minorVersion: 0,
|
||||
patchVersion: 2,
|
||||
fullVersion: [16, 0, 2.7, 1],
|
||||
},
|
||||
version: [16, 0, 2, 7, 1]
|
||||
}
|
||||
];
|
||||
// M1 is only supported for Java 16 & 17
|
||||
if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
|
||||
jdkVersions.push({
|
||||
majorVersion: 11,
|
||||
minorVersion: 0,
|
||||
patchVersion: 13,
|
||||
fullVersion: [11, 0, 13, 8, 1],
|
||||
version: [11, 0, 13, 8, 1]
|
||||
});
|
||||
}
|
||||
return jdkVersions;
|
||||
});
|
||||
}
|
||||
getPlatformOption(platform = process.platform) {
|
||||
switch (platform) {
|
||||
getPlatformOption() {
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return { archive: 'tar.gz', os: 'macos' };
|
||||
case 'win32':
|
||||
|
@ -13944,11 +13935,14 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
|
|||
case 'linux':
|
||||
return { archive: 'tar.gz', os: 'linux' };
|
||||
default:
|
||||
throw new Error(`Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`);
|
||||
throw new Error(`Platform '${process.platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`);
|
||||
}
|
||||
}
|
||||
convertVersionToSemver(version) {
|
||||
return `${version.majorVersion}.${version.minorVersion}.${version.patchVersion}`;
|
||||
const major = version.version[0];
|
||||
const minor = version.version[1];
|
||||
const patch = version.version[2];
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
||||
}
|
||||
exports.MicrosoftDistributions = MicrosoftDistributions;
|
||||
|
|
|
@ -8,8 +8,6 @@ import * as tc from '@actions/tool-cache';
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const supportedPlatform = `'linux', 'macos', 'windows'`;
|
||||
|
||||
export class MicrosoftDistributions extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Microsoft', installerOptions);
|
||||
|
@ -39,14 +37,14 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
if (this.architecture !== 'x64' && this.architecture != 'aarch64') {
|
||||
if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
|
||||
const opts = this.getPlatformOption();
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion.join('.')}-${opts.os}-${
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
|
||||
this.architecture
|
||||
}.${opts.archive}`,
|
||||
version: this.convertVersionToSemver(item)
|
||||
|
@ -71,36 +69,28 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
|
||||
private async getAvailableVersions(): Promise<MicrosoftVersion[]> {
|
||||
// TODO get these dynamically!
|
||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||
const jdkVersions = [
|
||||
{
|
||||
majorVersion: 17,
|
||||
minorVersion: 0,
|
||||
patchVersion: 1,
|
||||
fullVersion: [17, 0, 1, 12, 1]
|
||||
version: [17, 0, 1, 12, 1]
|
||||
},
|
||||
{
|
||||
majorVersion: 16,
|
||||
minorVersion: 0,
|
||||
patchVersion: 2,
|
||||
fullVersion: [16, 0, 2.7, 1]
|
||||
version: [16, 0, 2, 7, 1]
|
||||
}
|
||||
];
|
||||
|
||||
// M1 is only supported for Java 16 & 17
|
||||
if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
|
||||
jdkVersions.push({
|
||||
majorVersion: 11,
|
||||
minorVersion: 0,
|
||||
patchVersion: 13,
|
||||
fullVersion: [11, 0, 13, 8, 1]
|
||||
version: [11, 0, 13, 8, 1]
|
||||
});
|
||||
}
|
||||
|
||||
return jdkVersions;
|
||||
}
|
||||
|
||||
private getPlatformOption(platform: NodeJS.Platform = process.platform): PlatformOptions {
|
||||
switch (platform) {
|
||||
private getPlatformOption(): PlatformOptions {
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return { archive: 'tar.gz', os: 'macos' };
|
||||
case 'win32':
|
||||
|
@ -109,12 +99,15 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
return { archive: 'tar.gz', os: 'linux' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`
|
||||
`Platform '${process.platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private convertVersionToSemver(version: MicrosoftVersion): string {
|
||||
return `${version.majorVersion}.${version.minorVersion}.${version.patchVersion}`;
|
||||
const major = version.version[0];
|
||||
const minor = version.version[1];
|
||||
const patch = version.version[2];
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,5 @@ export interface PlatformOptions {
|
|||
|
||||
export interface MicrosoftVersion {
|
||||
downloadUrl?: string;
|
||||
majorVersion: number;
|
||||
minorVersion: number;
|
||||
patchVersion: number;
|
||||
fullVersion: Array<number>;
|
||||
version: Array<number>;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue