From 654e4df6f4f34a8198b3d0c51a3f8417eb377db0 Mon Sep 17 00:00:00 2001
From: airsquared <36649395+airsquared@users.noreply.github.com>
Date: Fri, 30 Aug 2019 19:49:43 -0700
Subject: [PATCH] Add support for JDKs with JavaFX
Also changes the toolcache to 'fx-jdk' for JDKs with JavaFX and 'jdk' for JDKs without JavaFX
---
__tests__/installer.test.ts | 17 +++++++++--------
action.yml | 4 ++++
lib/installer.js | 20 +++++++++++++-------
lib/setup-java.js | 6 ++++--
src/installer.ts | 21 ++++++++++++++-------
src/setup-java.ts | 3 ++-
6 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts
index 6ac7ff8b..8c2c9812 100644
--- a/__tests__/installer.test.ts
+++ b/__tests__/installer.test.ts
@@ -52,7 +52,7 @@ describe('installer tests', () => {
}, 100000);
it('Installs version of Java from jdkFile if no matching version is installed', async () => {
- await installer.getJava('12', 'x64', javaFilePath);
+ await installer.getJava('12', 'x64', javaFilePath, false);
const JavaDir = path.join(toolDir, 'Java', '12.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@@ -62,7 +62,7 @@ describe('installer tests', () => {
it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
- await installer.getJava('1000', 'x64', 'bad path');
+ await installer.getJava('1000', 'x64', 'bad path', false);
} catch {
thrown = true;
}
@@ -70,7 +70,7 @@ describe('installer tests', () => {
});
it('Downloads java if no file given', async () => {
- await installer.getJava('8.0.102', 'x64', '');
+ await installer.getJava('8.0.102', 'x64', '', false);
const JavaDir = path.join(toolDir, 'Java', '8.0.102', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@@ -78,7 +78,7 @@ describe('installer tests', () => {
}, 100000);
it('Downloads java with 1.x syntax', async () => {
- await installer.getJava('1.10', 'x64', '');
+ await installer.getJava('1.10', 'x64', '', false);
const JavaDir = path.join(toolDir, 'Java', '10.0.2', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@@ -86,7 +86,7 @@ describe('installer tests', () => {
}, 100000);
it('Downloads java with normal semver syntax', async () => {
- await installer.getJava('9.0.x', 'x64', '');
+ await installer.getJava('9.0.x', 'x64', '', false);
const JavaDir = path.join(toolDir, 'Java', '9.0.7', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
@@ -96,7 +96,7 @@ describe('installer tests', () => {
it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
- await installer.getJava('1000', 'x64', 'bad path');
+ await installer.getJava('1000', 'x64', 'bad path', false);
} catch {
thrown = true;
}
@@ -111,7 +111,8 @@ describe('installer tests', () => {
await installer.getJava(
'250',
'x64',
- 'path shouldnt matter, found in cache'
+ 'path shouldnt matter, found in cache',
+ false
);
return;
});
@@ -122,7 +123,7 @@ describe('installer tests', () => {
let thrown = false;
try {
// This will throw if it doesn't find it in the cache (because no such version exists)
- await installer.getJava('251', 'x64', 'bad path');
+ await installer.getJava('251', 'x64', 'bad path', false);
} catch {
thrown = true;
}
diff --git a/action.yml b/action.yml
index f1081cce..c48b2333 100644
--- a/action.yml
+++ b/action.yml
@@ -12,6 +12,10 @@ inputs:
jdkFile:
description: 'Path to where the compressed JDK is located. The path could be in your source repository or a local path on the agent.'
required: false
+ javafx:
+ description: 'Whether or not to install a JDK with JavaFX. Takes either true or false.'
+ required: false
+ default: 'false'
# Deprecated option, do not use. Will not be supported after October 1, 2019
version:
description: 'Deprecated. Use java-version instead. Will not be supported after October 1, 2019'
diff --git a/lib/installer.js b/lib/installer.js
index 5f068a15..e7a832d9 100644
--- a/lib/installer.js
+++ b/lib/installer.js
@@ -1,9 +1,10 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
@@ -41,9 +42,9 @@ if (!tempDirectory) {
}
tempDirectory = path.join(baseLocation, 'actions', 'temp');
}
-function getJava(version, arch, jdkFile) {
+function getJava(version, arch, jdkFile, javafx) {
return __awaiter(this, void 0, void 0, function* () {
- let toolPath = tc.find('Java', version);
+ let toolPath = tc.find(javafx ? 'fx-jdk' : 'jdk', version);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
}
@@ -54,7 +55,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(//gi) || [];
- const downloadInfo = getDownloadInfo(refs, version);
+ const downloadInfo = getDownloadInfo(refs, version, javafx);
jdkFile = yield tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
@@ -66,7 +67,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, javafx ? 'fx-jdk' : 'jdk', getCacheVersionString(version), arch);
}
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
core.exportVariable('JAVA_HOME', toolPath);
@@ -162,7 +163,7 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
}
});
}
-function getDownloadInfo(refs, version) {
+function getDownloadInfo(refs, version, javafx) {
version = normalizeVersion(version);
let extension = '';
if (IS_WINDOWS) {
@@ -185,13 +186,18 @@ function getDownloadInfo(refs, version) {
}
// If we haven't returned, means we're looking at the correct platform
let versions = ref.match(/jdk.*-/gi) || [];
+ if (javafx) { // If getting a JDK with JavaFX, the version prefix is different
+ versions = ref.match(/ca-fx-jdk.*-/gi) || [];
+ }
if (versions.length > 1) {
throw new Error(`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`);
}
if (versions.length == 0) {
return;
}
- const refVersion = versions[0].slice('jdk'.length, versions[0].length - 1);
+ // If getting a JDK with JavaFX, the version prefix is different
+ let jdkVersionPrefix = javafx ? 'ca-fx-jdk' : 'jdk';
+ const refVersion = versions[0].slice(jdkVersionPrefix.length, versions[0].length - 1);
if (semver.satisfies(refVersion, version)) {
versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
ref.slice(''.length));
diff --git a/lib/setup-java.js b/lib/setup-java.js
index 05e231cb..922c54d4 100644
--- a/lib/setup-java.js
+++ b/lib/setup-java.js
@@ -1,9 +1,10 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
@@ -27,7 +28,8 @@ function run() {
}
const arch = core.getInput('architecture', { required: true });
const jdkFile = core.getInput('jdkFile', { required: false }) || '';
- yield installer.getJava(version, arch, jdkFile);
+ const javafx = core.getInput('javafx', { required: false }) == 'true';
+ yield installer.getJava(version, arch, jdkFile, javafx);
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
}
diff --git a/src/installer.ts b/src/installer.ts
index 646f552d..f2fd12b6 100644
--- a/src/installer.ts
+++ b/src/installer.ts
@@ -29,9 +29,10 @@ if (!tempDirectory) {
export async function getJava(
version: string,
arch: string,
- jdkFile: string
+ jdkFile: string,
+ javafx: boolean
): Promise {
- let toolPath = tc.find('Java', version);
+ let toolPath = tc.find(javafx ? 'fx-jdk' : 'jdk', version);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
@@ -45,8 +46,8 @@ export async function getJava(
)).readBody();
let refs = contents.match(//gi) || [];
- const downloadInfo = getDownloadInfo(refs, version);
-
+ const downloadInfo = getDownloadInfo(refs, version, javafx);
+
jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
@@ -66,7 +67,7 @@ export async function getJava(
core.debug(`jdk extracted to ${jdkDir}`);
toolPath = await tc.cacheDir(
jdkDir,
- 'Java',
+ javafx ? 'fx-jdk' : 'jdk',
getCacheVersionString(version),
arch
);
@@ -173,7 +174,8 @@ async function unzipJavaDownload(
function getDownloadInfo(
refs: string[],
- version: string
+ version: string,
+ javafx: boolean
): {version: string; url: string} {
version = normalizeVersion(version);
let extension = '';
@@ -198,6 +200,9 @@ function getDownloadInfo(
// If we haven't returned, means we're looking at the correct platform
let versions = ref.match(/jdk.*-/gi) || [];
+ if (javafx) { // If getting a JDK with JavaFX, the version prefix is different
+ versions = ref.match(/ca-fx-jdk.*-/gi) || [];
+ }
if (versions.length > 1) {
throw new Error(
`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`
@@ -206,7 +211,9 @@ function getDownloadInfo(
if (versions.length == 0) {
return;
}
- const refVersion = versions[0].slice('jdk'.length, versions[0].length - 1);
+ // If getting a JDK with JavaFX, the version prefix is different
+ let jdkVersionPrefix = javafx ? 'ca-fx-jdk' : 'jdk';
+ const refVersion = versions[0].slice(jdkVersionPrefix.length, versions[0].length - 1);
if (semver.satisfies(refVersion, version)) {
versionMap.set(
diff --git a/src/setup-java.ts b/src/setup-java.ts
index c5f84ba2..34315e9d 100644
--- a/src/setup-java.ts
+++ b/src/setup-java.ts
@@ -10,8 +10,9 @@ async function run() {
}
const arch = core.getInput('architecture', {required: true});
const jdkFile = core.getInput('jdkFile', {required: false}) || '';
+ const javafx = core.getInput('javafx', {required: false}) == 'true';
- await installer.getJava(version, arch, jdkFile);
+ await installer.getJava(version, arch, jdkFile, javafx);
const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);