Skip to content

Commit 502a665

Browse files
Add "Contents/Home" postfix on macOS if provider creates it (#139)
* Update e2e-versions.yml * Update e2e-versions.yml * implement fix * Update e2e-versions.yml * Update installer.ts * fix filter logic * Update e2e-versions.yml * remove extra logic * Update e2e-versions.yml
1 parent 804a60f commit 502a665

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
with:
8989
java-version: ${{ matrix.version }}
9090
distribution: zulu
91+
- name: Verify Java
92+
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
93+
shell: bash
9194

9295
setup-java-ea-versions-adopt:
9396
name: adopt ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }}
@@ -107,6 +110,9 @@ jobs:
107110
with:
108111
java-version: ${{ matrix.version }}
109112
distribution: adopt
113+
- name: Verify Java
114+
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
115+
shell: bash
110116

111117
setup-java-custom-package-type:
112118
name: ${{ matrix.distribution }} ${{ matrix.version }} (${{ matrix.java-package }}-x64) - ${{ matrix.os }}

dist/setup/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,10 +3951,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
39513951
exports.JavaBase = void 0;
39523952
const tc = __importStar(__webpack_require__(139));
39533953
const core = __importStar(__webpack_require__(470));
3954+
const fs = __importStar(__webpack_require__(747));
39543955
const semver_1 = __importDefault(__webpack_require__(876));
39553956
const path_1 = __importDefault(__webpack_require__(622));
39563957
const httpm = __importStar(__webpack_require__(539));
39573958
const util_1 = __webpack_require__(322);
3959+
const constants_1 = __webpack_require__(211);
39583960
class JavaBase {
39593961
constructor(distribution, installerOptions) {
39603962
this.distribution = distribution;
@@ -3978,6 +3980,11 @@ class JavaBase {
39783980
foundJava = yield this.downloadTool(javaRelease);
39793981
core.info(`Java ${foundJava.version} was downloaded`);
39803982
}
3983+
// JDK folder may contain postfix "Contents/Home" on macOS
3984+
const macOSPostfixPath = path_1.default.join(foundJava.path, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
3985+
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
3986+
foundJava.path = macOSPostfixPath;
3987+
}
39813988
core.info(`Setting Java ${foundJava.version} as the default`);
39823989
this.setJavaDefault(foundJava.version, foundJava.path);
39833990
return foundJava;
@@ -26861,7 +26868,6 @@ const fs_1 = __importDefault(__webpack_require__(747));
2686126868
const path_1 = __importDefault(__webpack_require__(622));
2686226869
const semver_1 = __importDefault(__webpack_require__(876));
2686326870
const base_installer_1 = __webpack_require__(83);
26864-
const constants_1 = __webpack_require__(211);
2686526871
const util_1 = __webpack_require__(322);
2686626872
class AdoptDistribution extends base_installer_1.JavaBase {
2686726873
constructor(installerOptions) {
@@ -26907,9 +26913,6 @@ class AdoptDistribution extends base_installer_1.JavaBase {
2690726913
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
2690826914
const version = this.getToolcacheVersionName(javaRelease.version);
2690926915
javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
26910-
if (process.platform === 'darwin') {
26911-
javaPath = path_1.default.join(javaPath, constants_1.MACOS_JAVA_CONTENT_POSTFIX);
26912-
}
2691326916
return { version: javaRelease.version, path: javaPath };
2691426917
});
2691526918
}

src/distributions/adopt/installer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ export class AdoptDistribution extends JavaBase {
6767

6868
javaPath = await tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
6969

70-
if (process.platform === 'darwin') {
71-
javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX);
72-
}
73-
7470
return { version: javaRelease.version, path: javaPath };
7571
}
7672

src/distributions/base-installer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as tc from '@actions/tool-cache';
22
import * as core from '@actions/core';
3+
import * as fs from 'fs';
34
import semver from 'semver';
45
import path from 'path';
56
import * as httpm from '@actions/http-client';
67
import { getToolcachePath, getVersionFromToolcachePath, isVersionSatisfies } from '../util';
78
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
9+
import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants';
810

911
export abstract class JavaBase {
1012
protected http: httpm.HttpClient;
@@ -40,6 +42,12 @@ export abstract class JavaBase {
4042
core.info(`Java ${foundJava.version} was downloaded`);
4143
}
4244

45+
// JDK folder may contain postfix "Contents/Home" on macOS
46+
const macOSPostfixPath = path.join(foundJava.path, MACOS_JAVA_CONTENT_POSTFIX);
47+
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
48+
foundJava.path = macOSPostfixPath;
49+
}
50+
4351
core.info(`Setting Java ${foundJava.version} as the default`);
4452
this.setJavaDefault(foundJava.version, foundJava.path);
4553

0 commit comments

Comments
 (0)