Skip to content

Commit b1ddb90

Browse files
committed
Merge branch 'issue-187' into devel
2 parents 20f6798 + bb8fcdf commit b1ddb90

File tree

10 files changed

+1009
-28
lines changed

10 files changed

+1009
-28
lines changed

build.gradle

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id 'com.gradle.plugin-publish' version '0.12.0'
77
id 'io.codearte.nexus-staging' version '0.21.2'
88
id 'eclipse'
9-
id 'de.undercouch.download' version '4.1.1'
9+
id 'de.undercouch.download' version '5.0.4'
1010
}
1111

1212
repositories {
@@ -224,10 +224,18 @@ nexusStaging {
224224
password = project.findProperty('ossrhPassword') ?: ''
225225
}
226226

227-
task updateUniversalJavaApplicationStub(type: Download) {
228-
group 'Update'
229-
description 'Downloads universalJavaApplicationStub to src/main/resources/mac and overrides the existing one.'
230-
src 'https://raw.githubusercontent.com/fvarrui/universalJavaApplicationStub/master/src/universalJavaApplicationStub'
227+
228+
task updateUniversalJavaApplicationStub(type : Download) {
229+
def version = '20220410.162252'
230+
group 'Update universalJavaApplicationStub'
231+
description 'Downloads and ovewrites compiled and scripted versions of universalJavaApplicationStub to src/main/resources/mac and overrides the existing ones.'
232+
src([
233+
"https://github.com/fvarrui/universalJavaApplicationStub/releases/download/${version}/universalJavaApplicationStub.sh",
234+
"https://github.com/fvarrui/universalJavaApplicationStub/releases/download/${version}/universalJavaApplicationStub.x86_64",
235+
"https://github.com/fvarrui/universalJavaApplicationStub/releases/download/${version}/universalJavaApplicationStub.arm64",
236+
"https://github.com/fvarrui/universalJavaApplicationStub/releases/download/${version}/universalJavaApplicationStub"
237+
])
231238
dest file('src/main/resources/mac')
232-
overwrite true
239+
overwrite true
233240
}
241+

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, this.getAssetsDir());
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);
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+
entitlements = new File(assetsFolder, "entitlements.plist");
169+
VelocityUtils.render("mac/entitlements.plist.vtl", entitlements, 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

src/main/resources/mac/Info.plist.vtl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@
116116
#if ($info.scripts.bootstrap)
117117
<key>BootstrapScript</key>
118118
<string>$APP_PACKAGE/Contents/Resources/scripts/${info.bootstrapFile.name}</string>
119+
#end
120+
<key>RelocateJar</key>
121+
#if ($info.macConfig.relocateJar)
122+
<true/>
123+
#else
124+
<false/>
119125
#end
120126
</dict>
121127
<key>LSEnvironment</key>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<!--
6+
Allow Execution of JIT-compiled Code Entitlement
7+
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-jit
8+
-->
9+
<key>com.apple.security.cs.allow-jit</key>
10+
<true/>
11+
<!--
12+
Allow Unsigned Executable Memory Entitlement
13+
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-unsigned-executable-memory
14+
-->
15+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
16+
<true/>
17+
<!--
18+
Disable Executable Memory Protection Entitlement
19+
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-executable-page-protection
20+
-->
21+
<key>com.apple.security.cs.disable-executable-page-protection</key>
22+
<true/>
23+
<!--
24+
Allow DYLD Environment Variables Entitlement
25+
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-dyld-environment-variables
26+
-->
27+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
28+
<true/>
29+
<!--
30+
Disable Library Validation Entitlement
31+
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-library-validation
32+
-->
33+
<key>com.apple.security.cs.disable-library-validation</key>
34+
<true/>
35+
</dict>
36+
</plist>
143 KB
Binary file not shown.
82.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)