Skip to content

Commit 85316b2

Browse files
committed
U refactoring
1 parent c3acbc6 commit 85316b2

File tree

2 files changed

+39
-41
lines changed

2 files changed

+39
-41
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,13 @@ protected File doApply(MacPackager packager) throws Exception {
8383
File volumeIcon = (macConfig.getVolumeIcon() != null) ? macConfig.getVolumeIcon() : iconFile;
8484
FileUtils.copyFileToFile(volumeIcon, new File(appFolder, ".VolumeIcon.icns"));
8585

86-
87-
8886
// creates image
8987
Logger.info("Creating image: " + tempDmgFile.getAbsolutePath());
9088
String osArchitecture = System.getProperty("os.arch");
91-
if (osArchitecture.toLowerCase().equals("aarch64")) {
92-
93-
execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", volumeName, "-ov", "-fs", "APFS", "-format", "UDRW", tempDmgFile);
94-
95-
} else {
96-
97-
execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", volumeName, "-ov", "-fs", "HFS+", "-format", "UDRW", tempDmgFile);
98-
99-
}
89+
boolean isAarch64 = osArchitecture.toLowerCase().equals("aarch64");
90+
String fileSystem = isAarch64 ? "APFS" : "HFS+";
91+
Logger.warn(osArchitecture + " architecture detected. Using " + fileSystem + " filesystem");
92+
execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", volumeName, "-ov", "-fs", fileSystem, "-format", "UDRW", tempDmgFile);
10093

10194
if (mountFolder.exists()) {
10295
Logger.info("Unmounting volume: " + mountFolder);
@@ -138,7 +131,7 @@ protected File doApply(MacPackager packager) throws Exception {
138131
Logger.info("Fixing permissions...");
139132
execute("chmod", "-Rf", "u+r,go-w", mountFolder);
140133

141-
if (!osArchitecture.toLowerCase().equals("aarch64")) {
134+
if (!isAarch64) {
142135
// makes the top window open itself on mount:
143136
Logger.info("Blessing ...");
144137
execute("bless", "--folder", mountFolder, "--openfolder", mountFolder);

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
* Packager for Mac OS X
2424
*/
2525
public class MacPackager extends Packager {
26-
26+
2727
private File appFile;
2828
private File contentsFolder;
2929
private File resourcesFolder;
3030
private File javaFolder;
3131
private File macOSFolder;
32-
32+
3333
public File getAppFile() {
3434
return appFile;
3535
}
@@ -38,18 +38,20 @@ public File getAppFile() {
3838
public void doInit() throws Exception {
3939

4040
this.macConfig.setDefaults(this);
41-
42-
// FIX useResourcesAsWorkingDir=false doesn't work fine on Mac OS (option disabled)
41+
42+
// FIX useResourcesAsWorkingDir=false doesn't work fine on Mac OS (option
43+
// disabled)
4344
if (!this.isUseResourcesAsWorkingDir()) {
4445
this.useResourcesAsWorkingDir = true;
45-
Logger.warn("'useResourcesAsWorkingDir' property disabled on Mac OS (useResourcesAsWorkingDir is always true)");
46+
Logger.warn(
47+
"'useResourcesAsWorkingDir' property disabled on Mac OS (useResourcesAsWorkingDir is always true)");
4648
}
47-
49+
4850
}
4951

5052
@Override
5153
protected void doCreateAppStructure() throws Exception {
52-
54+
5355
// initializes the references to the app structure folders
5456
this.appFile = new File(appFolder, name + ".app");
5557
this.contentsFolder = new File(appFile, "Contents");
@@ -58,19 +60,19 @@ protected void doCreateAppStructure() throws Exception {
5860
this.macOSFolder = new File(contentsFolder, "MacOS");
5961

6062
// makes dirs
61-
63+
6264
FileUtils.mkdir(this.appFile);
6365
Logger.info("App file folder created: " + appFile.getAbsolutePath());
64-
66+
6567
FileUtils.mkdir(this.contentsFolder);
6668
Logger.info("Contents folder created: " + contentsFolder.getAbsolutePath());
67-
69+
6870
FileUtils.mkdir(this.resourcesFolder);
6971
Logger.info("Resources folder created: " + resourcesFolder.getAbsolutePath());
70-
72+
7173
FileUtils.mkdir(this.javaFolder);
7274
Logger.info("Java folder created: " + javaFolder.getAbsolutePath());
73-
75+
7476
FileUtils.mkdir(this.macOSFolder);
7577
Logger.info("MacOS folder created: " + macOSFolder.getAbsolutePath());
7678

@@ -81,35 +83,34 @@ protected void doCreateAppStructure() throws Exception {
8183
this.resourcesDestinationFolder = resourcesFolder;
8284

8385
}
84-
86+
8587
/**
8688
* Creates a native MacOS app bundle
8789
*/
8890
@Override
8991
public File doCreateApp() throws Exception {
90-
9192

9293
// copies jarfile to Java folder
9394
FileUtils.copyFileToFolder(jarFile, javaFolder);
94-
95+
9596
if (this.administratorRequired) {
9697

9798
// sets startup file
98-
this.executable = new File(macOSFolder, "startup");
99-
99+
this.executable = new File(macOSFolder, "startup");
100+
100101
// creates startup file to boot java app
101102
VelocityUtils.render("mac/startup.vtl", executable, this);
102103
executable.setExecutable(true, false);
103104
Logger.info("Startup script file created in " + executable.getAbsolutePath());
104105

105106
} else {
106-
107+
107108
// sets startup file
108-
this.executable = new File(macOSFolder, "universalJavaApplicationStub");
109+
this.executable = new File(macOSFolder, "universalJavaApplicationStub");
109110
Logger.info("Using " + executable.getAbsolutePath() + " as startup script");
110-
111+
111112
}
112-
113+
113114
// copies universalJavaApplicationStub startup file to boot java app
114115
File appStubFile = new File(macOSFolder, "universalJavaApplicationStub");
115116
FileUtils.copyResourceToFile("/mac/universalJavaApplicationStub", appStubFile, true);
@@ -121,12 +122,15 @@ public File doCreateApp() throws Exception {
121122
return content;
122123
});
123124
appStubFile.setExecutable(true, false);
124-
125+
125126
// process classpath
126127
classpath = (this.macConfig.isRelocateJar() ? "Java/" : "") + this.jarFile.getName() + (classpath != null ? ":" + classpath : "");
127128
classpaths = Arrays.asList(classpath.split("[:;]"));
128129
if (!isUseResourcesAsWorkingDir()) {
129-
classpaths = classpaths.stream().map(cp -> new File(cp).isAbsolute() ? cp : "$ResourcesFolder/" + cp).collect(Collectors.toList());
130+
classpaths = classpaths
131+
.stream()
132+
.map(cp -> new File(cp).isAbsolute() ? cp : "$ResourcesFolder/" + cp)
133+
.collect(Collectors.toList());
130134
}
131135
classpath = StringUtils.join(classpaths, ":");
132136

@@ -144,22 +148,23 @@ public File doCreateApp() throws Exception {
144148
} else {
145149
codesign(this.macConfig.getDeveloperId(), this.macConfig.getEntitlements(), this.appFile);
146150
}
147-
151+
148152
return appFile;
149153
}
150154

151-
private void codesign(String developerId, File entitlements, File appFile) throws IOException, CommandLineException {
155+
private void codesign(String developerId, File entitlements, File appFile)
156+
throws IOException, CommandLineException {
152157

153158
List<String> flags = new ArrayList<>();
154159
if (VersionUtils.compareVersions("10.13.6", SystemUtils.OS_VERSION) >= 0) {
155-
flags.add("runtime"); // enable hardened runtime if Mac OS version >= 10.13.6
160+
flags.add("runtime"); // enable hardened runtime if Mac OS version >= 10.13.6
156161
} else {
157-
Logger.warn("Mac OS version detected: " + SystemUtils.OS_VERSION + " ... hardened runtime disabled!");
162+
Logger.warn("Mac OS version detected: " + SystemUtils.OS_VERSION + " ... hardened runtime disabled!");
158163
}
159-
164+
160165
List<Object> codesignArgs = new ArrayList<>();
161166
codesignArgs.add("--force");
162-
if (!flags.isEmpty()) {
167+
if (!flags.isEmpty()) {
163168
codesignArgs.add("--options");
164169
codesignArgs.add(StringUtils.join(flags, ","));
165170
}

0 commit comments

Comments
 (0)