Merge 5321a4dff097f94f22687359df1d5e15ab5eb160 into 78078da0cd035d0d177cc2cb696e05d96fba7d11

This commit is contained in:
John Oliver 2023-10-18 11:30:05 +00:00 committed by GitHub
commit ec37390610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12450 additions and 54957 deletions

View File

@ -1,5 +1,4 @@
import {HttpClient} from '@actions/http-client';
import {IAdoptAvailableVersions} from '../../src/distributions/adopt/models';
import {
AdoptDistribution,
AdoptImplementation
@ -8,18 +7,33 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
import temurinManifestData from '../data/temurin.json';
import manifestData from '../data/adopt.json';
import {
TemurinDistribution,
TemurinImplementation
} from '../../src/distributions/temurin/installer';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: []
});
spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValue({
statusCode: 200,
headers: {},
result: []
});
});
afterEach(() => {
@ -132,6 +146,15 @@ describe('getAvailableVersions', () => {
it('load available versions', async () => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
@ -233,6 +256,17 @@ 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',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
const distribution = new AdoptDistribution(
{
version: '11',
@ -240,14 +274,108 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
describe('delegates to Temurin', () => {
it.each([
['8', '8.0.302+8'],
['16', '16.0.2+7'],
['16.0', '16.0.2+7'],
['16.0.2', '16.0.2+7'],
['8.x', '8.0.302+8'],
['x', '16.0.2+7']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () =>
temurinManifestData as any;
const distribution = new AdoptDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['findPackageForDownload'] = async () => {
throw new Error(`Could not find satisfied version`);
};
const resolvedVersion = await temurinDistribution[
'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) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
const distribution = new AdoptDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
temurinDistribution
);
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
);
expect(resolvedVersion.version).toBe(expected);
}
);
});
it('version is found but binaries list is empty', async () => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
const distribution = new AdoptDistribution(
{
version: '11',
@ -255,13 +383,24 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */);
});
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
it('version is not found', async () => {
const distribution = new AdoptDistribution(
@ -271,7 +410,8 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
@ -280,6 +420,23 @@ describe('findPackageForDownload', () => {
});
it('version list is empty', async () => {
const spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
return {
statusCode: 200,
headers: {},
result: manifestData as any
} as any;
});
const distribution = new AdoptDistribution(
{
version: '11',

28659
dist/cleanup/index.js vendored

File diff suppressed because one or more lines are too long

38520
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@ import {
getDownloadArchiveExtension,
isVersionSatisfies
} from '../../util';
import {TemurinDistribution, TemurinImplementation} from '../temurin/installer';
export enum AdoptImplementation {
Hotspot = 'Hotspot',
@ -26,13 +27,61 @@ export enum AdoptImplementation {
export class AdoptDistribution extends JavaBase {
constructor(
installerOptions: JavaInstallerOptions,
private readonly jvmImpl: AdoptImplementation
private readonly jvmImpl: AdoptImplementation,
private readonly temurinDistribution: TemurinDistribution | null = null
) {
super(`Adopt-${jvmImpl}`, installerOptions);
if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) {
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
);
}
}
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."
);
}
if (
this.jvmImpl == AdoptImplementation.Hotspot &&
this.temurinDistribution != null
) {
try {
const result = await this.temurinDistribution.findPackageForDownload(
version
);
if (result != undefined) {
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.'
);
}
}
}
// failed to find a Temurin version, so fall back to AdoptOpenJDK
return this.findPackageForDownloadOldAdoptOpenJdk(version);
}
private async findPackageForDownloadOldAdoptOpenJdk(
version: string
): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();
const availableVersionsWithBinaries = availableVersionsRaw

View File

@ -30,7 +30,7 @@ export class TemurinDistribution extends JavaBase {
super(`Temurin-${jvmImpl}`, installerOptions);
}
protected async findPackageForDownload(
public async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();