Loading __tests__/distributors/local-installer.test.ts +87 Changes for __tests__/distributors/local-installer.test.ts: 87 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -214,6 +214,93 @@ describe('setupJava', () => { ); }); it('java is resolved from toolcache including Contents/Home on MacOS', async () => { const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk', checkLatest: false }; const jdkFile = 'not_existing_one'; const expected = { version: actualJavaVersion, path: path.join( 'Java_jdkfile_jdk', inputs.version, inputs.architecture, 'Contents', 'Home' ) }; const originalPlatform = process.platform; Object.defineProperty(process, 'platform', { value: 'darwin' }); spyFsStat = jest.spyOn(fs, 'existsSync'); spyFsStat.mockImplementation((file: string) => { return file.endsWith('Home'); }); mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyCoreInfo).toHaveBeenCalledWith( `Resolved Java ${actualJavaVersion} from tool-cache` ); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` ); Object.defineProperty(process, 'platform', { value: originalPlatform }); }); it('java is unpacked from jdkfile including Contents/Home on MacOS', async () => { const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk', checkLatest: false }; const jdkFile = expectedJdkFile; const expected = { version: '11.0.289', path: path.join( 'Java_jdkfile_jdk', inputs.version, inputs.architecture, 'Contents', 'Home' ) }; const originalPlatform = process.platform; Object.defineProperty(process, 'platform', { value: 'darwin' }); spyFsStat = jest.spyOn(fs, 'existsSync'); spyFsStat.mockImplementation((file: string) => { return file.endsWith('Home'); }); mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); expect(spyTcFindAllVersions).toHaveBeenCalled(); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Resolved Java ${actualJavaVersion} from tool-cache` ); expect(spyCoreInfo).toHaveBeenCalledWith( `Extracting Java from '${jdkFile}'` ); expect(spyCoreInfo).toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` ); Object.defineProperty(process, 'platform', { value: originalPlatform }); }); it.each([ [ { Loading dist/setup/index.js +6 −6 Changes for dist/setup/index.js: 6 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -104608,17 +104608,17 @@ class LocalDistribution extends base_installer_1.JavaBase { const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0]; const archivePath = path_1.default.join(extractedJavaPath, archiveName); const javaVersion = this.version; let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); // for different Java distributions, postfix can exist or not so need to check both cases if (process.platform === 'darwin' && fs_1.default.existsSync(path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX))) { javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX); } const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); foundJava = { version: javaVersion, path: javaPath }; } // 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_1.default.existsSync(macOSPostfixPath)) { foundJava.path = macOSPostfixPath; } core.info(`Setting Java ${foundJava.version} as default`); this.setJavaDefault(foundJava.version, foundJava.path); return foundJava; src/distributions/local/installer.ts +10 −9 Changes for src/distributions/local/installer.ts: 10 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -47,27 +47,28 @@ export class LocalDistribution extends JavaBase { const archivePath = path.join(extractedJavaPath, archiveName); const javaVersion = this.version; let javaPath = await tc.cacheDir( const javaPath = await tc.cacheDir( archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture ); // for different Java distributions, postfix can exist or not so need to check both cases if ( process.platform === 'darwin' && fs.existsSync(path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX)) ) { javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX); } foundJava = { version: javaVersion, path: javaPath }; } // 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 default`); this.setJavaDefault(foundJava.version, foundJava.path); Loading Loading
__tests__/distributors/local-installer.test.ts +87 Changes for __tests__/distributors/local-installer.test.ts: 87 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -214,6 +214,93 @@ describe('setupJava', () => { ); }); it('java is resolved from toolcache including Contents/Home on MacOS', async () => { const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk', checkLatest: false }; const jdkFile = 'not_existing_one'; const expected = { version: actualJavaVersion, path: path.join( 'Java_jdkfile_jdk', inputs.version, inputs.architecture, 'Contents', 'Home' ) }; const originalPlatform = process.platform; Object.defineProperty(process, 'platform', { value: 'darwin' }); spyFsStat = jest.spyOn(fs, 'existsSync'); spyFsStat.mockImplementation((file: string) => { return file.endsWith('Home'); }); mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyCoreInfo).toHaveBeenCalledWith( `Resolved Java ${actualJavaVersion} from tool-cache` ); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` ); Object.defineProperty(process, 'platform', { value: originalPlatform }); }); it('java is unpacked from jdkfile including Contents/Home on MacOS', async () => { const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk', checkLatest: false }; const jdkFile = expectedJdkFile; const expected = { version: '11.0.289', path: path.join( 'Java_jdkfile_jdk', inputs.version, inputs.architecture, 'Contents', 'Home' ) }; const originalPlatform = process.platform; Object.defineProperty(process, 'platform', { value: 'darwin' }); spyFsStat = jest.spyOn(fs, 'existsSync'); spyFsStat.mockImplementation((file: string) => { return file.endsWith('Home'); }); mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); expect(spyTcFindAllVersions).toHaveBeenCalled(); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Resolved Java ${actualJavaVersion} from tool-cache` ); expect(spyCoreInfo).toHaveBeenCalledWith( `Extracting Java from '${jdkFile}'` ); expect(spyCoreInfo).toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` ); Object.defineProperty(process, 'platform', { value: originalPlatform }); }); it.each([ [ { Loading
dist/setup/index.js +6 −6 Changes for dist/setup/index.js: 6 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -104608,17 +104608,17 @@ class LocalDistribution extends base_installer_1.JavaBase { const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0]; const archivePath = path_1.default.join(extractedJavaPath, archiveName); const javaVersion = this.version; let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); // for different Java distributions, postfix can exist or not so need to check both cases if (process.platform === 'darwin' && fs_1.default.existsSync(path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX))) { javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX); } const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); foundJava = { version: javaVersion, path: javaPath }; } // 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_1.default.existsSync(macOSPostfixPath)) { foundJava.path = macOSPostfixPath; } core.info(`Setting Java ${foundJava.version} as default`); this.setJavaDefault(foundJava.version, foundJava.path); return foundJava;
src/distributions/local/installer.ts +10 −9 Changes for src/distributions/local/installer.ts: 10 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -47,27 +47,28 @@ export class LocalDistribution extends JavaBase { const archivePath = path.join(extractedJavaPath, archiveName); const javaVersion = this.version; let javaPath = await tc.cacheDir( const javaPath = await tc.cacheDir( archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture ); // for different Java distributions, postfix can exist or not so need to check both cases if ( process.platform === 'darwin' && fs.existsSync(path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX)) ) { javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX); } foundJava = { version: javaVersion, path: javaPath }; } // 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 default`); this.setJavaDefault(foundJava.version, foundJava.path); Loading