add support for adoptopenjdk binaries

This commit is contained in:
George Adams 2020-05-26 14:20:02 +01:00
parent 1253a7eed4
commit db7c9fb180
No known key found for this signature in database
GPG key ID: 7B8D7E4421A0916D
7 changed files with 149 additions and 47 deletions

View file

@ -5,7 +5,7 @@ jobs:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:
matrix: matrix:
operating-system: [ubuntu-latest, windows-latest] operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -24,7 +24,7 @@ jobs:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:
matrix: matrix:
operating-system: [ubuntu-latest, windows-latest] operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -19,7 +19,8 @@ steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: '9.0.4' # The JDK version to make available on the path. java-version: '11' # The JDK version to make available on the path.
vendor: adoptopenjdk # (adoptopenjdk or zulu) - defaults to adoptopenjdk
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64 architecture: x64 # (x64 or x86) - defaults to x64
- run: java -cp java HelloWorldApp - run: java -cp java HelloWorldApp
@ -30,13 +31,13 @@ Examples of version specifications that the java-version parameter will accept:
e.g. ```6, 7, 8, 9, 10, 11, 12, 13, ...``` e.g. ```6, 7, 8, 9, 10, 11, 12, 13, ...```
- A semver Java version specification - A semver Java version specification (Zulu only)
e.g. ```8.0.232, 7.0.181, 11.0.4``` e.g. ```8.0.232, 7.0.181, 11.0.4```
e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212``` e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212```
- An early access (EA) Java version - An early access (EA) Java version (Zulu only)
e.g. ```14-ea, 15-ea``` e.g. ```14-ea, 15-ea```
@ -46,7 +47,7 @@ Examples of version specifications that the java-version parameter will accept:
Note that, per semver rules, EA builds will be matched by explicit EA version specifications. Note that, per semver rules, EA builds will be matched by explicit EA version specifications.
- 1.x syntax - 1.x syntax (Zulu only)
e.g. ```1.8``` (same as ```8```) e.g. ```1.8``` (same as ```8```)

View file

