From 2e6f934c20a59a06d089ad69b7545e87da650c83 Mon Sep 17 00:00:00 2001 From: Alexander Kerner Date: Fri, 22 Jul 2022 23:25:32 +0200 Subject: [PATCH 1/2] Add custom launcher file property --- .../io/github/fvarrui/javapackager/model/MacConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java b/src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java index 6d961be6..027d979c 100644 --- a/src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java +++ b/src/main/java/io/github/fvarrui/javapackager/model/MacConfig.java @@ -34,6 +34,7 @@ public class MacConfig implements Serializable { private String developerId = "-"; private File entitlements; private File provisionProfile; + private File customLauncher; private boolean codesignApp = true; private InfoPlist infoPlist = new InfoPlist(); private boolean hardenedCodesign = true; @@ -191,6 +192,14 @@ public void setDeveloperId(String developerId) { this.developerId = developerId; } + public File getCustomLauncher() { + return customLauncher; + } + + public void setCustomLauncher(File customLauncher) { + this.customLauncher = customLauncher; + } + public File getProvisionProfile() { return provisionProfile; } From 79219c97d3430c633b208d050e4438a15782649f Mon Sep 17 00:00:00 2001 From: Alexander Kerner Date: Sat, 23 Jul 2022 20:04:03 +0200 Subject: [PATCH 2/2] Support custom app launcher --- .../javapackager/packagers/MacPackager.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java b/src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java index d1729d33..2cc8d373 100644 --- a/src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java +++ b/src/main/java/io/github/fvarrui/javapackager/packagers/MacPackager.java @@ -93,33 +93,37 @@ public File doCreateApp() throws Exception { if (this.administratorRequired) { + // We need a helper script ("startup") in this case, + // which invokes the launcher script/ executable with administrator rights. + // TODO: admin script depends on launcher file name 'universalJavaApplicationStub' + // sets startup file this.executable = new File(macOSFolder, "startup"); // creates startup file to boot java app VelocityUtils.render("mac/startup.vtl", executable, this); - executable.setExecutable(true, false); - Logger.info("Startup script file created in " + executable.getAbsolutePath()); - } else { - // sets startup file - this.executable = new File(macOSFolder, "universalJavaApplicationStub"); - Logger.info("Using " + executable.getAbsolutePath() + " as startup script"); - - } - - // copies universalJavaApplicationStub startup file to boot java app - File appStubFile = new File(macOSFolder, "universalJavaApplicationStub"); - String universalJavaApplicationStubResource = null; - switch (macConfig.getMacStartup()) { - case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break; - case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break; - case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break; - case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break; + File launcher = macConfig.getCustomLauncher(); + if(launcher != null && launcher.canRead() && launcher.isFile()){ + FileUtils.copyFileToFolder(launcher, macOSFolder); + this.executable = new File(macOSFolder, launcher.getName()); + } else { + // sets startup file + File appStubFile = new File(macOSFolder, "universalJavaApplicationStub"); + String universalJavaApplicationStubResource = null; + switch (macConfig.getMacStartup()) { + case UNIVERSAL: universalJavaApplicationStubResource = "universalJavaApplicationStub"; break; + case X86_64: universalJavaApplicationStubResource = "universalJavaApplicationStub.x86_64"; break; + case ARM64: universalJavaApplicationStubResource = "universalJavaApplicationStub.arm64"; break; + case SCRIPT: universalJavaApplicationStubResource = "universalJavaApplicationStub.sh"; break; + } + FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile); + this.executable = appStubFile; + } } - FileUtils.copyResourceToFile("/mac/" + universalJavaApplicationStubResource, appStubFile); - appStubFile.setExecutable(true, false); + executable.setExecutable(true, false); + Logger.info("Startup script file created in " + executable.getAbsolutePath()); // process classpath classpath = (this.macConfig.isRelocateJar() ? "Java/" : "") + this.jarFile.getName() + (classpath != null ? ":" + classpath : "");