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

@ -41,9 +41,9 @@ if (!tempDirectory) {
}
tempDirectory = path.join(baseLocation, 'actions', 'temp');
}
function getJava(version, arch, jdkFile) {
function getJava(version, arch, jdkFile, javaPackage) {
return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find('Java', version);
let toolPath = tc.find(javaPackage, version);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
}
@ -54,7 +54,7 @@ function getJava(version, arch, jdkFile) {
let http = new httpm.HttpClient('setup-java');
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody();
let refs = contents.match(/<a href.*\">/gi) || [];
const downloadInfo = getDownloadInfo(refs, version);
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
jdkFile = yield tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
@ -66,7 +66,7 @@ function getJava(version, arch, jdkFile) {
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
core.debug(`jdk extracted to ${jdkDir}`);
toolPath = yield tc.cacheDir(jdkDir, 'Java', getCacheVersionString(version), arch);
toolPath = yield tc.cacheDir(jdkDir, javaPackage, getCacheVersionString(version), arch);
}
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
core.exportVariable('JAVA_HOME', toolPath);
@ -162,7 +162,7 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
}
});
}
function getDownloadInfo(refs, version) {
function getDownloadInfo(refs, version, javaPackage) {
version = normalizeVersion(version);
let extension = '';
if (IS_WINDOWS) {
@ -176,6 +176,19 @@ function getDownloadInfo(refs, version) {
extension = `-linux_x64.tar.gz`;
}
}
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();
// Filter by platform
@ -184,7 +197,7 @@ function getDownloadInfo(refs, version) {
return;
}
// 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

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