Skip to content

Commit 856a132

Browse files
committed
U property to choose between different types of macos startups
1 parent 4ba4f13 commit 856a132

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class MacConfig implements Serializable {
3636
private boolean codesignApp = true;
3737
private InfoPlist infoPlist = new InfoPlist();
3838
private boolean hardenedCodesign = true;
39+
private MacStartup macStartup = MacStartup.SCRIPT;
3940

4041
public File getIcnsFile() {
4142
return icnsFile;
@@ -221,6 +222,14 @@ public boolean isHardenedCodesign() {
221222
return hardenedCodesign;
222223
}
223224

225+
public MacStartup getMacStartup() {
226+
return macStartup;
227+
}
228+
229+
public void setMacStartup(MacStartup macStartup) {
230+
this.macStartup = macStartup;
231+
}
232+
224233
@Override
225234
public String toString() {
226235
return "MacConfig [icnsFile=" + icnsFile + ", backgroundImage=" + backgroundImage + ", windowWidth="
@@ -230,7 +239,7 @@ public String toString() {
230239
+ ", volumeName=" + volumeName + ", generateDmg=" + generateDmg + ", generatePkg=" + generatePkg
231240
+ ", relocateJar=" + relocateJar + ", appId=" + appId + ", developerId=" + developerId
232241
+ ", entitlements=" + entitlements + ", codesignApp=" + codesignApp + ", infoPlist=" + infoPlist
233-
+ ", hardenedCodesign=" + hardenedCodesign + "]";
242+
+ ", hardenedCodesign=" + hardenedCodesign + ", macStartup=" + macStartup + "]";
234243
}
235244

236245
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.fvarrui.javapackager.model;
2+
3+
public enum MacStartup {
4+
UNIVERSAL,
5+
X86_64,
6+
ARM64,
7+
SCRIPT
8+
}

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package io.github.fvarrui.javapackager.packagers;
22

33
import java.io.File;
4-
import java.io.IOException;
54
import java.util.ArrayList;
65
import java.util.Arrays;
76
import java.util.List;
87
import java.util.stream.Collectors;
98

109
import org.apache.commons.lang3.StringUtils;
1110
import org.apache.commons.lang3.SystemUtils;
12-
import org.codehaus.plexus.util.cli.CommandLineException;
1311

1412
import io.github.fvarrui.javapackager.model.Platform;
1513
import io.github.fvarrui.javapackager.utils.CommandUtils;
@@ -113,14 +111,14 @@ public File doCreateApp() throws Exception {
113111

114112
// copies universalJavaApplicationStub startup file to boot java app
115113
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
116-
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true);
117-
FileUtils.processFileContent(appStubFile, content -> {
118-
if (!macConfig.isRelocateJar()) {
119-
content = content.replaceAll("/Contents/Resources/Java", "/Contents/Resources");
120-
}
121-
content = content.replaceAll("\\$\\{info.name\\}", this.name);
122-
return content;
123-
});
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, true);
124122
appStubFile.setExecutable(true, false);
125123

126124
// process classpath
@@ -152,9 +150,9 @@ public File doCreateApp() throws Exception {
152150
return appFile;
153151
}
154152

155-
private void codesign(String developerId, File entitlements, File appFile)
156-
throws IOException, CommandLineException {
153+
private void codesign(String developerId, File entitlements, File appFile) throws Exception {
157154

155+
// checks --option flags
158156
List<String> flags = new ArrayList<>();
159157
if (macConfig.isHardenedCodesign()) {
160158
if (VersionUtils.compareVersions("10.13.6", SystemUtils.OS_VERSION) >= 0) {
@@ -163,25 +161,31 @@ private void codesign(String developerId, File entitlements, File appFile)
163161
Logger.warn("Mac OS version detected: " + SystemUtils.OS_VERSION + " ... hardened runtime disabled!");
164162
}
165163
}
164+
165+
// if entitlements.plist file not specified, use a default one
166+
if (entitlements == null) {
167+
Logger.warn("Entitlements file not specified. Using defaults!");
168+
File entitlementsFile = new File(assetsFolder, "entitlements.plist");
169+
VelocityUtils.render("mac/entitlements.plist.vtl", entitlementsFile, this);
170+
} else if (!entitlements.exists()) {
171+
throw new Exception("Entitlements file doesn't exist: " + entitlements);
172+
}
166173

174+
// prepare params array
167175
List<Object> codesignArgs = new ArrayList<>();
168176
codesignArgs.add("--force");
169177
if (!flags.isEmpty()) {
170178
codesignArgs.add("--options");
171179
codesignArgs.add(StringUtils.join(flags, ","));
172180
}
173-
codesignArgs.add("--deep");
174-
if (entitlements == null) {
175-
Logger.warn("Entitlements file not specified");
176-
} else if (!entitlements.exists()) {
177-
Logger.warn("Entitlements file doesn't exist: " + entitlements);
178-
} else {
179-
codesignArgs.add("--entitlements");
180-
codesignArgs.add(entitlements);
181-
}
181+
codesignArgs.add("--deep");
182+
codesignArgs.add("--entitlements");
183+
codesignArgs.add(entitlements);
182184
codesignArgs.add("--sign");
183185
codesignArgs.add(developerId);
184186
codesignArgs.add(appFile);
187+
188+
// run codesign
185189
CommandUtils.execute("codesign", codesignArgs.toArray(new Object[codesignArgs.size()]));
186190
}
187191

0 commit comments

Comments
 (0)