Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBM Semeru (OpenJ9) Support #289

Merged
merged 15 commits into from
Mar 21, 2023
3 changes: 2 additions & 1 deletion .github/workflows/e2e-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
'zulu',
'liberica',
'microsoft',
'semeru',
'corretto'
] # internally 'adopt-hotspot' is the same as 'adopt'
version: ['8', '11', '16']
Expand Down Expand Up @@ -199,7 +200,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
distribution: ['temurin', 'zulu', 'liberica']
distribution: ['temurin', 'zulu', 'liberica', 'semeru']
java-package: ['jre']
version: ['17.0']
include:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ typings/
# DynamoDB Local files
.dynamodb/
.vscode/

# IntelliJ / WebStorm
/.idea/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ Currently, the following distributions are supported:
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
| `microsoft` | Microsoft Build of OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
| `semeru` | IBM Semeru Runtime Open Edition | [Link](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [Link](https://openjdk.java.net/legal/gplv2+ce.html) |
| `oracle` | Oracle JDK | [Link](https://www.oracle.com/java/technologies/downloads/) | [Link](https://java.com/freeuselicense)

**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.

**NOTE:** AdoptOpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` to `temurin` to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
**NOTE:** AdoptOpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` and `adopt-openj9`, to `temurin` and `semeru` respectively, to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).

**NOTE:** For Azul Zulu OpenJDK architectures x64 and arm64 are mapped to x86 / arm with proper hw_bitness.

Expand Down
2,168 changes: 2,168 additions & 0 deletions __tests__/data/semeru.json

Large diffs are not rendered by default.

287 changes: 287 additions & 0 deletions __tests__/distributors/semeru-installer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
import {HttpClient} from '@actions/http-client';

import {JavaInstallerOptions} from '../../src/distributions/base-models';
import {SemeruDistribution} from '../../src/distributions/semeru/installer';

import manifestData from '../data/semeru.json';

describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;

beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: []
});
});

afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});

it.each([
[
{
version: '16',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{
version: '16',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
'os=mac&architecture=x86&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{
version: '16',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
'os=mac&architecture=x64&image_type=jre&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{
version: '16',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
]
])(
'build correct url for %s',
async (installerOptions: JavaInstallerOptions, expectedParameters) => {
const distribution = new SemeruDistribution(installerOptions);
const baseUrl =
'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
const expectedUrl = `${baseUrl}?project=jdk&vendor=ibm&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
distribution['getPlatformOption'] = () => 'mac';

await distribution['getAvailableVersions']();

expect(spyHttpClient.mock.calls).toHaveLength(1);
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
}
);

it('load available versions', async () => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: []
});

const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).not.toBeNull();
expect(availableVersions.length).toBe(manifestData.length * 2);
});

it.each([
['jdk', 'Java_IBM_Semeru_jdk'],
['jre', 'Java_IBM_Semeru_jre']
])('find right toolchain folder', (packageType: string, expected: string) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: packageType,
checkLatest: false
});

// @ts-ignore - because it is protected
expect(distribution.toolcacheFolderName).toBe(expected);
});
});

describe('findPackageForDownload', () => {
it.each([
['8', '8.0.322+6'],
['16', '16.0.2+7'],
['16.0', '16.0.2+7'],
['16.0.2', '16.0.2+7'],
['8.x', '8.0.322+6'],
['x', '17.0.2+8']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
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 distribution = new SemeruDistribution({
version: '9.0.8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */);
});

it('version is not found', async () => {
const distribution = new SemeruDistribution({
version: '7.x',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});

it('version list is empty', async () => {
const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});

it.each(['x64', 'x86', 'ppc64le', 'ppc64', 's390x', 'aarch64'])(
'correct Semeru `%s` architecture resolves',
async (arch: string) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: arch,
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload']('8');
expect(resolvedVersion.version).not.toBeNull();
}
);

it.each(['zos', 'z/OS', 'z/os', 'test0987654321=', '++=++', 'myArch'])(
'incorrect Semeru `%s` architecture throws',
async (arch: string) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: arch,
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
`Unsupported architecture for IBM Semeru: ${arch}, the following are supported: x64, x86, ppc64le, ppc64, s390x, aarch64`
);
}
);

it.each(['9-ea', '17-ea', '8-ea', '4-ea'])(
'early access version are illegal for Semeru (%s)',
async (version: string) => {
const distribution = new SemeruDistribution({
version: version,
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload'](version)
).rejects.toThrow(
'IBM Semeru does not provide builds for early access versions'
);
}
);

it.each([
'jdk+fx',
'jre+fx',
'test',
'test2',
'jdk-fx',
'javafx',
'jdk-javafx',
'ibm',
' '
])(
'rejects incorrect `%s` Semeru package type',
async (packageType: string) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: packageType,
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
'IBM Semeru only provide `jdk` and `jre` package types'
);
}
);

it.each(['jdk', 'jre'])(
'accepts correct `%s` Semeru package type',
async (packageType: string) => {
const distribution = new SemeruDistribution({
version: '8',
architecture: 'x64',
packageType: packageType,
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload']('8');
await expect(resolvedVersion.version).toMatch(/8[0-9.]+/);
}
);

it('fails when long release name is used', async () => {
expect(
() =>
new SemeruDistribution({
version: 'jdk-16.0.2+7_openj9-0.27.1',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
})
).toThrow(
"The string 'jdk-16.0.2+7_openj9-0.27.1' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information"
);
});
});