diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml
index 45b8626..805d411 100644
--- a/.github/workflows/workflow.yml
+++ b/.github/workflows/workflow.yml
@@ -9,12 +9,12 @@ jobs:
operating-system: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
- uses: actions/checkout@master
+ uses: actions/checkout@v2
- - name: Set Node.js 10.x
- uses: actions/setup-node@master
+ - name: Setup Node.js 12.x
+ uses: actions/setup-node@v1
with:
- node-version: 10.x
+ node-version: 12.x
- name: npm install
run: npm install
@@ -40,12 +40,12 @@ jobs:
run: |
echo "127.0.0.0 registry.npm.js nodejs.org github.com api.github.com download.java.net static.azul.com" | sudo tee -a /etc/hosts
- name: Checkout
- uses: actions/checkout@master
+ uses: actions/checkout@v2
- - name: Set Node.js 10.x
- uses: actions/setup-node@master
+ - name: Setup Node.js 12.x
+ uses: actions/setup-node@v1
with:
- node-version: 10.x
+ node-version: 12.x
- name: npm install
run: npm install
diff --git a/dist/index.js b/dist/index.js
index 12c71d3..9663265 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -2856,84 +2856,84 @@ function coerce (version, options) {
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"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) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
-};
-var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
- result["default"] = mod;
- return result;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-const fs = __importStar(__webpack_require__(747));
-const os = __importStar(__webpack_require__(87));
-const path = __importStar(__webpack_require__(622));
-const core = __importStar(__webpack_require__(470));
-const io = __importStar(__webpack_require__(1));
-exports.M2_DIR = '.m2';
-exports.SETTINGS_FILE = 'settings.xml';
-exports.DEFAULT_ID = 'github';
-exports.DEFAULT_USERNAME = 'GITHUB_ACTOR';
-exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN';
-function configAuthentication(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
- return __awaiter(this, void 0, void 0, function* () {
- console.log(`creating ${exports.SETTINGS_FILE} with server-id: ${id};`, `environment variables: username=\$${username} and password=\$${password}`);
- // when an alternate m2 location is specified use only that location (no .m2 directory)
- // otherwise use the home/.m2/ path
- const directory = path.join(core.getInput('settings-path') || os.homedir(), core.getInput('settings-path') ? '' : exports.M2_DIR);
- yield io.mkdirP(directory);
- core.debug(`created directory ${directory}`);
- yield write(directory, generate(id, username, password));
- });
-}
-exports.configAuthentication = configAuthentication;
-function escapeXML(value) {
- return value
- .replace(/&/g, '&')
- .replace(//g, '>')
- .replace(/"/g, '"')
- .replace(/'/g, ''');
-}
-// only exported for testing purposes
-function generate(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
- return `
-
-
-
- ${escapeXML(id)}
- \${env.${escapeXML(username)}}
- \${env.${escapeXML(password)}}
-
-
-
- `;
-}
-exports.generate = generate;
-function write(directory, settings) {
- return __awaiter(this, void 0, void 0, function* () {
- const location = path.join(directory, exports.SETTINGS_FILE);
- if (fs.existsSync(location)) {
- console.warn(`overwriting existing file ${location}`);
- }
- else {
- console.log(`writing ${location}`);
- }
- return fs.writeFileSync(location, settings, {
- encoding: 'utf-8',
- flag: 'w'
- });
- });
-}
+
+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) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+ result["default"] = mod;
+ return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const fs = __importStar(__webpack_require__(747));
+const os = __importStar(__webpack_require__(87));
+const path = __importStar(__webpack_require__(622));
+const core = __importStar(__webpack_require__(470));
+const io = __importStar(__webpack_require__(1));
+exports.M2_DIR = '.m2';
+exports.SETTINGS_FILE = 'settings.xml';
+exports.DEFAULT_ID = 'github';
+exports.DEFAULT_USERNAME = 'GITHUB_ACTOR';
+exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN';
+function configAuthentication(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
+ return __awaiter(this, void 0, void 0, function* () {
+ console.log(`creating ${exports.SETTINGS_FILE} with server-id: ${id};`, `environment variables: username=\$${username} and password=\$${password}`);
+ // when an alternate m2 location is specified use only that location (no .m2 directory)
+ // otherwise use the home/.m2/ path
+ const directory = path.join(core.getInput('settings-path') || os.homedir(), core.getInput('settings-path') ? '' : exports.M2_DIR);
+ yield io.mkdirP(directory);
+ core.debug(`created directory ${directory}`);
+ yield write(directory, generate(id, username, password));
+ });
+}
+exports.configAuthentication = configAuthentication;
+function escapeXML(value) {
+ return value
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+}
+// only exported for testing purposes
+function generate(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
+ return `
+
+
+
+ ${escapeXML(id)}
+ \${env.${escapeXML(username)}}
+ \${env.${escapeXML(password)}}
+
+
+
+ `;
+}
+exports.generate = generate;
+function write(directory, settings) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const location = path.join(directory, exports.SETTINGS_FILE);
+ if (fs.existsSync(location)) {
+ console.warn(`overwriting existing file ${location}`);
+ }
+ else {
+ console.log(`writing ${location}`);
+ }
+ return fs.writeFileSync(location, settings, {
+ encoding: 'utf-8',
+ flag: 'w'
+ });
+ });
+}
/***/ }),
@@ -4525,52 +4525,52 @@ module.exports = require("fs");
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"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) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
-};
-var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
- result["default"] = mod;
- return result;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-const core = __importStar(__webpack_require__(470));
-const installer = __importStar(__webpack_require__(923));
-const auth = __importStar(__webpack_require__(331));
-const path = __importStar(__webpack_require__(622));
-function run() {
- return __awaiter(this, void 0, void 0, function* () {
- try {
- let version = core.getInput('version');
- if (!version) {
- version = core.getInput('java-version', { required: true });
- }
- const arch = core.getInput('architecture', { required: true });
- const javaPackage = core.getInput('java-package', { required: true });
- const jdkFile = core.getInput('jdkFile', { required: false }) || '';
- yield installer.getJava(version, arch, jdkFile, javaPackage);
- const matchersPath = path.join(__dirname, '..', '.github');
- console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
- const id = core.getInput('server-id', { required: false }) || undefined;
- const username = core.getInput('server-username', { required: false }) || undefined;
- const password = core.getInput('server-password', { required: false }) || undefined;
- yield auth.configAuthentication(id, username, password);
- }
- catch (error) {
- core.setFailed(error.message);
- }
- });
-}
-run();
+
+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) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+ result["default"] = mod;
+ return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const core = __importStar(__webpack_require__(470));
+const installer = __importStar(__webpack_require__(923));
+const auth = __importStar(__webpack_require__(331));
+const path = __importStar(__webpack_require__(622));
+function run() {
+ return __awaiter(this, void 0, void 0, function* () {
+ try {
+ let version = core.getInput('version');
+ if (!version) {
+ version = core.getInput('java-version', { required: true });
+ }
+ const arch = core.getInput('architecture', { required: true });
+ const javaPackage = core.getInput('java-package', { required: true });
+ const jdkFile = core.getInput('jdkFile', { required: false }) || '';
+ yield installer.getJava(version, arch, jdkFile, javaPackage);
+ const matchersPath = path.join(__dirname, '..', '.github');
+ console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
+ const id = core.getInput('server-id', { required: false }) || undefined;
+ const username = core.getInput('server-username', { required: false }) || undefined;
+ const password = core.getInput('server-password', { required: false }) || undefined;
+ yield auth.configAuthentication(id, username, password);
+ }
+ catch (error) {
+ core.setFailed(error.message);
+ }
+ });
+}
+run();
/***/ }),
@@ -4622,265 +4622,282 @@ module.exports = require("url");
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"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) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
-};
-var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
- result["default"] = mod;
- return result;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-let tempDirectory = process.env['RUNNER_TEMP'] || '';
-const core = __importStar(__webpack_require__(470));
-const io = __importStar(__webpack_require__(1));
-const exec = __importStar(__webpack_require__(986));
-const tc = __importStar(__webpack_require__(533));
-const fs = __importStar(__webpack_require__(747));
-const path = __importStar(__webpack_require__(622));
-const semver = __importStar(__webpack_require__(280));
-const httpm = __importStar(__webpack_require__(539));
-const IS_WINDOWS = process.platform === 'win32';
-if (!tempDirectory) {
- let baseLocation;
- if (IS_WINDOWS) {
- // On windows use the USERPROFILE env variable
- baseLocation = process.env['USERPROFILE'] || 'C:\\';
- }
- else {
- if (process.platform === 'darwin') {
- baseLocation = '/Users';
- }
- else {
- baseLocation = '/home';
- }
- }
- tempDirectory = path.join(baseLocation, 'actions', 'temp');
-}
-function getJava(version, arch, jdkFile, javaPackage) {
- return __awaiter(this, void 0, void 0, function* () {
- let toolPath = tc.find(javaPackage, version);
- if (toolPath) {
- core.debug(`Tool found in cache ${toolPath}`);
- }
- else {
- let compressedFileExtension = '';
- if (!jdkFile) {
- core.debug('Downloading Jdk from Azul');
- 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, javaPackage);
- jdkFile = yield tc.downloadTool(downloadInfo.url);
- version = downloadInfo.version;
- compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
- }
- else {
- core.debug('Retrieving Jdk from local path');
- }
- compressedFileExtension = compressedFileExtension || getFileEnding(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, javaPackage, getCacheVersionString(version), arch);
- }
- let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
- core.exportVariable('JAVA_HOME', toolPath);
- core.exportVariable(extendedJavaHome, toolPath);
- core.addPath(path.join(toolPath, 'bin'));
- });
-}
-exports.getJava = getJava;
-function getCacheVersionString(version) {
- const versionArray = version.split('.');
- const major = versionArray[0];
- const minor = versionArray.length > 1 ? versionArray[1] : '0';
- const patch = versionArray.length > 2 ? versionArray[2] : '0';
- return `${major}.${minor}.${patch}`;
-}
-function getFileEnding(file) {
- let fileEnding = '';
- if (file.endsWith('.tar')) {
- fileEnding = '.tar';
- }
- else if (file.endsWith('.tar.gz')) {
- fileEnding = '.tar.gz';
- }
- else if (file.endsWith('.zip')) {
- fileEnding = '.zip';
- }
- else if (file.endsWith('.7z')) {
- fileEnding = '.7z';
- }
- else {
- throw new Error(`${file} has an unsupported file extension`);
- }
- return fileEnding;
-}
-function extractFiles(file, fileEnding, destinationFolder) {
- return __awaiter(this, void 0, void 0, function* () {
- const stats = fs.statSync(file);
- if (!stats) {
- throw new Error(`Failed to extract ${file} - it doesn't exist`);
- }
- else if (stats.isDirectory()) {
- throw new Error(`Failed to extract ${file} - it is a directory`);
- }
- if ('.tar' === fileEnding || '.tar.gz' === fileEnding) {
- yield tc.extractTar(file, destinationFolder);
- }
- else if ('.zip' === fileEnding) {
- yield tc.extractZip(file, destinationFolder);
- }
- else {
- // fall through and use sevenZip
- yield tc.extract7z(file, destinationFolder);
- }
- });
-}
-// This method recursively finds all .pack files under fsPath and unpacks them with the unpack200 tool
-function unpackJars(fsPath, javaBinPath) {
- return __awaiter(this, void 0, void 0, function* () {
- if (fs.existsSync(fsPath)) {
- if (fs.lstatSync(fsPath).isDirectory()) {
- for (const file in fs.readdirSync(fsPath)) {
- const curPath = path.join(fsPath, file);
- yield unpackJars(curPath, javaBinPath);
- }
- }
- else if (path.extname(fsPath).toLowerCase() === '.pack') {
- // Unpack the pack file synchonously
- const p = path.parse(fsPath);
- const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200';
- const args = IS_WINDOWS ? '-r -v -l ""' : '';
- const name = path.join(p.dir, p.name);
- yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [
- `${args} "${name}.pack" "${name}.jar"`
- ]);
- }
- }
- });
-}
-function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
- return __awaiter(this, void 0, void 0, function* () {
- // Create the destination folder if it doesn't exist
- yield io.mkdirP(destinationFolder);
- const jdkFile = path.normalize(repoRoot);
- const stats = fs.statSync(jdkFile);
- if (stats.isFile()) {
- yield extractFiles(jdkFile, fileEnding, destinationFolder);
- const jdkDirectory = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]);
- yield unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin'));
- return jdkDirectory;
- }
- else {
- throw new Error(`Jdk argument ${jdkFile} is not a file`);
- }
- });
-}
-function getDownloadInfo(refs, version, javaPackage) {
- version = normalizeVersion(version);
- let extension = '';
- if (IS_WINDOWS) {
- extension = `-win_x64.zip`;
- }
- else {
- if (process.platform === 'darwin') {
- extension = `-macosx_x64.tar.gz`;
- }
- else {
- 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
- let versionMap = new Map();
- // Filter by platform
- refs.forEach(ref => {
- if (!ref.endsWith(extension + '">')) {
- return;
- }
- // If we haven't returned, means we're looking at the correct platform
- let versions = ref.match(pkgRegexp) || [];
- 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(pkgTypeLength, versions[0].length - 1);
- if (semver.satisfies(refVersion, version)) {
- versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
- ref.slice(''.length));
- }
- });
- // Choose the most recent satisfying version
- let curVersion = '0.0.0';
- let curUrl = '';
- for (const entry of versionMap.entries()) {
- const entryVersion = entry[0];
- const entryUrl = entry[1];
- if (semver.gt(entryVersion, curVersion)) {
- curUrl = entryUrl;
- curVersion = entryVersion;
- }
- }
- if (curUrl == '') {
- 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 };
-}
-function normalizeVersion(version) {
- if (version.slice(0, 2) === '1.') {
- // Trim leading 1. for versions like 1.8
- version = version.slice(2);
- if (!version) {
- throw new Error('1. is not a valid version');
- }
- }
- if (version.endsWith('-ea')) {
- // convert e.g. 14-ea to 14.0.0-ea
- if (version.indexOf('.') == -1) {
- version = version.slice(0, version.length - 3) + '.0.0-ea';
- }
- // match anything in -ea.X (semver won't do .x matching on pre-release versions)
- if (version[0] >= '0' && version[0] <= '9') {
- version = '>=' + version;
- }
- }
- else if (version.split('.').length < 3) {
- // For non-ea versions, add trailing .x if it is missing
- if (version[version.length - 1] != 'x') {
- version = version + '.x';
- }
- }
- return version;
-}
+
+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) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+ result["default"] = mod;
+ return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+let tempDirectory = process.env['RUNNER_TEMP'] || '';
+const core = __importStar(__webpack_require__(470));
+const io = __importStar(__webpack_require__(1));
+const exec = __importStar(__webpack_require__(986));
+const httpm = __importStar(__webpack_require__(539));
+const tc = __importStar(__webpack_require__(533));
+const fs = __importStar(__webpack_require__(747));
+const path = __importStar(__webpack_require__(622));
+const semver = __importStar(__webpack_require__(280));
+const IS_WINDOWS = process.platform === 'win32';
+if (!tempDirectory) {
+ let baseLocation;
+ if (IS_WINDOWS) {
+ // On windows use the USERPROFILE env variable
+ baseLocation = process.env['USERPROFILE'] || 'C:\\';
+ }
+ else {
+ if (process.platform === 'darwin') {
+ baseLocation = '/Users';
+ }
+ else {
+ baseLocation = '/home';
+ }
+ }
+ tempDirectory = path.join(baseLocation, 'actions', 'temp');
+}
+function getJava(version, arch, jdkFile, javaPackage) {
+ return __awaiter(this, void 0, void 0, function* () {
+ let toolPath = tc.find(javaPackage, version);
+ if (toolPath) {
+ core.debug(`Tool found in cache ${toolPath}`);
+ }
+ else {
+ let compressedFileExtension = '';
+ if (!jdkFile) {
+ 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 = yield http.get(url);
+ const statusCode = response.message.statusCode || 0;
+ if (statusCode < 200 || statusCode > 299) {
+ let body = '';
+ try {
+ body = yield 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 = yield response.readBody();
+ const refs = contents.match(//gi) || [];
+ const downloadInfo = getDownloadInfo(refs, version, javaPackage);
+ jdkFile = yield tc.downloadTool(downloadInfo.url);
+ version = downloadInfo.version;
+ compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
+ }
+ else {
+ core.debug('Retrieving Jdk from local path');
+ }
+ compressedFileExtension = compressedFileExtension || getFileEnding(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, javaPackage, getCacheVersionString(version), arch);
+ }
+ let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
+ core.exportVariable('JAVA_HOME', toolPath);
+ core.exportVariable(extendedJavaHome, toolPath);
+ core.addPath(path.join(toolPath, 'bin'));
+ });
+}
+exports.getJava = getJava;
+function getCacheVersionString(version) {
+ const versionArray = version.split('.');
+ const major = versionArray[0];
+ const minor = versionArray.length > 1 ? versionArray[1] : '0';
+ const patch = versionArray.length > 2 ? versionArray[2] : '0';
+ return `${major}.${minor}.${patch}`;
+}
+function getFileEnding(file) {
+ let fileEnding = '';
+ if (file.endsWith('.tar')) {
+ fileEnding = '.tar';
+ }
+ else if (file.endsWith('.tar.gz')) {
+ fileEnding = '.tar.gz';
+ }
+ else if (file.endsWith('.zip')) {
+ fileEnding = '.zip';
+ }
+ else if (file.endsWith('.7z')) {
+ fileEnding = '.7z';
+ }
+ else {
+ throw new Error(`${file} has an unsupported file extension`);
+ }
+ return fileEnding;
+}
+function extractFiles(file, fileEnding, destinationFolder) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const stats = fs.statSync(file);
+ if (!stats) {
+ throw new Error(`Failed to extract ${file} - it doesn't exist`);
+ }
+ else if (stats.isDirectory()) {
+ throw new Error(`Failed to extract ${file} - it is a directory`);
+ }
+ if ('.tar' === fileEnding || '.tar.gz' === fileEnding) {
+ yield tc.extractTar(file, destinationFolder);
+ }
+ else if ('.zip' === fileEnding) {
+ yield tc.extractZip(file, destinationFolder);
+ }
+ else {
+ // fall through and use sevenZip
+ yield tc.extract7z(file, destinationFolder);
+ }
+ });
+}
+// This method recursively finds all .pack files under fsPath and unpacks them with the unpack200 tool
+function unpackJars(fsPath, javaBinPath) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (fs.existsSync(fsPath)) {
+ if (fs.lstatSync(fsPath).isDirectory()) {
+ for (const file in fs.readdirSync(fsPath)) {
+ const curPath = path.join(fsPath, file);
+ yield unpackJars(curPath, javaBinPath);
+ }
+ }
+ else if (path.extname(fsPath).toLowerCase() === '.pack') {
+ // Unpack the pack file synchonously
+ const p = path.parse(fsPath);
+ const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200';
+ const args = IS_WINDOWS ? '-r -v -l ""' : '';
+ const name = path.join(p.dir, p.name);
+ yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [
+ `${args} "${name}.pack" "${name}.jar"`
+ ]);
+ }
+ }
+ });
+}
+function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
+ return __awaiter(this, void 0, void 0, function* () {
+ // Create the destination folder if it doesn't exist
+ yield io.mkdirP(destinationFolder);
+ const jdkFile = path.normalize(repoRoot);
+ const stats = fs.statSync(jdkFile);
+ if (stats.isFile()) {
+ yield extractFiles(jdkFile, fileEnding, destinationFolder);
+ const jdkDirectory = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]);
+ yield unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin'));
+ return jdkDirectory;
+ }
+ else {
+ throw new Error(`Jdk argument ${jdkFile} is not a file`);
+ }
+ });
+}
+function getDownloadInfo(refs, version, javaPackage) {
+ version = normalizeVersion(version);
+ let extension = '';
+ if (IS_WINDOWS) {
+ extension = `-win_x64.zip`;
+ }
+ else {
+ if (process.platform === 'darwin') {
+ extension = `-macosx_x64.tar.gz`;
+ }
+ else {
+ 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
+ let versionMap = new Map();
+ // Filter by platform
+ refs.forEach(ref => {
+ if (!ref.endsWith(extension + '">')) {
+ return;
+ }
+ // If we haven't returned, means we're looking at the correct platform
+ let versions = ref.match(pkgRegexp) || [];
+ 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(pkgTypeLength, versions[0].length - 1);
+ if (semver.satisfies(refVersion, version)) {
+ versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
+ ref.slice(''.length));
+ }
+ });
+ // Choose the most recent satisfying version
+ let curVersion = '0.0.0';
+ let curUrl = '';
+ for (const entry of versionMap.entries()) {
+ const entryVersion = entry[0];
+ const entryUrl = entry[1];
+ if (semver.gt(entryVersion, curVersion)) {
+ curUrl = entryUrl;
+ curVersion = entryVersion;
+ }
+ }
+ if (curUrl == '') {
+ 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 };
+}
+function normalizeVersion(version) {
+ if (version.slice(0, 2) === '1.') {
+ // Trim leading 1. for versions like 1.8
+ version = version.slice(2);
+ if (!version) {
+ throw new Error('1. is not a valid version');
+ }
+ }
+ if (version.endsWith('-ea')) {
+ // convert e.g. 14-ea to 14.0.0-ea
+ if (version.indexOf('.') == -1) {
+ version = version.slice(0, version.length - 3) + '.0.0-ea';
+ }
+ // match anything in -ea.X (semver won't do .x matching on pre-release versions)
+ if (version[0] >= '0' && version[0] <= '9') {
+ version = '>=' + version;
+ }
+ }
+ else if (version.split('.').length < 3) {
+ // For non-ea versions, add trailing .x if it is missing
+ if (version[version.length - 1] != 'x') {
+ version = version + '.x';
+ }
+ }
+ return version;
+}
/***/ }),
diff --git a/src/installer.ts b/src/installer.ts
index 9cc16a5..cce8fa3 100644
--- a/src/installer.ts
+++ b/src/installer.ts
@@ -39,15 +39,28 @@ export async function getJava(
} else {
let compressedFileExtension = '';
if (!jdkFile) {
- core.debug('Downloading Jdk from Azul');
- let http: httpm.HttpClient = new httpm.HttpClient('setup-java');
- let contents = await (
- await http.get('https://static.azul.com/zulu/bin/')
- ).readBody();
- let refs = contents.match(//gi) || [];
+ 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(//gi) || [];
const downloadInfo = getDownloadInfo(refs, version, javaPackage);
-
jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';