Format adopt

This commit is contained in:
John Oliver 2023-09-28 11:43:18 +01:00
parent b50facbbd0
commit 2df4cee1ae
2 changed files with 104 additions and 85 deletions

View File

@ -1,11 +1,17 @@
import {HttpClient} from '@actions/http-client';
import {AdoptDistribution, AdoptImplementation} from '../../src/distributions/adopt/installer';
import {
AdoptDistribution,
AdoptImplementation
} from '../../src/distributions/adopt/installer';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
import manifestData from '../data/adopt.json';
import {TemurinDistribution, TemurinImplementation} from "../../src/distributions/temurin/installer";
import {
TemurinDistribution,
TemurinImplementation
} from '../../src/distributions/temurin/installer';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -258,7 +264,6 @@ describe('findPackageForDownload', () => {
['15.0.1+9', '15.0.1+9'],
['15.0.1+9.1', '15.0.1+9.1']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
@ -280,18 +285,19 @@ describe('findPackageForDownload', () => {
temurinDistribution
);
temurinDistribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
temurinDistribution['getAvailableVersions'] = async () =>
manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](
input
);
expect(resolvedVersion.version).toBe(expected);
});
});
describe('Falls back if Temurin fails', () => {
it.each([
['9', '9.0.7+10']
])('version is resolved correctly %s -> %s', async (input, expected) => {
it.each([['9', '9.0.7+10']])(
'version is resolved correctly %s -> %s',
async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
@ -313,14 +319,18 @@ describe('findPackageForDownload', () => {
temurinDistribution
);
temurinDistribution['findPackageForDownload'] = async () => new Promise(function () {
throw new Error("Could not find satisfied version for SemVer")
temurinDistribution['findPackageForDownload'] = async () =>
new Promise(function () {
throw new Error('Could not find satisfied version for SemVer');
});
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
const resolvedVersion = await distribution['findPackageForDownload'](
input
);
expect(resolvedVersion.version).toBe(expected);
});
}
);
});
it('version is found but binaries list is empty', async () => {

View File

@ -17,7 +17,7 @@ import {
getDownloadArchiveExtension,
isVersionSatisfies
} from '../../util';
import {TemurinDistribution, TemurinImplementation} from "../temurin/installer";
import {TemurinDistribution, TemurinImplementation} from '../temurin/installer';
export enum AdoptImplementation {
Hotspot = 'Hotspot',
@ -33,36 +33,45 @@ export class AdoptDistribution extends JavaBase {
super(`Adopt-${jvmImpl}`, installerOptions);
if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) {
throw new Error("Only Hotspot JVM is supported by Temurin.")
throw new Error('Only Hotspot JVM is supported by Temurin.');
}
// Only use the temurin repo for Hotspot JVMs
if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) {
this.temurinDistribution = new TemurinDistribution(
installerOptions,
TemurinImplementation.Hotspot);
TemurinImplementation.Hotspot
);
}
}
protected async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
if (this.jvmImpl == AdoptImplementation.Hotspot) {
core.notice("AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration.")
core.notice(
"AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration."
);
}
if (this.jvmImpl == AdoptImplementation.Hotspot && this.temurinDistribution != null) {
if (
this.jvmImpl == AdoptImplementation.Hotspot &&
this.temurinDistribution != null
) {
try {
let result = await this.temurinDistribution.findPackageForDownload(version)
let result = await this.temurinDistribution.findPackageForDownload(
version
);
if (result != undefined) {
return result
return result;
}
} catch (error) {
if (error.message.includes('Could not find satisfied version')) {
core.notice("The JVM you are looking for could not be found in the Temurin repository, this likely indicates " +
"that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.")
core.notice(
'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' +
'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'
);
}
}
}