From b082205a41fff9026de7ae32dc98a748c64f9937 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 19 Mar 2021 11:10:28 +0300 Subject: [PATCH] implement fix --- dist/setup/index.js | 25 ++++++++++++++++++++----- src/distributions/adopt/installer.ts | 4 ---- src/distributions/base-installer.ts | 8 ++++++++ src/distributions/zulu/installer.ts | 17 ++++++++++++++++- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index f102f900..288db359 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3951,10 +3951,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.JavaBase = void 0; const tc = __importStar(__webpack_require__(139)); const core = __importStar(__webpack_require__(470)); +const fs = __importStar(__webpack_require__(747)); const semver_1 = __importDefault(__webpack_require__(876)); const path_1 = __importDefault(__webpack_require__(622)); const httpm = __importStar(__webpack_require__(539)); const util_1 = __webpack_require__(322); +const constants_1 = __webpack_require__(211); class JavaBase { constructor(distribution, installerOptions) { this.distribution = distribution; @@ -3978,6 +3980,11 @@ class JavaBase { foundJava = yield this.downloadTool(javaRelease); core.info(`Java ${foundJava.version} was downloaded`); } + // JDK folder may contain postfix "Contents/Home" on macOS + const macOSPostfixPath = path_1.default.join(foundJava.path, constants_1.MACOS_JAVA_CONTENT_POSTFIX); + if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) { + foundJava.path = macOSPostfixPath; + } core.info(`Setting Java ${foundJava.version} as the default`); this.setJavaDefault(foundJava.version, foundJava.path); return foundJava; @@ -14001,7 +14008,8 @@ class ZuluDistribution extends base_installer_1.JavaBase { extractedJavaPath = yield util_1.extractJdkFile(javaArchivePath, extension); const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0]; const archivePath = path_1.default.join(extractedJavaPath, archiveName); - const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaRelease.version), this.architecture); + const jdkPath = this.findJDKInstallationSubfolder(archivePath); + const javaPath = yield tc.cacheDir(jdkPath, this.toolcacheFolderName, this.getToolcacheVersionName(javaRelease.version), this.architecture); return { version: javaRelease.version, path: javaPath }; }); } @@ -14074,6 +14082,17 @@ class ZuluDistribution extends base_installer_1.JavaBase { } return mainVersion; } + findJDKInstallationSubfolder(archiveFolder) { + // Zulu archive contains a bunch of symlinks and zulu-.jdk subfolder + const jdkFolders = fs_1.default + .readdirSync(archiveFolder, { withFileTypes: true }) + .filter(item => !item.isSymbolicLink()) + .filter(item => item.name.startsWith('zulu-') && item.name.endsWith('.jdk')); + if (jdkFolders.length === 0) { + return archiveFolder; + } + return path_1.default.join(archiveFolder, jdkFolders[0].name); + } } exports.ZuluDistribution = ZuluDistribution; @@ -26861,7 +26880,6 @@ const fs_1 = __importDefault(__webpack_require__(747)); const path_1 = __importDefault(__webpack_require__(622)); const semver_1 = __importDefault(__webpack_require__(876)); const base_installer_1 = __webpack_require__(83); -const constants_1 = __webpack_require__(211); const util_1 = __webpack_require__(322); class AdoptDistribution extends base_installer_1.JavaBase { constructor(installerOptions) { @@ -26907,9 +26925,6 @@ class AdoptDistribution extends base_installer_1.JavaBase { const archivePath = path_1.default.join(extractedJavaPath, archiveName); const version = this.getToolcacheVersionName(javaRelease.version); javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture); - if (process.platform === 'darwin') { - javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX); - } return { version: javaRelease.version, path: javaPath }; }); } diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 5b316e5d..49a01f0f 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -67,10 +67,6 @@ export class AdoptDistribution extends JavaBase { javaPath = await tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture); - if (process.platform === 'darwin') { - javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX); - } - return { version: javaRelease.version, path: javaPath }; } diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 8c4698cb..6f1312c7 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -1,10 +1,12 @@ import * as tc from '@actions/tool-cache'; import * as core from '@actions/core'; +import * as fs from 'fs'; import semver from 'semver'; import path from 'path'; import * as httpm from '@actions/http-client'; import { getToolcachePath, getVersionFromToolcachePath, isVersionSatisfies } from '../util'; import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models'; +import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants'; export abstract class JavaBase { protected http: httpm.HttpClient; @@ -40,6 +42,12 @@ export abstract class JavaBase { core.info(`Java ${foundJava.version} was downloaded`); } + // JDK folder may contain postfix "Contents/Home" on macOS + const macOSPostfixPath = path.join(foundJava.path, MACOS_JAVA_CONTENT_POSTFIX); + if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) { + foundJava.path = macOSPostfixPath; + } + core.info(`Setting Java ${foundJava.version} as the default`); this.setJavaDefault(foundJava.version, foundJava.path); diff --git a/src/distributions/zulu/installer.ts b/src/distributions/zulu/installer.ts index 7cb32704..42e2b2db 100644 --- a/src/distributions/zulu/installer.ts +++ b/src/distributions/zulu/installer.ts @@ -72,8 +72,10 @@ export class ZuluDistribution extends JavaBase { const archiveName = fs.readdirSync(extractedJavaPath)[0]; const archivePath = path.join(extractedJavaPath, archiveName); + const jdkPath = this.findJDKInstallationSubfolder(archivePath); + const javaPath = await tc.cacheDir( - archivePath, + jdkPath, this.toolcacheFolderName, this.getToolcacheVersionName(javaRelease.version), this.architecture @@ -160,4 +162,17 @@ export class ZuluDistribution extends JavaBase { return mainVersion; } + + private findJDKInstallationSubfolder(archiveFolder: string) { + // Zulu archive contains a bunch of symlinks and zulu-.jdk subfolder + const jdkFolders = fs + .readdirSync(archiveFolder, { withFileTypes: true }) + .filter(item => !item.isSymbolicLink()) + .filter(item => item.name.startsWith('zulu-') && item.name.endsWith('.jdk')); + if (jdkFolders.length === 0) { + return archiveFolder; + } + + return path.join(archiveFolder, jdkFolders[0].name); + } }