mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 10:26:46 +00:00
Add optional java-package parameter supporting jdk, jre, jdk+fx (#2)
* Add optional java-package parameter
This commit is contained in:
parent
f0fe308971
commit
f5880a80aa
4 changed files with 56 additions and 18 deletions
|
@ -41,9 +41,9 @@ if (!tempDirectory) {
|
||||||
}
|
}
|
||||||
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
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* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let toolPath = tc.find('Java', version);
|
let toolPath = tc.find(javaPackage, version);
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.debug(`Tool found in cache ${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 http = new httpm.HttpClient('setup-java');
|
||||||
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody();
|
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody();
|
||||||
let refs = contents.match(/<a href.*\">/gi) || [];
|
let refs = contents.match(/<a href.*\">/gi) || [];
|
||||||
const downloadInfo = getDownloadInfo(refs, version);
|
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
|
||||||
jdkFile = yield tc.downloadTool(downloadInfo.url);
|
jdkFile = yield tc.downloadTool(downloadInfo.url);
|
||||||
version = downloadInfo.version;
|
version = downloadInfo.version;
|
||||||
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
|
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));
|
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
||||||
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
|
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
|
||||||
core.debug(`jdk extracted to ${jdkDir}`);
|
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;
|
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
|
||||||
core.exportVariable('JAVA_HOME', toolPath);
|
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);
|
version = normalizeVersion(version);
|
||||||
let extension = '';
|
let extension = '';
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
|
@ -176,6 +176,23 @@ function getDownloadInfo(refs, version) {
|
||||||
extension = `-linux_x64.tar.gz`;
|
extension = `-linux_x64.tar.gz`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let pkgRegexp = new RegExp('');
|
||||||
|
let pkgTypeLength = 0;
|
||||||
|
if (javaPackage === 'jdk') {
|
||||||
|
pkgRegexp = /jdk.*-/gi;
|
||||||
|
pkgTypeLength = 'jdk'.length;
|
||||||
|
}
|
||||||
|
else if (javaPackage == 'jre') {
|
||||||
|
pkgRegexp = /jre.*-/gi;
|
||||||
|
pkgTypeLength = 'jre'.length;
|
||||||
|
}
|
||||||
|
else if (javaPackage == 'jdk+fx') {
|
||||||
|
pkgRegexp = /fx-jdk.*-/gi;
|
||||||
|
pkgTypeLength = 'fx-jdk'.length;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error(`package argument ${javaPackage} is not in [jdk | jre | jdk+fx]`);
|
||||||
|
}
|
||||||
// Maps version to url
|
// Maps version to url
|
||||||
let versionMap = new Map();
|
let versionMap = new Map();
|
||||||
// Filter by platform
|
// Filter by platform
|
||||||
|
@ -184,14 +201,14 @@ function getDownloadInfo(refs, version) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If we haven't returned, means we're looking at the correct platform
|
// 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) {
|
if (versions.length > 1) {
|
||||||
throw new Error(`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`);
|
throw new Error(`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`);
|
||||||
}
|
}
|
||||||
if (versions.length == 0) {
|
if (versions.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const refVersion = versions[0].slice('jdk'.length, versions[0].length - 1);
|
const refVersion = versions[0].slice(pkgTypeLength, versions[0].length - 1);
|
||||||
if (semver.satisfies(refVersion, version)) {
|
if (semver.satisfies(refVersion, version)) {
|
||||||
versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
|
versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
|
||||||
ref.slice('<a href="'.length, ref.length - '">'.length));
|
ref.slice('<a href="'.length, ref.length - '">'.length));
|
||||||
|
@ -209,7 +226,7 @@ function getDownloadInfo(refs, version) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (curUrl == '') {
|
if (curUrl == '') {
|
||||||
throw new Error(`No valid download found for version ${version}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`);
|
throw new Error(`No valid download found for version ${version} and package ${javaPackage}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`);
|
||||||
}
|
}
|
||||||
return { version: curVersion, url: curUrl };
|
return { version: curVersion, url: curUrl };
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ function run() {
|
||||||
}
|
}
|
||||||
const arch = core.getInput('architecture', { required: true });
|
const arch = core.getInput('architecture', { required: true });
|
||||||
const jdkFile = core.getInput('jdkFile', { required: false }) || '';
|
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');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,10 @@ if (!tempDirectory) {
|
||||||
export async function getJava(
|
export async function getJava(
|
||||||
version: string,
|
version: string,
|
||||||
arch: string,
|
arch: string,
|
||||||
jdkFile: string
|
jdkFile: string,
|
||||||
|
javaPackage: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let toolPath = tc.find('Java', version);
|
let toolPath = tc.find(javaPackage, version);
|
||||||
|
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.debug(`Tool found in cache ${toolPath}`);
|
core.debug(`Tool found in cache ${toolPath}`);
|
||||||
|
@ -45,7 +46,7 @@ export async function getJava(
|
||||||
)).readBody();
|
)).readBody();
|
||||||
let refs = contents.match(/<a href.*\">/gi) || [];
|
let refs = contents.match(/<a href.*\">/gi) || [];
|
||||||
|
|
||||||
const downloadInfo = getDownloadInfo(refs, version);
|
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
|
||||||
|
|
||||||
jdkFile = await tc.downloadTool(downloadInfo.url);
|
jdkFile = await tc.downloadTool(downloadInfo.url);
|
||||||
version = downloadInfo.version;
|
version = downloadInfo.version;
|
||||||
|
@ -66,7 +67,7 @@ export async function getJava(
|
||||||
core.debug(`jdk extracted to ${jdkDir}`);
|
core.debug(`jdk extracted to ${jdkDir}`);
|
||||||
toolPath = await tc.cacheDir(
|
toolPath = await tc.cacheDir(
|
||||||
jdkDir,
|
jdkDir,
|
||||||
'Java',
|
javaPackage,
|
||||||
getCacheVersionString(version),
|
getCacheVersionString(version),
|
||||||
arch
|
arch
|
||||||
);
|
);
|
||||||
|
@ -173,7 +174,8 @@ async function unzipJavaDownload(
|
||||||
|
|
||||||
function getDownloadInfo(
|
function getDownloadInfo(
|
||||||
refs: string[],
|
refs: string[],
|
||||||
version: string
|
version: string,
|
||||||
|
javaPackage: string
|
||||||
): {version: string; url: string} {
|
): {version: string; url: string} {
|
||||||
version = normalizeVersion(version);
|
version = normalizeVersion(version);
|
||||||
let extension = '';
|
let extension = '';
|
||||||
|
@ -187,6 +189,23 @@ function getDownloadInfo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pkgRegexp = new RegExp('');
|
||||||
|
let pkgTypeLength = 0;
|
||||||
|
if (javaPackage === 'jdk') {
|
||||||
|
pkgRegexp = /jdk.*-/gi;
|
||||||
|
pkgTypeLength = 'jdk'.length;
|
||||||
|
} else if (javaPackage == 'jre') {
|
||||||
|
pkgRegexp = /jre.*-/gi;
|
||||||
|
pkgTypeLength = 'jre'.length;
|
||||||
|
} else if (javaPackage == 'jdk+fx') {
|
||||||
|
pkgRegexp = /fx-jdk.*-/gi;
|
||||||
|
pkgTypeLength = 'fx-jdk'.length;
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`package argument ${javaPackage} is not in [jdk | jre | jdk+fx]`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Maps version to url
|
// Maps version to url
|
||||||
let versionMap = new Map();
|
let versionMap = new Map();
|
||||||
|
|
||||||
|
@ -197,7 +216,7 @@ function getDownloadInfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we haven't returned, means we're looking at the correct platform
|
// 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) {
|
if (versions.length > 1) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`
|
`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`
|
||||||
|
@ -206,7 +225,7 @@ function getDownloadInfo(
|
||||||
if (versions.length == 0) {
|
if (versions.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const refVersion = versions[0].slice('jdk'.length, versions[0].length - 1);
|
const refVersion = versions[0].slice(pkgTypeLength, versions[0].length - 1);
|
||||||
|
|
||||||
if (semver.satisfies(refVersion, version)) {
|
if (semver.satisfies(refVersion, version)) {
|
||||||
versionMap.set(
|
versionMap.set(
|
||||||
|
@ -231,7 +250,7 @@ function getDownloadInfo(
|
||||||
|
|
||||||
if (curUrl == '') {
|
if (curUrl == '') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`No valid download found for version ${version}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`
|
`No valid download found for version ${version} and package ${javaPackage}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,9 @@ async function run() {
|
||||||
}
|
}
|
||||||
const arch = core.getInput('architecture', {required: true});
|
const arch = core.getInput('architecture', {required: true});
|
||||||
const jdkFile = core.getInput('jdkFile', {required: false}) || '';
|
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');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue