Add optional java-package parameter

This commit is contained in:
Gil Tene 2019-11-02 17:47:44 -07:00
parent 25d3249d32
commit e7c72b564b
4 changed files with 42 additions and 14 deletions

View file

@ -29,9 +29,10 @@ if (!tempDirectory) {
export async function getJava(
version: string,
arch: string,
jdkFile: string
jdkFile: string,
javaPackage: string
): Promise<void> {
let toolPath = tc.find('Java', version);
let toolPath = tc.find(javaPackage, version);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
@ -45,7 +46,7 @@ export async function getJava(
)).readBody();
let refs = contents.match(/<a href.*\">/gi) || [];
const downloadInfo = getDownloadInfo(refs, version);
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
@ -66,7 +67,7 @@ export async function getJava(
core.debug(`jdk extracted to ${jdkDir}`);
toolPath = await tc.cacheDir(
jdkDir,
'Java',
javaPackage,
getCacheVersionString(version),
arch
);
@ -173,7 +174,8 @@ async function unzipJavaDownload(
function getDownloadInfo(
refs: string[],
version: string
version: string,
javaPackage: string
): {version: string; url: string} {
version = normalizeVersion(version);
let extension = '';
@ -187,6 +189,17 @@ function getDownloadInfo(
}
}
let pkgRegexp = new RegExp('');
if (javaPackage === 'jdk') {
pkgRegexp = /jdk.*-/gi;
} else if (javaPackage == 'jre') {
pkgRegexp = /jre.*-/gi;
} else if (javaPackage == 'jdk+fx') {
pkgRegexp = /fx-jdk.*-/gi;
} else {
throw new Error(`package argument ${javaPackage} is not in [jdk | jre | jdk+fx]`);
}
// Maps version to url
let versionMap = new Map();
@ -197,7 +210,7 @@ function getDownloadInfo(
}
// If we haven't returned, means we're looking at the correct platform
let versions = ref.match(/jdk.*-/gi) || [];
let versions = ref.match(pkgRegexp) || [];
if (versions.length > 1) {
throw new Error(
`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`

View file

@ -10,8 +10,9 @@ async function run() {
}
const arch = core.getInput('architecture', {required: true});
const jdkFile = core.getInput('jdkFile', {required: false}) || '';
const javaPackage = core.getInput('java-package', {required: false}) || 'jdk';
await installer.getJava(version, arch, jdkFile);
await installer.getJava(version, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);