Skip to content
Permalink
Browse files
feat(datasource/adoptium): support jre only releases (#11652)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
  • Loading branch information
viceice and HonkingGoose committed Sep 9, 2021
1 parent 922a36c commit 218fc5b6946e6e41d86d772e34f9d04ce37c10fb
@@ -0,0 +1,20 @@
{
"versions": [
{
"build": 7,
"major": 11,
"minor": 0,
"openjdk_version": "11.0.12+7",
"security": 12,
"semver": "11.0.12+7"
},
{
"build": 8,
"major": 8,
"minor": 0,
"openjdk_version": "1.8.0_302-b08",
"security": 302,
"semver": "8.0.302+8"
}
]
}
@@ -159,6 +159,21 @@ Object {
}
`;

exports[`datasource/adoptium-java/index getReleases processes real data (jre) 1`] = `
Object {
"homepage": "https://adoptium.net",
"registryUrl": "https://api.adoptium.net/",
"releases": Array [
Object {
"version": "8.0.302+8",
},
Object {
"version": "11.0.12+7",
},
],
}
`;

exports[`datasource/adoptium-java/index getReleases processes real data 1`] = `
Object {
"homepage": "https://adoptium.net",
@@ -4,3 +4,12 @@ export const pageSize = 50;
export const defaultRegistryUrl = 'https://api.adoptium.net/';

export const datasource = 'adoptium-java';

export function getImageType(lookupName: string): string {
switch (lookupName) {
case 'java-jre':
return 'jre';
default:
return 'jdk';
}
}
@@ -5,9 +5,10 @@ import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { datasource, defaultRegistryUrl, pageSize } from './common';

const res1 = loadFixture('page.json');
const jre = loadFixture('jre.json');

function getPath(page: number): string {
return `/v3/info/release_versions?page_size=${pageSize}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium&page=${page}`;
function getPath(page: number, imageType = 'jdk'): string {
return `/v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium&page=${page}`;
}
function* range(start: number, end: number): Generator<number, number, number> {
yield start;
@@ -17,6 +18,8 @@ function* range(start: number, end: number): Generator<number, number, number> {
yield* range(start + 1, end);
}

const depName = 'java';

describe('datasource/adoptium-java/index', () => {
describe('getReleases', () => {
it('throws for error', async () => {
@@ -27,7 +30,7 @@ describe('datasource/adoptium-java/index', () => {
await expect(
getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
@@ -37,7 +40,7 @@ describe('datasource/adoptium-java/index', () => {
expect(
await getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
})
).toBeNull();
});
@@ -50,7 +53,7 @@ describe('datasource/adoptium-java/index', () => {
expect(
await getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
})
).toBeNull();
});
@@ -60,7 +63,7 @@ describe('datasource/adoptium-java/index', () => {
await expect(
getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
@@ -69,12 +72,22 @@ describe('datasource/adoptium-java/index', () => {
httpMock.scope(defaultRegistryUrl).get(getPath(0)).reply(200, res1);
const res = await getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(3);
});

it('processes real data (jre)', async () => {
httpMock.scope(defaultRegistryUrl).get(getPath(0, 'jre')).reply(200, jre);
const res = await getPkgReleases({
datasource,
depName: 'java-jre',
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2);
});

it('pages', async () => {
httpMock
.scope(defaultRegistryUrl)
@@ -86,7 +99,7 @@ describe('datasource/adoptium-java/index', () => {
.reply(404);
const res = await getPkgReleases({
datasource,
depName: 'adoptium-java',
depName,
});
expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(50);
@@ -1,9 +1,15 @@
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import { cache } from '../../util/cache/package/decorator';
import { HttpError } from '../../util/http/types';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import { datasource, defaultRegistryUrl, pageSize } from './common';
import {
datasource,
defaultRegistryUrl,
getImageType,
pageSize,
} from './common';
import type { AdoptiumJavaResponse } from './types';

export class AdoptiumJavaDatasource extends Datasource {
@@ -25,9 +31,15 @@ export class AdoptiumJavaDatasource extends Datasource {
})
async getReleases({
registryUrl,
lookupName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
let page = 0;
const url = `${registryUrl}v3/info/release_versions?page_size=${pageSize}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium`;
const imageType = getImageType(lookupName);
logger.trace(
{ registryUrl, lookupName, imageType },
'fetching java release'
);
const url = `${registryUrl}v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium`;

const result: ReleaseResult = {
homepage: 'https://adoptium.net',
@@ -1,5 +1,10 @@
This datasource returns releases from [Adoptium](https://adoptium.net/) API.

It uses `project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium` as filter parameters.
It uses `image_type=<jre|jdk>&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium` as filter parameters.

It only uses the first 50 pages with 50 items per page.

Use `java-jdk` or `java` as `lookupName` to get releases which come with the Java Development Kit.

Use `java-jre` as `lookupName` if you only want releases which come with the Java Runtime Environment.
Currently only the LTS releases of Java come with the JRE.

0 comments on commit 218fc5b

Please sign in to comment.