@ -13,12 +13,15 @@ import * as installer from '../src/installer';
let javaFilePath = ''; let javaFilePath = '';
let javaUrl = ''; let javaUrl = '';
let additionalPath = '';
if (process.platform === 'win32') { if (process.platform === 'win32') {
javaFilePath = path.join(javaDir, 'java_win.zip'); javaFilePath = path.join(javaDir, 'java_win.zip');
javaUrl = javaUrl =
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_windows-x64_bin.zip'; 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_windows-x64_bin.zip';
} else if (process.platform === 'darwin') { } else if (process.platform === 'darwin') {
javaFilePath = path.join(javaDir, 'java_mac.tar.gz'); javaFilePath = path.join(javaDir, 'java_mac.tar.gz');
// macOS tarballs are in bundle format
additionalPath = '/Contents/Home';
javaUrl = javaUrl =
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz'; 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz';
} else { } else {
@ -51,34 +54,57 @@ describe('installer tests', () => {
} }
}, 100000); }, 100000);
it('Installs version of Java from jdkFile if no matching version is installed', async () => { it('Installs version of Java from jdkFile if no matching version is installed AdoptOpenJDK', async () => {
await installer.getJava('12', 'x64', javaFilePath, 'jdk'); await installer.getJava('12', 'adoptopenjdk', 'x64', javaFilePath, 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '12.0.0', 'x64'); const JavaDir = path.join(toolDir, 'jdk', '12.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000); }, 100000);
it('Throws if invalid directory to jdk', async () => { it('Installs version of Java from jdkFile if no matching version is installed Zulu', async () => {
await installer.getJava('12', 'zulu', 'x64', javaFilePath, 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '12.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);
it('Throws if invalid directory to jdk AdoptOpenJDK', async () => {
let thrown = false; let thrown = false;
try { try {
await installer.getJava('1000', 'x64', 'bad path', 'jdk'); await installer.getJava('1000', 'adoptopenjdk', 'x64', 'bad path', 'jdk');
} catch { } catch {
thrown = true; thrown = true;
} }
expect(thrown).toBe(true); expect(thrown).toBe(true);
}); });
it('Downloads java if no file given', async () => { it('Throws if invalid directory to jdk Zulu', async () => {
await installer.getJava('8.0.102', 'x64', '', 'jdk'); let thrown = false;
const JavaDir = path.join(toolDir, 'jdk', '8.0.102', 'x64'); try {
await installer.getJava('1000', 'zulu', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('Downloads java if no file given AdoptOpenJDK', async () => {
await installer.getJava('8', 'adoptopenjdk', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '8.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);
it('Downloads java if no file given Zulu', async () => {
await installer.getJava('8.0.102', 'zulu', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '8.0.102', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000); }, 100000);
it('Downloads java with 1.x syntax', async () => { it('Downloads java with 1.x syntax', async () => {
await installer.getJava('1.10', 'x64', '', 'jdk'); await installer.getJava('1.10', 'zulu', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '10.0.2', 'x64'); const JavaDir = path.join(toolDir, 'jdk', '10.0.2', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@ -86,15 +112,23 @@ describe('installer tests', () => {
}, 100000); }, 100000);
it('Downloads java with normal semver syntax', async () => { it('Downloads java with normal semver syntax', async () => {
await installer.getJava('9.0.x', 'x64', '', 'jdk'); await installer.getJava('9.0.x', 'zulu', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '9.0.7', 'x64'); const JavaDir = path.join(toolDir, 'jdk', '9.0.7', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000); }, 100000);
it('Downloads java if package is jre', async () => { it('Downloads java if package is jre AdoptOpenJDK', async () => {
await installer.getJava('8.0.222', 'x64', '', 'jre'); await installer.getJava('11', 'adoptopenjdk', 'x64', '', 'jre');
const JavaDir = path.join(toolDir, 'jre', '11.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);
it('Downloads java if package is jre Zulu', async () => {
await installer.getJava('8.0.222', 'zulu', 'x64', '', 'jre');
const JavaDir = path.join(toolDir, 'jre', '8.0.222', 'x64'); const JavaDir = path.join(toolDir, 'jre', '8.0.222', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@ -102,17 +136,27 @@ describe('installer tests', () => {
}, 100000); }, 100000);
it('Downloads java if package is jdk+fx', async () => { it('Downloads java if package is jdk+fx', async () => {
await installer.getJava('8.0.222', 'x64', '', 'jdk+fx'); await installer.getJava('8.0.222', 'zulu', 'x64', '', 'jdk+fx');
const JavaDir = path.join(toolDir, 'jdk+fx', '8.0.222', 'x64'); const JavaDir = path.join(toolDir, 'jdk+fx', '8.0.222', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000); }, 100000);
it('Throws if invalid java package is specified', async () => { it('Throws if invalid java package is specified AdoptOpenJDK', async () => {
let thrown = false; let thrown = false;
try { try {
await installer.getJava('8.0.222', 'x64', '', 'bad jdk'); await installer.getJava('8', 'adoptopenjdk', 'x64', '', 'bad jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('Throws if invalid java package is specified Zulu', async () => {
let thrown = false;
try {
await installer.getJava('8.0.222', 'zulu', 'x64', '', 'bad jdk');
} catch { } catch {
thrown = true; thrown = true;
} }
@ -122,7 +166,7 @@ describe('installer tests', () => {
it('Throws if invalid directory to jdk', async () => { it('Throws if invalid directory to jdk', async () => {
let thrown = false; let thrown = false;
try { try {
await installer.getJava('1000', 'x64', 'bad path', 'jdk'); await installer.getJava('1000', 'zulu', 'x64', 'bad path', 'jdk');
} catch { } catch {
thrown = true; thrown = true;
} }
@ -136,6 +180,7 @@ describe('installer tests', () => {
// This will throw if it doesn't find it in the cache (because no such version exists) // This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getJava( await installer.getJava(
'250', '250',
'zulu',
'x64', 'x64',
'path shouldnt matter, found in cache', 'path shouldnt matter, found in cache',
'jdk' 'jdk'
@ -149,7 +194,7 @@ describe('installer tests', () => {
let thrown = false; let thrown = false;
try { try {
// This will throw if it doesn't find it in the cache (because no such version exists) // This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getJava('251', 'x64', 'bad path', 'jdk'); await installer.getJava('251', 'zulu', 'x64', 'bad path', 'jdk');
} catch { } catch {
thrown = true; thrown = true;
} }

View file

@ -9,6 +9,11 @@ inputs:
Early access versions can be specified in the form of e.g. 14-ea, Early access versions can be specified in the form of e.g. 14-ea,
14.0.0-ea, or 14.0.0-ea.28' 14.0.0-ea, or 14.0.0-ea.28'
required: true required: true
vendor:
description: 'The vendor to fetch the binary from (adoptopenjdk, zulu).
Defaults to adoptopenjdk'
required: false
default: 'adoptopenjdk'
java-package: java-package:
description: 'The package type (jre, jdk, jdk+fx)' description: 'The package type (jre, jdk, jdk+fx)'
required: false required: false

View file

@ -13,6 +13,7 @@ const IS_WINDOWS = util.isWindows();
export async function getJava( export async function getJava(
version: string, version: string,
vendor: string,
arch: string, arch: string,
jdkFile: string, jdkFile: string,
javaPackage: string javaPackage: string
@ -23,31 +24,26 @@ export async function getJava(
core.debug(`Tool found in cache ${toolPath}`); core.debug(`Tool found in cache ${toolPath}`);
} else { } else {
let compressedFileExtension = ''; let compressedFileExtension = '';
if (!jdkFile) { if (!jdkFile) {
core.debug('Downloading JDK from Azul'); async function setupVendor(vendor: string) {
const http = new httpm.HttpClient('setup-java', undefined, { switch (vendor) {
allowRetries: true, case 'adoptopenjdk':
maxRetries: 3 [jdkFile, version] = await getJavaAdoptOpenJDK(
}); version,
const url = 'https://static.azul.com/zulu/bin/'; javaPackage,
const response = await http.get(url); arch
const statusCode = response.message.statusCode || 0; );
if (statusCode < 200 || statusCode > 299) { break;
let body = ''; case 'zulu':
try { [jdkFile, version] = await getJavaZulu(version, javaPackage);
body = await response.readBody(); break;
} catch (err) {
core.debug(`Unable to read body: ${err.message}`);
} }
const message = `Unexpected HTTP status code '${response.message.statusCode}' when retrieving versions from '${url}'. ${body}`.trim(); return [jdkFile, version];
throw new Error(message);
} }
const contents = await response.readBody(); [jdkFile, version] = await setupVendor(vendor);
const refs = contents.match(/<a href.*\">/gi) || [];
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
} else { } else {
core.debug('Retrieving Jdk from local path'); core.debug('Retrieving Jdk from local path');
@ -71,6 +67,8 @@ export async function getJava(
); );
} }
if (process.platform === 'darwin') toolPath += '/Contents/Home';
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch; let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
core.exportVariable(extendedJavaHome, toolPath); //TODO: remove for v2 core.exportVariable(extendedJavaHome, toolPath); //TODO: remove for v2
// For portability reasons environment variables should only consist of // For portability reasons environment variables should only consist of
@ -85,6 +83,52 @@ export async function getJava(
core.setOutput('version', version); core.setOutput('version', version);
} }
async function getJavaZulu(version: string, javaPackage: string) {
core.debug('Downloading JDK from Azul');
const http = new httpm.HttpClient('setup-java', undefined, {
allowRetries: true,
maxRetries: 3
});
const url = 'https://static.azul.com/zulu/bin/';
const response = await http.get(url);
const statusCode = response.message.statusCode || 0;
if (statusCode < 200 || statusCode > 299) {
let body = '';
try {
body = await response.readBody();
} catch (err) {
core.debug(`Unable to read body: ${err.message}`);
}
const message = `Unexpected HTTP status code '${response.message.statusCode}' when retrieving versions from '${url}'. ${body}`.trim();
throw new Error(message);
}
const contents = await response.readBody();
const refs = contents.match(/<a href.*\">/gi) || [];
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
const jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
return [jdkFile, version];
}
async function getJavaAdoptOpenJDK(
version: string,
javaPackage: string,
arch: string
) {
core.debug('Downloading JDK from AdoptOpenJDK');
const jdkFile = await tc.downloadTool(
`https://api.adoptopenjdk.net/v3/binary/latest/${normalizeAdoptOpenJDK(
version
)}/ga/${OS}/${arch}/${javaPackage}/hotspot/normal/adoptopenjdk`
);
return [jdkFile, version];
}
function getCacheVersionString(version: string) { function getCacheVersionString(version: string) {
const versionArray = version.split('.'); const versionArray = version.split('.');
const major = versionArray[0]; const major = versionArray[0];
@ -290,3 +334,8 @@ function normalizeVersion(version: string): string {
return version; return version;
} }
function normalizeAdoptOpenJDK(version: string): string {
if (version == '1.8') return '8';
return version;
}

View file

@ -11,13 +11,14 @@ async function run() {
if (!version) { if (!version) {
version = core.getInput(constants.INPUT_JAVA_VERSION, {required: true}); version = core.getInput(constants.INPUT_JAVA_VERSION, {required: true});
} }
const vendor = core.getInput('vendor', {required: true});
const arch = core.getInput(constants.INPUT_ARCHITECTURE, {required: true}); const arch = core.getInput(constants.INPUT_ARCHITECTURE, {required: true});
const javaPackage = core.getInput(constants.INPUT_JAVA_PACKAGE, { const javaPackage = core.getInput(constants.INPUT_JAVA_PACKAGE, {
required: true required: true
}); });
const jdkFile = core.getInput(constants.INPUT_JDK_FILE, {required: false}); const jdkFile = core.getInput(constants.INPUT_JDK_FILE, {required: false});
await installer.getJava(version, arch, jdkFile, javaPackage); await installer.getJava(version, vendor, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '..', '.github'); const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);

View file

@ -12,6 +12,7 @@ export function getTempDir() {
} else { } else {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
baseLocation = '/Users'; baseLocation = '/Users';
toolPath += '/Contents/Home';
} else { } else {
baseLocation = '/home'; baseLocation = '/home';
} }