Skip to content

Commit f184c3b

Browse files
committed
U macos codesigning process enhanced
1 parent d5f053b commit f184c3b

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public class MacConfig implements Serializable {
2727
private boolean generateDmg = true;
2828
private boolean generatePkg = true;
2929
private boolean relocateJar = true;
30-
private String signingIdentity = "-";
30+
private String appIdentifier;
31+
private String developerId = "-";
32+
private File entitlements;
3133

3234
public File getIcnsFile() {
3335
return icnsFile;
@@ -165,12 +167,28 @@ public void setRelocateJar(boolean relocateJar) {
165167
this.relocateJar = relocateJar;
166168
}
167169

168-
public String getSigningIdentity() {
169-
return signingIdentity;
170+
public String getAppIdentifier() {
171+
return appIdentifier;
170172
}
171173

172-
public void setSigningIdentity(String signingIdentity) {
173-
this.signingIdentity = signingIdentity;
174+
public void setAppIdentifier(String appIdentifier) {
175+
this.appIdentifier = appIdentifier;
176+
}
177+
178+
public String getDeveloperId() {
179+
return developerId;
180+
}
181+
182+
public void setDeveloperId(String developerId) {
183+
this.developerId = developerId;
184+
}
185+
186+
public File getEntitlements() {
187+
return entitlements;
188+
}
189+
190+
public void setEntitlements(File entitlements) {
191+
this.entitlements = entitlements;
174192
}
175193

176194
@Override
@@ -180,7 +198,8 @@ public String toString() {
180198
+ ", iconSize=" + iconSize + ", textSize=" + textSize + ", iconX=" + iconX + ", iconY=" + iconY
181199
+ ", appsLinkIconX=" + appsLinkIconX + ", appsLinkIconY=" + appsLinkIconY + ", volumeIcon=" + volumeIcon
182200
+ ", volumeName=" + volumeName + ", generateDmg=" + generateDmg + ", generatePkg=" + generatePkg
183-
+ ", relocateJar=" + relocateJar + ", signingIdentity=" + signingIdentity + "]";
201+
+ ", relocateJar=" + relocateJar + ", appIdentifier=" + appIdentifier + ", developerId=" + developerId
202+
+ ", entitlements=" + entitlements + "]";
184203
}
185204

186205
/**
@@ -199,5 +218,6 @@ public void setDefaults(Packager packager) {
199218
this.setIconY(defaultIfNull(this.getIconY(), 116));
200219
this.setAppsLinkIconX(defaultIfNull(this.getAppsLinkIconX(), 360));
201220
this.setAppsLinkIconY(defaultIfNull(this.getAppsLinkIconY(), 116));
221+
this.setAppIdentifier(defaultIfNull(this.getAppIdentifier(), packager.getMainClass()));
202222
}
203223
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package io.github.fvarrui.javapackager.packagers;
22

33
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.codehaus.plexus.util.cli.CommandLineException;
49

510
import io.github.fvarrui.javapackager.model.Platform;
611
import io.github.fvarrui.javapackager.utils.CommandUtils;
@@ -114,12 +119,30 @@ public File doCreateApp() throws Exception {
114119

115120
// codesigns app folder
116121
if (Platform.mac.isCurrentPlatform()) {
117-
CommandUtils.execute("codesign", "--force", "--deep", "--sign", this.macConfig.getSigningIdentity(), appFile);
122+
codesign(this.macConfig.getDeveloperId(), this.macConfig.getEntitlements(), this.appFile);
118123
} else {
119124
Logger.warn("Generated app could not be signed due to current platform is " + Platform.getCurrentPlatform());
120125
}
121126

122127
return appFile;
123128
}
124129

130+
private void codesign(String developerId, File entitlements, File appFile) throws IOException, CommandLineException {
131+
List<Object> codesignArgs = new ArrayList<>();
132+
codesignArgs.add("--force");
133+
codesignArgs.add("--deep");
134+
if (entitlements == null) {
135+
Logger.warn("Entitlements file not specified");
136+
} else if (!entitlements.exists()) {
137+
Logger.warn("Entitlements file doesn't exist: " + entitlements);
138+
} else {
139+
codesignArgs.add("--entitlements");
140+
codesignArgs.add(entitlements);
141+
}
142+
codesignArgs.add("--sign");
143+
codesignArgs.add(developerId);
144+
codesignArgs.add(appFile);
145+
CommandUtils.execute("codesign", codesignArgs.toArray(new Object[codesignArgs.size()]));
146+
}
147+
125148
}

0 commit comments

Comments
 (0)