This commit is contained in:
John Oliver 2023-11-22 14:49:12 -08:00 committed by GitHub
commit 784f7490e0
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 {HttpClient} from '@actions/http-client';
import {IAdoptAvailableVersions} from '../../src/distributions/adopt/models';
import { import {
AdoptDistribution, AdoptDistribution,
AdoptImplementation AdoptImplementation
@ -8,14 +7,29 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os'; import os from 'os';
import temurinManifestData from '../data/temurin.json';
import manifestData from '../data/adopt.json'; import manifestData from '../data/adopt.json';
import {
TemurinDistribution,
TemurinImplementation
} from '../../src/distributions/temurin/installer';
describe('getAvailableVersions', () => { describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance; let spyHttpClient: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({ spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValue({
statusCode: 200, statusCode: 200,
headers: {}, headers: {},
result: [] result: []
@ -132,6 +146,15 @@ describe('getAvailableVersions', () => {
it('load available versions', async () => { it('load available versions', async () => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValueOnce({ .mockReturnValueOnce({
statusCode: 200, statusCode: 200,
headers: {}, headers: {},
@ -233,6 +256,17 @@ describe('findPackageForDownload', () => {
['15.0.1+9', '15.0.1+9'], ['15.0.1+9', '15.0.1+9'],
['15.0.1+9.1', '15.0.1+9.1'] ['15.0.1+9.1', '15.0.1+9.1']
])('version is resolved correctly %s -> %s', async (input, expected) => { ])('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( const distribution = new AdoptDistribution(
{ {
version: '11', version: '11',
@ -240,14 +274,36 @@ describe('findPackageForDownload', () => {
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, },
AdoptImplementation.Hotspot AdoptImplementation.Hotspot,
temurinDistribution
); );
distribution['getAvailableVersions'] = async () => manifestData as any; distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input); const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected); expect(resolvedVersion.version).toBe(expected);
}); });
it('version is found but binaries list is empty', async () => { 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( const distribution = new AdoptDistribution(
{ {
version: '11', version: '11',
@ -255,13 +311,96 @@ describe('findPackageForDownload', () => {
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, },
AdoptImplementation.Hotspot 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',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
temurinDistribution
); );
distribution['getAvailableVersions'] = async () => manifestData as any; distribution['getAvailableVersions'] = async () => manifestData as any;
await expect( await expect(
distribution['findPackageForDownload']('9.0.8') distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */); ).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 () => { it('version is not found', async () => {
const distribution = new AdoptDistribution( const distribution = new AdoptDistribution(
@ -271,7 +410,8 @@ describe('findPackageForDownload', () => {
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}, },
AdoptImplementation.Hotspot AdoptImplementation.Hotspot,
temurinDistribution
); );
distribution['getAvailableVersions'] = async () => manifestData as any; distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow( await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
@ -280,6 +420,23 @@ describe('findPackageForDownload', () => {
}); });
it('version list is empty', async () => { 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( const distribution = new AdoptDistribution(
{ {
version: '11', version: '11',

28551
dist/cleanup/index.js vendored

File diff suppressed because one or more lines are too long

38414
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -17,6 +17,7 @@ import {
getDownloadArchiveExtension, getDownloadArchiveExtension,
isVersionSatisfies isVersionSatisfies
} from '../../util'; } from '../../util';
import {TemurinDistribution, TemurinImplementation} from '../temurin/installer';
export enum AdoptImplementation { export enum AdoptImplementation {
Hotspot = 'Hotspot', Hotspot = 'Hotspot',
@ -26,13 +27,61 @@ export enum AdoptImplementation {
export class AdoptDistribution extends JavaBase { export class AdoptDistribution extends JavaBase {
constructor( constructor(
installerOptions: JavaInstallerOptions, installerOptions: JavaInstallerOptions,
private readonly jvmImpl: AdoptImplementation private readonly jvmImpl: AdoptImplementation,
private readonly temurinDistribution: TemurinDistribution | null = null
) { ) {
super(`Adopt-${jvmImpl}`, installerOptions); 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( protected async findPackageForDownload(
version: string 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> { ): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsRaw = await this.getAvailableVersions();
const availableVersionsWithBinaries = availableVersionsRaw const availableVersionsWithBinaries = availableVersionsRaw

View file

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