Skip to content

Commit 5514389

Browse files
authored
Merge pull request #238 from kerner1000/feature/custom-launcher
Feature/custom launcher
2 parents 4228ce5 + 79219c9 commit 5514389

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class MacConfig implements Serializable {
3434
private String developerId = "-";
3535
private File entitlements;
3636
private File provisionProfile;
37+
private File customLauncher;
3738
private boolean codesignApp = true;
3839
private InfoPlist infoPlist = new InfoPlist();
3940
private boolean hardenedCodesign = true;
@@ -191,6 +192,14 @@ public void setDeveloperId(String developerId) {
191192
this.developerId = developerId;
192193
}
193194

195+
public File getCustomLauncher() {
196+
return customLauncher;
197+
}
198+
199+
public void setCustomLauncher(File customLauncher) {
200+
this.customLauncher = customLauncher;
201+
}
202+
194203
public File getProvisionProfile() {
195204
return provisionProfile;
196205
}

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

+23-19
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,37 @@ public File doCreateApp() throws Exception {
9393

9494
if (this.administratorRequired) {
9595

96+
// We need a helper script ("startup") in this case,
97+
// which invokes the launcher script/ executable with administrator rights.
98+
// TODO: admin script depends on launcher file name 'universalJavaApplicationStub'
99+
96100
// sets startup file
97101
this.executable = new File(macOSFolder, "startup");
98102

99103
// creates startup file to boot java app
100104
VelocityUtils.render("mac/startup.vtl", executable, this);
101-
executable.setExecutable(true, false);
102-
Logger.info("Startup script file created in " + executable.getAbsolutePath());
103-
104105
} else {
105106

106-
// sets startup file
107-
this.executable = new File(macOSFolder, "universalJavaApplicationStub");
108-
Logger.info("Using " + executable.getAbsolutePath() + " as startup script");
109-
110-
}
111-
112-
// copies universalJavaApplicationStub startup file to boot java app
113-
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
114-
String universalJavaApplicationStubResource = null;
115-
switch (macConfig.getMacStartup()) {
116-
case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break;
117-
case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break;
118-
case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break;
119-
case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break;
107+
File launcher = macConfig.getCustomLauncher();
108+
if(launcher != null && launcher.canRead() && launcher.isFile()){
109+
FileUtils.copyFileToFolder(launcher, macOSFolder);
110+
this.executable = new File(macOSFolder, launcher.getName());
111+
} else {
112+
// sets startup file
113+
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
114+
String universalJavaApplicationStubResource = null;
115+
switch (macConfig.getMacStartup()) {
116+
case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break;
117+
case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break;
118+
case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break;
119+
case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break;
120+
}
121+
FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile);
122+
this.executable = appStubFile;
123+
}
120124
}
121-
FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile);
122-
appStubFile.setExecutable(true, false);
125+
executable.setExecutable(true, false);
126+
Logger.info("Startup script file created in " + executable.getAbsolutePath());
123127

124128
// process classpath
125129
classpath = (this.macConfig.isRelocateJar() ? "Java/" : "") + this.jarFile.getName() + (classpath != null ? ":" + classpath : "");

0 commit comments

Comments
 (0)