Skip to content

Commit 191ba8c

Browse files
authored
always check postfix "Contents/Home" on macOS (actions#397)
1 parent e42168c commit 191ba8c

File tree

3 files changed

+103
-15
lines changed

3 files changed

+103
-15
lines changed

__tests__/distributors/local-installer.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,93 @@ describe('setupJava', () => {
214214
);
215215
});
216216

217+
it('java is resolved from toolcache including Contents/Home on MacOS', async () => {
218+
const inputs = {
219+
version: actualJavaVersion,
220+
architecture: 'x86',
221+
packageType: 'jdk',
222+
checkLatest: false
223+
};
224+
const jdkFile = 'not_existing_one';
225+
const expected = {
226+
version: actualJavaVersion,
227+
path: path.join(
228+
'Java_jdkfile_jdk',
229+
inputs.version,
230+
inputs.architecture,
231+
'Contents',
232+
'Home'
233+
)
234+
};
235+
const originalPlatform = process.platform;
236+
Object.defineProperty(process, 'platform', {
237+
value: 'darwin'
238+
});
239+
240+
spyFsStat = jest.spyOn(fs, 'existsSync');
241+
spyFsStat.mockImplementation((file: string) => {
242+
return file.endsWith('Home');
243+
});
244+
245+
mockJavaBase = new LocalDistribution(inputs, jdkFile);
246+
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
247+
expect(spyGetToolcachePath).toHaveBeenCalled();
248+
expect(spyCoreInfo).toHaveBeenCalledWith(
249+
`Resolved Java ${actualJavaVersion} from tool-cache`
250+
);
251+
expect(spyCoreInfo).not.toHaveBeenCalledWith(
252+
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
253+
);
254+
255+
Object.defineProperty(process, 'platform', {
256+
value: originalPlatform
257+
});
258+
});
259+
260+
it('java is unpacked from jdkfile including Contents/Home on MacOS', async () => {
261+
const inputs = {
262+
version: '11.0.289',
263+
architecture: 'x86',
264+
packageType: 'jdk',
265+
checkLatest: false
266+
};
267+
const jdkFile = expectedJdkFile;
268+
const expected = {
269+
version: '11.0.289',
270+
path: path.join(
271+
'Java_jdkfile_jdk',
272+
inputs.version,
273+
inputs.architecture,
274+
'Contents',
275+
'Home'
276+
)
277+
};
278+
const originalPlatform = process.platform;
279+
Object.defineProperty(process, 'platform', {
280+
value: 'darwin'
281+
});
282+
spyFsStat = jest.spyOn(fs, 'existsSync');
283+
spyFsStat.mockImplementation((file: string) => {
284+
return file.endsWith('Home');
285+
});
286+
287+
mockJavaBase = new LocalDistribution(inputs, jdkFile);
288+
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
289+
expect(spyTcFindAllVersions).toHaveBeenCalled();
290+
expect(spyCoreInfo).not.toHaveBeenCalledWith(
291+
`Resolved Java ${actualJavaVersion} from tool-cache`
292+
);
293+
expect(spyCoreInfo).toHaveBeenCalledWith(
294+
`Extracting Java from '${jdkFile}'`
295+
);
296+
expect(spyCoreInfo).toHaveBeenCalledWith(
297+
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
298+
);
299+
Object.defineProperty(process, 'platform', {
300+
value: originalPlatform
301+
});
302+
});
303+
217304
it.each([
218305
[
219306
{

dist/setup/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104608,17 +104608,17 @@ class LocalDistribution extends base_installer_1.JavaBase {
104608104608
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
104609104609
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
104610104610
const javaVersion = this.version;
104611-
let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture);
104612-
// for different Java distributions, postfix can exist or not so need to check both cases
104613-
if (process.platform === 'darwin' &&
104614-
fs_1.default.existsSync(path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX))) {
104615-
javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
104616-
}
104611+
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture);
104617104612
foundJava = {
104618104613
version: javaVersion,
104619104614
path: javaPath
104620104615
};
104621104616
}
104617+
// JDK folder may contain postfix "Contents/Home" on macOS
104618+
const macOSPostfixPath = path_1.default.join(foundJava.path, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
104619+
if (process.platform === 'darwin' && fs_1.default.existsSync(macOSPostfixPath)) {
104620+
foundJava.path = macOSPostfixPath;
104621+
}
104622104622
core.info(`Setting Java ${foundJava.version} as default`);
104623104623
this.setJavaDefault(foundJava.version, foundJava.path);
104624104624
return foundJava;

src/distributions/local/installer.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,28 @@ export class LocalDistribution extends JavaBase {
4747
const archivePath = path.join(extractedJavaPath, archiveName);
4848
const javaVersion = this.version;
4949

50-
let javaPath = await tc.cacheDir(
50+
const javaPath = await tc.cacheDir(
5151
archivePath,
5252
this.toolcacheFolderName,
5353
this.getToolcacheVersionName(javaVersion),
5454
this.architecture
5555
);
5656

57-
// for different Java distributions, postfix can exist or not so need to check both cases
58-
if (
59-
process.platform === 'darwin' &&
60-
fs.existsSync(path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX))
61-
) {
62-
javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX);
63-
}
64-
6557
foundJava = {
6658
version: javaVersion,
6759
path: javaPath
6860
};
6961
}
7062

63+
// JDK folder may contain postfix "Contents/Home" on macOS
64+
const macOSPostfixPath = path.join(
65+
foundJava.path,
66+
MACOS_JAVA_CONTENT_POSTFIX
67+
);
68+
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
69+
foundJava.path = macOSPostfixPath;
70+
}
71+
7172
core.info(`Setting Java ${foundJava.version} as default`);
7273

7374
this.setJavaDefault(foundJava.version, foundJava.path);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy