Skip to content

Commit c673b59

Browse files
fvarruiclaude
andcommitted
Fix missing macOS launcher with administratorRequired (#473, #398)
The launcher was only copied when administratorRequired was false, so the 'startup' helper script called a universalJavaApplicationStub that didn't exist. Always copy the launcher and invoke it by its real name from startup.vtl, so customLauncher also works in admin mode. The admin smoke test job is no longer allowed to fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 56a0c50 commit c673b59

5 files changed

Lines changed: 46 additions & 13 deletions

File tree

‎.github/scripts/check-macos-app.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ if [ -x "$EXE" ]; then pass "executable present: $EXE"; else fail "executable mi
2929
# launcher stub (also called by the 'startup' script when administratorRequired=true, issues #473/#398)
3030
if [ -x "$STUB" ]; then pass "launcher present: $STUB"; else fail "launcher missing: $STUB"; fi
3131

32+
# with administratorRequired=true, the 'startup' script must invoke the launcher
33+
if [ "$ADMIN" = "true" ]; then
34+
if grep -q "SCRIPTPATH/$(basename "$STUB")" "$MACOS/startup"; then pass "startup script invokes $(basename "$STUB")"; else fail "startup script doesn't invoke $(basename "$STUB")"; cat "$MACOS/startup"; fi
35+
fi
36+
3237
# compiled launchers must contain native arm64 code (issues #448/#449)
3338
if [ "$MAC_STARTUP" != "SCRIPT" ] && [ -f "$STUB" ]; then
3439
file "$STUB"

‎.github/workflows/macos-smoke.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ jobs:
1212
name: ${{ matrix.os }} / ${{ matrix.macStartup }}${{ matrix.admin && ' / admin' || '' }}
1313
runs-on: ${{ matrix.os }}
1414
timeout-minutes: 30
15-
# administratorRequired is a known failure (issues #473/#398) until fixed
16-
continue-on-error: ${{ matrix.admin }}
1715
strategy:
1816
fail-fast: false
1917
matrix:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# macOS app with administratorRequired has no launcher (#473, #398)
2+
3+
## Problem
4+
5+
With `administratorRequired=true`, the macOS app does nothing after the user enters the admin password (#398). `Contents/MacOS/universalJavaApplicationStub` is missing from the bundle (#473). Reproduced by the macOS smoke tests (run 37165552012, job `macos-15 / SCRIPT / admin`).
6+
7+
## Cause
8+
9+
`MacPackager.processStartupScript()` only copied the launcher (precompiled stub or `customLauncher`) in the non-admin branch. In admin mode it only rendered the `startup` helper script, and `mac/startup.vtl` invoked a hardcoded `universalJavaApplicationStub` that was never copied.
10+
11+
## Solution
12+
13+
- `processStartupScript()` always copies the launcher to `Contents/MacOS` and keeps it in a new `launcher` field (`getLauncher()`). In admin mode `startup` is the executable; otherwise the launcher is.
14+
- `mac/startup.vtl` invokes `$SCRIPTPATH/${info.launcher.name}` instead of the hardcoded name, so `customLauncher` also works in admin mode.
15+
- Custom `startup.vtl` templates in users' `assetsDir` keep working: the default launcher is still named `universalJavaApplicationStub`.
16+
- The smoke test checks that the `startup` script invokes an existing launcher, and the admin job no longer has `continue-on-error`.
17+
18+
## Verification
19+
20+
- macOS smoke tests: the admin job must pass (launcher present, invoked by `startup`).
21+
- Not verifiable in CI: the password prompt and the app actually starting with admin rights. #398 reporters said a similar fix (branch `issue-398`, before the native launcher) still didn't start the app. Ask them to test a snapshot before closing #398. #473 can be closed with this fix.

‎src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class MacPackager extends Packager {
3434
private File javaFolder;
3535
private File macOSFolder;
3636
private File jreBundleFolder;
37+
private File launcher;
3738

3839
public MacPackager() {
3940
super();
@@ -44,6 +45,10 @@ public File getAppFile() {
4445
return appFile;
4546
}
4647

48+
public File getLauncher() {
49+
return launcher;
50+
}
51+
4752
@Override
4853
public void doInit() throws Exception {
4954

@@ -121,12 +126,21 @@ public File doCreateApp() throws Exception {
121126
}
122127

123128
private void processStartupScript() throws Exception {
124-
129+
130+
// copies the launcher (custom or precompiled) to Contents/MacOS
131+
File customLauncher = macConfig.getCustomLauncher();
132+
if (customLauncher != null && customLauncher.canRead() && customLauncher.isFile()) {
133+
FileUtils.copyFileToFolder(customLauncher, macOSFolder);
134+
this.launcher = new File(macOSFolder, customLauncher.getName());
135+
} else {
136+
this.launcher = preparePrecompiledStartupStub();
137+
}
138+
launcher.setExecutable(true, false);
139+
125140
if (this.administratorRequired) {
126141

127142
// We need a helper script ("startup") in this case,
128-
// which invokes the launcher script/ executable with administrator rights.
129-
// TODO: admin script depends on launcher file name 'universalJavaApplicationStub'
143+
// which invokes the launcher with administrator rights.
130144

131145
// sets startup file
132146
this.executable = new File(macOSFolder, "startup");
@@ -136,13 +150,8 @@ private void processStartupScript() throws Exception {
136150

137151
} else {
138152

139-
File launcher = macConfig.getCustomLauncher();
140-
if (launcher != null && launcher.canRead() && launcher.isFile()){
141-
FileUtils.copyFileToFolder(launcher, macOSFolder);
142-
this.executable = new File(macOSFolder, launcher.getName());
143-
} else {
144-
this.executable = preparePrecompiledStartupStub();
145-
}
153+
this.executable = launcher;
154+
146155
}
147156

148157
executable.setExecutable(true, false);

‎src/main/resources/mac/startup.vtl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
# MacOS startup script generated by JavaPackager plugin
33
SCRIPTPATH=`cd "$(dirname "$0")" ; pwd`
4-
osascript -e "do shell script quoted form of \"$SCRIPTPATH\" & \"/universalJavaApplicationStub $@\" with administrator privileges" &
4+
osascript -e "do shell script quoted form of \"$SCRIPTPATH/${info.launcher.name}\" & \" $@\" with administrator privileges" &

0 commit comments

Comments
 (0)