author | herrick |
Tue, 18 Dec 2018 15:10:45 -0500 | |
branch | JDK-8200758-branch |
changeset 57077 | 8f9cf6ad59f0 |
parent 57070 | 42783e8e73de |
child 57078 | db003bfc5bf7 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
57039 | 28 |
import jdk.jpackage.internal.resources.MacResources; |
57038 | 29 |
|
30 |
import java.io.BufferedWriter; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileInputStream; |
|
33 |
import java.io.FileOutputStream; |
|
34 |
import java.io.FileWriter; |
|
35 |
import java.io.IOException; |
|
36 |
import java.io.InputStream; |
|
37 |
import java.io.OutputStream; |
|
38 |
import java.io.OutputStreamWriter; |
|
39 |
import java.io.UncheckedIOException; |
|
40 |
import java.io.Writer; |
|
41 |
import java.math.BigInteger; |
|
42 |
import java.nio.file.Files; |
|
43 |
import java.nio.file.Path; |
|
44 |
import java.nio.file.attribute.PosixFilePermission; |
|
45 |
import java.text.MessageFormat; |
|
46 |
import java.util.ArrayList; |
|
47 |
import java.util.Arrays; |
|
48 |
import java.util.EnumSet; |
|
49 |
import java.util.HashMap; |
|
50 |
import java.util.List; |
|
51 |
import java.util.Map; |
|
52 |
import java.util.Objects; |
|
53 |
import java.util.Optional; |
|
54 |
import java.util.ResourceBundle; |
|
55 |
import java.util.Set; |
|
56 |
import java.util.concurrent.atomic.AtomicReference; |
|
57 |
import java.util.function.Consumer; |
|
58 |
||
57039 | 59 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
60 |
import static jdk.jpackage.internal.MacBaseInstallerBundler.*; |
|
61 |
import static jdk.jpackage.internal.MacAppBundler.*; |
|
57038 | 62 |
|
63 |
public class MacAppImageBuilder extends AbstractAppImageBuilder { |
|
64 |
||
57059 | 65 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
66 |
"jdk.jpackage.internal.resources.MacResources"); |
|
57038 | 67 |
|
68 |
private static final String EXECUTABLE_NAME = "JavaAppLauncher"; |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
69 |
private static final String LIBRARY_NAME = "libapplauncher.dylib"; |
57038 | 70 |
private static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns"; |
71 |
private static final String OS_TYPE_CODE = "APPL"; |
|
72 |
private static final String TEMPLATE_INFO_PLIST_LITE = |
|
73 |
"Info-lite.plist.template"; |
|
74 |
private static final String TEMPLATE_RUNTIME_INFO_PLIST = |
|
75 |
"Runtime-Info.plist.template"; |
|
76 |
||
77 |
private final Path root; |
|
78 |
private final Path contentsDir; |
|
79 |
private final Path javaDir; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
80 |
private final Path javaModsDir; |
57038 | 81 |
private final Path resourcesDir; |
82 |
private final Path macOSDir; |
|
83 |
private final Path runtimeDir; |
|
84 |
private final Path runtimeRoot; |
|
85 |
private final Path mdir; |
|
86 |
||
87 |
private final Map<String, ? super Object> params; |
|
88 |
||
89 |
private static List<String> keyChains; |
|
90 |
||
91 |
public static final BundlerParamInfo<Boolean> |
|
92 |
MAC_CONFIGURE_LAUNCHER_IN_PLIST = new StandardBundlerParam<>( |
|
93 |
I18N.getString("param.configure-launcher-in-plist"), |
|
94 |
I18N.getString( |
|
95 |
"param.configure-launcher-in-plist.description"), |
|
96 |
"mac.configure-launcher-in-plist", |
|
97 |
Boolean.class, |
|
98 |
params -> Boolean.FALSE, |
|
99 |
(s, p) -> Boolean.valueOf(s)); |
|
100 |
||
101 |
public static final BundlerParamInfo<String> MAC_CATEGORY = |
|
102 |
new StandardBundlerParam<>( |
|
103 |
I18N.getString("param.category-name"), |
|
104 |
I18N.getString("param.category-name.description"), |
|
105 |
"mac.category", |
|
106 |
String.class, |
|
107 |
CATEGORY::fetchFrom, |
|
108 |
(s, p) -> s |
|
109 |
); |
|
110 |
||
111 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_NAME = |
|
112 |
new StandardBundlerParam<>( |
|
113 |
I18N.getString("param.cfbundle-name.name"), |
|
114 |
I18N.getString("param.cfbundle-name.description"), |
|
115 |
"mac.CFBundleName", |
|
116 |
String.class, |
|
117 |
params -> null, |
|
118 |
(s, p) -> s); |
|
119 |
||
120 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER = |
|
121 |
new StandardBundlerParam<>( |
|
122 |
I18N.getString("param.cfbundle-identifier.name"), |
|
123 |
I18N.getString("param.cfbundle-identifier.description"), |
|
124 |
Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(), |
|
125 |
String.class, |
|
126 |
IDENTIFIER::fetchFrom, |
|
127 |
(s, p) -> s); |
|
128 |
||
129 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION = |
|
130 |
new StandardBundlerParam<>( |
|
131 |
I18N.getString("param.cfbundle-version.name"), |
|
132 |
I18N.getString("param.cfbundle-version.description"), |
|
133 |
"mac.CFBundleVersion", |
|
134 |
String.class, |
|
135 |
p -> { |
|
136 |
String s = VERSION.fetchFrom(p); |
|
137 |
if (validCFBundleVersion(s)) { |
|
138 |
return s; |
|
139 |
} else { |
|
140 |
return "100"; |
|
141 |
} |
|
142 |
}, |
|
143 |
(s, p) -> s); |
|
144 |
||
145 |
public static final BundlerParamInfo<File> CONFIG_ROOT = |
|
146 |
new StandardBundlerParam<>( |
|
147 |
I18N.getString("param.config-root.name"), |
|
148 |
I18N.getString("param.config-root.description"), |
|
149 |
"configRoot", |
|
150 |
File.class, |
|
151 |
params -> { |
|
152 |
File configRoot = |
|
153 |
new File(BUILD_ROOT.fetchFrom(params), "macosx"); |
|
154 |
configRoot.mkdirs(); |
|
155 |
return configRoot; |
|
156 |
}, |
|
157 |
(s, p) -> new File(s)); |
|
158 |
||
159 |
public static final BundlerParamInfo<String> DEFAULT_ICNS_ICON = |
|
160 |
new StandardBundlerParam<>( |
|
161 |
I18N.getString("param.default-icon-icns"), |
|
162 |
I18N.getString("param.default-icon-icns.description"), |
|
163 |
".mac.default.icns", |
|
164 |
String.class, |
|
165 |
params -> TEMPLATE_BUNDLE_ICON, |
|
166 |
(s, p) -> s); |
|
167 |
||
168 |
public static final BundlerParamInfo<File> ICON_ICNS = |
|
169 |
new StandardBundlerParam<>( |
|
170 |
I18N.getString("param.icon-icns.name"), |
|
171 |
I18N.getString("param.icon-icns.description"), |
|
172 |
"icon.icns", |
|
173 |
File.class, |
|
174 |
params -> { |
|
175 |
File f = ICON.fetchFrom(params); |
|
176 |
if (f != null && !f.getName().toLowerCase().endsWith(".icns")) { |
|
177 |
Log.error(MessageFormat.format( |
|
178 |
I18N.getString("message.icon-not-icns"), f)); |
|
179 |
return null; |
|
180 |
} |
|
181 |
return f; |
|
182 |
}, |
|
183 |
(s, p) -> new File(s)); |
|
184 |
||
185 |
public static final StandardBundlerParam<Boolean> SIGN_BUNDLE = |
|
186 |
new StandardBundlerParam<>( |
|
187 |
I18N.getString("param.sign-bundle.name"), |
|
188 |
I18N.getString("param.sign-bundle.description"), |
|
189 |
Arguments.CLIOptions.MAC_SIGN.getId(), |
|
190 |
Boolean.class, |
|
191 |
params -> false, |
|
192 |
// valueOf(null) is false, we actually do want null in some cases |
|
193 |
(s, p) -> (s == null || "null".equalsIgnoreCase(s)) ? |
|
194 |
null : Boolean.valueOf(s) |
|
195 |
); |
|
196 |
||
197 |
public MacAppImageBuilder(Map<String, Object> config, Path imageOutDir) |
|
198 |
throws IOException { |
|
199 |
super(config, imageOutDir.resolve(APP_NAME.fetchFrom(config) |
|
200 |
+ ".app/Contents/PlugIns/Java.runtime/Contents/Home")); |
|
201 |
||
202 |
Objects.requireNonNull(imageOutDir); |
|
203 |
||
204 |
this.params = config; |
|
205 |
this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params) + ".app"); |
|
206 |
this.contentsDir = root.resolve("Contents"); |
|
207 |
this.javaDir = contentsDir.resolve("Java"); |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
208 |
this.javaModsDir = javaDir.resolve("mods"); |
57038 | 209 |
this.resourcesDir = contentsDir.resolve("Resources"); |
210 |
this.macOSDir = contentsDir.resolve("MacOS"); |
|
211 |
this.runtimeDir = contentsDir.resolve("PlugIns/Java.runtime"); |
|
212 |
this.runtimeRoot = runtimeDir.resolve("Contents/Home"); |
|
213 |
this.mdir = runtimeRoot.resolve("lib"); |
|
214 |
Files.createDirectories(javaDir); |
|
215 |
Files.createDirectories(resourcesDir); |
|
216 |
Files.createDirectories(macOSDir); |
|
217 |
Files.createDirectories(runtimeDir); |
|
218 |
} |
|
219 |
||
220 |
public MacAppImageBuilder(Map<String, Object> config, String jreName, |
|
221 |
Path imageOutDir) throws IOException { |
|
222 |
super(null, imageOutDir.resolve(jreName + "/Contents/Home")); |
|
223 |
||
224 |
Objects.requireNonNull(imageOutDir); |
|
225 |
||
226 |
this.params = config; |
|
227 |
this.root = imageOutDir.resolve(jreName ); |
|
228 |
this.contentsDir = root.resolve("Contents"); |
|
229 |
this.javaDir = null; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
230 |
this.javaModsDir = null; |
57038 | 231 |
this.resourcesDir = null; |
232 |
this.macOSDir = null; |
|
233 |
this.runtimeDir = this.root; |
|
234 |
this.runtimeRoot = runtimeDir.resolve("Contents/Home"); |
|
235 |
this.mdir = runtimeRoot.resolve("lib"); |
|
236 |
||
237 |
Files.createDirectories(runtimeDir); |
|
238 |
} |
|
239 |
||
240 |
private void writeEntry(InputStream in, Path dstFile) throws IOException { |
|
241 |
Files.createDirectories(dstFile.getParent()); |
|
242 |
Files.copy(in, dstFile); |
|
243 |
} |
|
244 |
||
245 |
// chmod ugo+x file |
|
246 |
private void setExecutable(Path file) { |
|
247 |
try { |
|
248 |
Set<PosixFilePermission> perms = |
|
249 |
Files.getPosixFilePermissions(file); |
|
250 |
perms.add(PosixFilePermission.OWNER_EXECUTE); |
|
251 |
perms.add(PosixFilePermission.GROUP_EXECUTE); |
|
252 |
perms.add(PosixFilePermission.OTHERS_EXECUTE); |
|
253 |
Files.setPosixFilePermissions(file, perms); |
|
254 |
} catch (IOException ioe) { |
|
255 |
throw new UncheckedIOException(ioe); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
private static void createUtf8File(File file, String content) |
|
260 |
throws IOException { |
|
261 |
try (OutputStream fout = new FileOutputStream(file); |
|
262 |
Writer output = new OutputStreamWriter(fout, "UTF-8")) { |
|
263 |
output.write(content); |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
public static boolean validCFBundleVersion(String v) { |
|
268 |
// CFBundleVersion (String - iOS, OS X) specifies the build version |
|
269 |
// number of the bundle, which identifies an iteration (released or |
|
270 |
// unreleased) of the bundle. The build version number should be a |
|
271 |
// string comprised of three non-negative, period-separated integers |
|
272 |
// with the first integer being greater than zero. The string should |
|
273 |
// only contain numeric (0-9) and period (.) characters. Leading zeros |
|
274 |
// are truncated from each integer and will be ignored (that is, |
|
275 |
// 1.02.3 is equivalent to 1.2.3). This key is not localizable. |
|
276 |
||
277 |
if (v == null) { |
|
278 |
return false; |
|
279 |
} |
|
280 |
||
281 |
String p[] = v.split("\\."); |
|
282 |
if (p.length > 3 || p.length < 1) { |
|
283 |
Log.verbose(I18N.getString( |
|
284 |
"message.version-string-too-many-components")); |
|
285 |
return false; |
|
286 |
} |
|
287 |
||
288 |
try { |
|
289 |
BigInteger n = new BigInteger(p[0]); |
|
290 |
if (BigInteger.ONE.compareTo(n) > 0) { |
|
291 |
Log.verbose(I18N.getString( |
|
292 |
"message.version-string-first-number-not-zero")); |
|
293 |
return false; |
|
294 |
} |
|
295 |
if (p.length > 1) { |
|
296 |
n = new BigInteger(p[1]); |
|
297 |
if (BigInteger.ZERO.compareTo(n) > 0) { |
|
298 |
Log.verbose(I18N.getString( |
|
299 |
"message.version-string-no-negative-numbers")); |
|
300 |
return false; |
|
301 |
} |
|
302 |
} |
|
303 |
if (p.length > 2) { |
|
304 |
n = new BigInteger(p[2]); |
|
305 |
if (BigInteger.ZERO.compareTo(n) > 0) { |
|
306 |
Log.verbose(I18N.getString( |
|
307 |
"message.version-string-no-negative-numbers")); |
|
308 |
return false; |
|
309 |
} |
|
310 |
} |
|
311 |
} catch (NumberFormatException ne) { |
|
312 |
Log.verbose(I18N.getString("message.version-string-numbers-only")); |
|
313 |
Log.verbose(ne); |
|
314 |
return false; |
|
315 |
} |
|
316 |
||
317 |
return true; |
|
318 |
} |
|
319 |
||
320 |
@Override |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
321 |
public Path getAppDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
322 |
return javaDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
323 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
324 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
325 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
326 |
public Path getAppModsDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
327 |
return javaModsDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
328 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
329 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
330 |
@Override |
57038 | 331 |
public InputStream getResourceAsStream(String name) { |
332 |
return MacResources.class.getResourceAsStream(name); |
|
333 |
} |
|
334 |
||
335 |
@Override |
|
336 |
public void prepareApplicationFiles() throws IOException { |
|
337 |
Map<String, ? super Object> originalParams = new HashMap<>(params); |
|
338 |
// Generate PkgInfo |
|
339 |
File pkgInfoFile = new File(contentsDir.toFile(), "PkgInfo"); |
|
340 |
pkgInfoFile.createNewFile(); |
|
341 |
writePkgInfo(pkgInfoFile); |
|
342 |
||
343 |
Path executable = macOSDir.resolve(getLauncherName(params)); |
|
344 |
||
345 |
// create the main app launcher |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
346 |
try (InputStream is_launcher = |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
347 |
getResourceAsStream("jpackageapplauncher"); |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
348 |
InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
57038 | 349 |
// Copy executable and library to MacOS folder |
350 |
writeEntry(is_launcher, executable); |
|
351 |
writeEntry(is_lib, macOSDir.resolve(LIBRARY_NAME)); |
|
352 |
} |
|
353 |
executable.toFile().setExecutable(true, false); |
|
354 |
// generate main app launcher config file |
|
355 |
File cfg = new File(root.toFile(), getLauncherCfgName(params)); |
|
356 |
writeCfgFile(params, cfg, "$APPDIR/PlugIns/Java.runtime"); |
|
357 |
||
358 |
// create secondary app launcher(s) and config file(s) |
|
359 |
List<Map<String, ? super Object>> entryPoints = |
|
360 |
StandardBundlerParam.SECONDARY_LAUNCHERS.fetchFrom(params); |
|
361 |
for (Map<String, ? super Object> entryPoint : entryPoints) { |
|
362 |
Map<String, ? super Object> tmp = new HashMap<>(originalParams); |
|
363 |
tmp.putAll(entryPoint); |
|
364 |
||
365 |
// add executable for secondary launcher |
|
366 |
Path secondaryExecutable = macOSDir.resolve(getLauncherName(tmp)); |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
367 |
try (InputStream is = getResourceAsStream("jpackageapplauncher");) { |
57038 | 368 |
writeEntry(is, secondaryExecutable); |
369 |
} |
|
370 |
secondaryExecutable.toFile().setExecutable(true, false); |
|
371 |
||
372 |
// add config file for secondary launcher |
|
373 |
cfg = new File(root.toFile(), getLauncherCfgName(tmp)); |
|
374 |
writeCfgFile(tmp, cfg, "$APPDIR/PlugIns/Java.runtime"); |
|
375 |
} |
|
376 |
||
377 |
// Copy class path entries to Java folder |
|
378 |
copyClassPathEntries(javaDir); |
|
379 |
||
380 |
/*********** Take care of "config" files *******/ |
|
381 |
File icon = ICON_ICNS.fetchFrom(params); |
|
382 |
InputStream in = locateResource( |
|
383 |
"package/macosx/" + APP_NAME.fetchFrom(params) + ".icns", |
|
384 |
"icon", |
|
385 |
DEFAULT_ICNS_ICON.fetchFrom(params), |
|
386 |
icon, |
|
387 |
VERBOSE.fetchFrom(params), |
|
388 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params)); |
|
389 |
Files.copy(in, |
|
390 |
resourcesDir.resolve(APP_NAME.fetchFrom(params) + ".icns")); |
|
391 |
||
392 |
// copy file association icons |
|
393 |
for (Map<String, ? |
|
394 |
super Object> fa : FILE_ASSOCIATIONS.fetchFrom(params)) { |
|
395 |
File f = FA_ICON.fetchFrom(fa); |
|
396 |
if (f != null && f.exists()) { |
|
397 |
try (InputStream in2 = new FileInputStream(f)) { |
|
398 |
Files.copy(in2, resourcesDir.resolve(f.getName())); |
|
399 |
} |
|
400 |
||
401 |
} |
|
402 |
} |
|
403 |
||
404 |
copyRuntimeFiles(); |
|
405 |
sign(); |
|
406 |
} |
|
407 |
||
408 |
@Override |
|
57070 | 409 |
public void prepareJreFiles() throws IOException { |
57038 | 410 |
copyRuntimeFiles(); |
411 |
sign(); |
|
412 |
} |
|
413 |
||
414 |
private void copyRuntimeFiles() throws IOException { |
|
415 |
// Generate Info.plist |
|
416 |
writeInfoPlist(contentsDir.resolve("Info.plist").toFile()); |
|
417 |
||
418 |
// generate java runtime info.plist |
|
419 |
writeRuntimeInfoPlist( |
|
420 |
runtimeDir.resolve("Contents/Info.plist").toFile()); |
|
421 |
||
422 |
// copy library |
|
423 |
Path runtimeMacOSDir = Files.createDirectories( |
|
424 |
runtimeDir.resolve("Contents/MacOS")); |
|
425 |
||
426 |
// JDK 9, 10, and 11 have extra '/jli/' subdir |
|
427 |
Path jli = runtimeRoot.resolve("lib/libjli.dylib"); |
|
428 |
if (!Files.exists(jli)) { |
|
429 |
jli = runtimeRoot.resolve("lib/jli/libjli.dylib"); |
|
430 |
} |
|
431 |
||
432 |
Files.copy(jli, runtimeMacOSDir.resolve("libjli.dylib")); |
|
433 |
} |
|
434 |
||
435 |
private void sign() throws IOException { |
|
436 |
if (Optional.ofNullable( |
|
437 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { |
|
438 |
try { |
|
439 |
addNewKeychain(params); |
|
440 |
} catch (InterruptedException e) { |
|
441 |
Log.error(e.getMessage()); |
|
442 |
} |
|
443 |
String signingIdentity = |
|
444 |
DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params); |
|
445 |
if (signingIdentity != null) { |
|
446 |
signAppBundle(params, root, signingIdentity, |
|
447 |
BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params), null, null); |
|
448 |
} |
|
449 |
restoreKeychainList(params); |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
private String getLauncherName(Map<String, ? super Object> params) { |
|
454 |
if (APP_NAME.fetchFrom(params) != null) { |
|
455 |
return APP_NAME.fetchFrom(params); |
|
456 |
} else { |
|
457 |
return MAIN_CLASS.fetchFrom(params); |
|
458 |
} |
|
459 |
} |
|
460 |
||
461 |
public static String getLauncherCfgName(Map<String, ? super Object> p) { |
|
462 |
return "Contents/Java/" + APP_NAME.fetchFrom(p) + ".cfg"; |
|
463 |
} |
|
464 |
||
465 |
private void copyClassPathEntries(Path javaDirectory) throws IOException { |
|
466 |
List<RelativeFileSet> resourcesList = |
|
467 |
APP_RESOURCES_LIST.fetchFrom(params); |
|
468 |
if (resourcesList == null) { |
|
469 |
throw new RuntimeException( |
|
470 |
I18N.getString("message.null-classpath")); |
|
471 |
} |
|
472 |
||
473 |
for (RelativeFileSet classPath : resourcesList) { |
|
474 |
File srcdir = classPath.getBaseDirectory(); |
|
475 |
for (String fname : classPath.getIncludedFiles()) { |
|
476 |
copyEntry(javaDirectory, srcdir, fname); |
|
477 |
} |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
private String getBundleName(Map<String, ? super Object> params) { |
|
482 |
if (MAC_CF_BUNDLE_NAME.fetchFrom(params) != null) { |
|
483 |
String bn = MAC_CF_BUNDLE_NAME.fetchFrom(params); |
|
484 |
if (bn.length() > 16) { |
|
485 |
Log.error(MessageFormat.format(I18N.getString( |
|
486 |
"message.bundle-name-too-long-warning"), |
|
487 |
MAC_CF_BUNDLE_NAME.getID(), bn)); |
|
488 |
} |
|
489 |
return MAC_CF_BUNDLE_NAME.fetchFrom(params); |
|
490 |
} else if (APP_NAME.fetchFrom(params) != null) { |
|
491 |
return APP_NAME.fetchFrom(params); |
|
492 |
} else { |
|
493 |
String nm = MAIN_CLASS.fetchFrom(params); |
|
494 |
if (nm.length() > 16) { |
|
495 |
nm = nm.substring(0, 16); |
|
496 |
} |
|
497 |
return nm; |
|
498 |
} |
|
499 |
} |
|
500 |
||
501 |
private void writeRuntimeInfoPlist(File file) throws IOException { |
|
502 |
Map<String, String> data = new HashMap<>(); |
|
503 |
String identifier = Arguments.CREATE_JRE_INSTALLER.fetchFrom(params) ? |
|
504 |
MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) : |
|
505 |
"com.oracle.java." + MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params); |
|
506 |
data.put("CF_BUNDLE_IDENTIFIER", identifier); |
|
507 |
String name = Arguments.CREATE_JRE_INSTALLER.fetchFrom(params) ? |
|
508 |
getBundleName(params): "Java Runtime Image"; |
|
509 |
data.put("CF_BUNDLE_NAME", name); |
|
510 |
data.put("CF_BUNDLE_VERSION", VERSION.fetchFrom(params)); |
|
511 |
data.put("CF_BUNDLE_SHORT_VERSION_STRING", VERSION.fetchFrom(params)); |
|
512 |
||
513 |
Writer w = new BufferedWriter(new FileWriter(file)); |
|
514 |
w.write(preprocessTextResource( |
|
515 |
"package/macosx/Runtime-Info.plist", |
|
516 |
I18N.getString("resource.runtime-info-plist"), |
|
517 |
TEMPLATE_RUNTIME_INFO_PLIST, |
|
518 |
data, |
|
519 |
VERBOSE.fetchFrom(params), |
|
520 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params))); |
|
521 |
w.close(); |
|
522 |
} |
|
523 |
||
524 |
private void writeInfoPlist(File file) throws IOException { |
|
525 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
526 |
"message.preparing-info-plist"), file.getAbsolutePath())); |
|
527 |
||
528 |
//prepare config for exe |
|
529 |
//Note: do not need CFBundleDisplayName if we don't support localization |
|
530 |
Map<String, String> data = new HashMap<>(); |
|
531 |
data.put("DEPLOY_ICON_FILE", APP_NAME.fetchFrom(params) + ".icns"); |
|
532 |
data.put("DEPLOY_BUNDLE_IDENTIFIER", |
|
533 |
MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params)); |
|
534 |
data.put("DEPLOY_BUNDLE_NAME", |
|
535 |
getBundleName(params)); |
|
536 |
data.put("DEPLOY_BUNDLE_COPYRIGHT", |
|
537 |
COPYRIGHT.fetchFrom(params) != null ? |
|
538 |
COPYRIGHT.fetchFrom(params) : "Unknown"); |
|
539 |
data.put("DEPLOY_LAUNCHER_NAME", getLauncherName(params)); |
|
540 |
data.put("DEPLOY_JAVA_RUNTIME_NAME", "$APPDIR/PlugIns/Java.runtime"); |
|
541 |
data.put("DEPLOY_BUNDLE_SHORT_VERSION", |
|
542 |
VERSION.fetchFrom(params) != null ? |
|
543 |
VERSION.fetchFrom(params) : "1.0.0"); |
|
544 |
data.put("DEPLOY_BUNDLE_CFBUNDLE_VERSION", |
|
545 |
MAC_CF_BUNDLE_VERSION.fetchFrom(params) != null ? |
|
546 |
MAC_CF_BUNDLE_VERSION.fetchFrom(params) : "100"); |
|
547 |
data.put("DEPLOY_BUNDLE_CATEGORY", MAC_CATEGORY.fetchFrom(params)); |
|
548 |
||
549 |
boolean hasMainJar = MAIN_JAR.fetchFrom(params) != null; |
|
550 |
boolean hasMainModule = |
|
551 |
StandardBundlerParam.MODULE.fetchFrom(params) != null; |
|
552 |
||
553 |
if (hasMainJar) { |
|
554 |
data.put("DEPLOY_MAIN_JAR_NAME", MAIN_JAR.fetchFrom(params). |
|
555 |
getIncludedFiles().iterator().next()); |
|
556 |
} |
|
557 |
else if (hasMainModule) { |
|
558 |
data.put("DEPLOY_MODULE_NAME", |
|
559 |
StandardBundlerParam.MODULE.fetchFrom(params)); |
|
560 |
} |
|
561 |
||
562 |
data.put("DEPLOY_PREFERENCES_ID", |
|
563 |
PREFERENCES_ID.fetchFrom(params).toLowerCase()); |
|
564 |
||
565 |
StringBuilder sb = new StringBuilder(); |
|
566 |
List<String> jvmOptions = JVM_OPTIONS.fetchFrom(params); |
|
567 |
||
568 |
String newline = ""; //So we don't add extra line after last append |
|
569 |
for (String o : jvmOptions) { |
|
570 |
sb.append(newline).append( |
|
571 |
" <string>").append(o).append("</string>"); |
|
572 |
newline = "\n"; |
|
573 |
} |
|
574 |
||
575 |
Map<String, String> jvmProps = JVM_PROPERTIES.fetchFrom(params); |
|
576 |
for (Map.Entry<String, String> entry : jvmProps.entrySet()) { |
|
577 |
sb.append(newline) |
|
578 |
.append(" <string>-D") |
|
579 |
.append(entry.getKey()) |
|
580 |
.append("=") |
|
581 |
.append(entry.getValue()) |
|
582 |
.append("</string>"); |
|
583 |
newline = "\n"; |
|
584 |
} |
|
585 |
||
586 |
data.put("DEPLOY_JVM_OPTIONS", sb.toString()); |
|
587 |
||
588 |
sb = new StringBuilder(); |
|
589 |
List<String> args = ARGUMENTS.fetchFrom(params); |
|
590 |
newline = ""; |
|
591 |
// So we don't add unneccessary extra line after last append |
|
592 |
||
593 |
for (String o : args) { |
|
594 |
sb.append(newline).append(" <string>").append(o).append( |
|
595 |
"</string>"); |
|
596 |
newline = "\n"; |
|
597 |
} |
|
598 |
data.put("DEPLOY_ARGUMENTS", sb.toString()); |
|
599 |
||
600 |
newline = ""; |
|
601 |
||
602 |
data.put("DEPLOY_LAUNCHER_CLASS", MAIN_CLASS.fetchFrom(params)); |
|
603 |
||
604 |
StringBuilder macroedPath = new StringBuilder(); |
|
605 |
for (String s : CLASSPATH.fetchFrom(params).split("[ ;:]+")) { |
|
606 |
macroedPath.append(s); |
|
607 |
macroedPath.append(":"); |
|
608 |
} |
|
609 |
macroedPath.deleteCharAt(macroedPath.length() - 1); |
|
610 |
||
611 |
data.put("DEPLOY_APP_CLASSPATH", macroedPath.toString()); |
|
612 |
||
613 |
StringBuilder bundleDocumentTypes = new StringBuilder(); |
|
614 |
StringBuilder exportedTypes = new StringBuilder(); |
|
615 |
for (Map<String, ? super Object> |
|
616 |
fileAssociation : FILE_ASSOCIATIONS.fetchFrom(params)) { |
|
617 |
||
618 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(fileAssociation); |
|
619 |
||
620 |
if (extensions == null) { |
|
621 |
Log.verbose(I18N.getString( |
|
622 |
"message.creating-association-with-null-extension")); |
|
623 |
} |
|
624 |
||
625 |
List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fileAssociation); |
|
626 |
String itemContentType = MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) |
|
627 |
+ "." + ((extensions == null || extensions.isEmpty()) |
|
628 |
? "mime" : extensions.get(0)); |
|
629 |
String description = FA_DESCRIPTION.fetchFrom(fileAssociation); |
|
630 |
File icon = FA_ICON.fetchFrom(fileAssociation); //TODO FA_ICON_ICNS |
|
631 |
||
632 |
bundleDocumentTypes.append(" <dict>\n") |
|
633 |
.append(" <key>LSItemContentTypes</key>\n") |
|
634 |
.append(" <array>\n") |
|
635 |
.append(" <string>") |
|
636 |
.append(itemContentType) |
|
637 |
.append("</string>\n") |
|
638 |
.append(" </array>\n") |
|
639 |
.append("\n") |
|
640 |
.append(" <key>CFBundleTypeName</key>\n") |
|
641 |
.append(" <string>") |
|
642 |
.append(description) |
|
643 |
.append("</string>\n") |
|
644 |
.append("\n") |
|
645 |
.append(" <key>LSHandlerRank</key>\n") |
|
646 |
.append(" <string>Owner</string>\n") |
|
647 |
// TODO make a bundler arg |
|
648 |
.append("\n") |
|
649 |
.append(" <key>CFBundleTypeRole</key>\n") |
|
650 |
.append(" <string>Editor</string>\n") |
|
651 |
// TODO make a bundler arg |
|
652 |
.append("\n") |
|
653 |
.append(" <key>LSIsAppleDefaultForType</key>\n") |
|
654 |
.append(" <true/>\n") |
|
655 |
// TODO make a bundler arg |
|
656 |
.append("\n"); |
|
657 |
||
658 |
if (icon != null && icon.exists()) { |
|
659 |
bundleDocumentTypes |
|
660 |
.append(" <key>CFBundleTypeIconFile</key>\n") |
|
661 |
.append(" <string>") |
|
662 |
.append(icon.getName()) |
|
663 |
.append("</string>\n"); |
|
664 |
} |
|
665 |
bundleDocumentTypes.append(" </dict>\n"); |
|
666 |
||
667 |
exportedTypes.append(" <dict>\n") |
|
668 |
.append(" <key>UTTypeIdentifier</key>\n") |
|
669 |
.append(" <string>") |
|
670 |
.append(itemContentType) |
|
671 |
.append("</string>\n") |
|
672 |
.append("\n") |
|
673 |
.append(" <key>UTTypeDescription</key>\n") |
|
674 |
.append(" <string>") |
|
675 |
.append(description) |
|
676 |
.append("</string>\n") |
|
677 |
.append(" <key>UTTypeConformsTo</key>\n") |
|
678 |
.append(" <array>\n") |
|
679 |
.append(" <string>public.data</string>\n") |
|
680 |
//TODO expose this? |
|
681 |
.append(" </array>\n") |
|
682 |
.append("\n"); |
|
683 |
||
684 |
if (icon != null && icon.exists()) { |
|
685 |
exportedTypes.append(" <key>UTTypeIconFile</key>\n") |
|
686 |
.append(" <string>") |
|
687 |
.append(icon.getName()) |
|
688 |
.append("</string>\n") |
|
689 |
.append("\n"); |
|
690 |
} |
|
691 |
||
692 |
exportedTypes.append("\n") |
|
693 |
.append(" <key>UTTypeTagSpecification</key>\n") |
|
694 |
.append(" <dict>\n") |
|
695 |
// TODO expose via param? .append( |
|
696 |
// " <key>com.apple.ostype</key>\n"); |
|
697 |
// TODO expose via param? .append( |
|
698 |
// " <string>ABCD</string>\n") |
|
699 |
.append("\n"); |
|
700 |
||
701 |
if (extensions != null && !extensions.isEmpty()) { |
|
702 |
exportedTypes.append( |
|
703 |
" <key>public.filename-extension</key>\n") |
|
704 |
.append(" <array>\n"); |
|
705 |
||
706 |
for (String ext : extensions) { |
|
707 |
exportedTypes.append(" <string>") |
|
708 |
.append(ext) |
|
709 |
.append("</string>\n"); |
|
710 |
} |
|
711 |
exportedTypes.append(" </array>\n"); |
|
712 |
} |
|
713 |
if (mimeTypes != null && !mimeTypes.isEmpty()) { |
|
714 |
exportedTypes.append(" <key>public.mime-type</key>\n") |
|
715 |
.append(" <array>\n"); |
|
716 |
||
717 |
for (String mime : mimeTypes) { |
|
718 |
exportedTypes.append(" <string>") |
|
719 |
.append(mime) |
|
720 |
.append("</string>\n"); |
|
721 |
} |
|
722 |
exportedTypes.append(" </array>\n"); |
|
723 |
} |
|
724 |
exportedTypes.append(" </dict>\n") |
|
725 |
.append(" </dict>\n"); |
|
726 |
} |
|
727 |
String associationData; |
|
728 |
if (bundleDocumentTypes.length() > 0) { |
|
729 |
associationData = |
|
730 |
"\n <key>CFBundleDocumentTypes</key>\n <array>\n" |
|
731 |
+ bundleDocumentTypes.toString() |
|
732 |
+ " </array>\n\n" |
|
733 |
+ " <key>UTExportedTypeDeclarations</key>\n <array>\n" |
|
734 |
+ exportedTypes.toString() |
|
735 |
+ " </array>\n"; |
|
736 |
} else { |
|
737 |
associationData = ""; |
|
738 |
} |
|
739 |
data.put("DEPLOY_FILE_ASSOCIATIONS", associationData); |
|
740 |
||
741 |
||
742 |
Writer w = new BufferedWriter(new FileWriter(file)); |
|
743 |
w.write(preprocessTextResource( |
|
744 |
// BUNDLER_PREFIX + getConfig_InfoPlist(params).getName(), |
|
745 |
"package/Info.plist", |
|
746 |
I18N.getString("resource.app-info-plist"), |
|
747 |
TEMPLATE_INFO_PLIST_LITE, |
|
748 |
data, VERBOSE.fetchFrom(params), |
|
749 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params))); |
|
750 |
w.close(); |
|
751 |
} |
|
752 |
||
753 |
private void writePkgInfo(File file) throws IOException { |
|
754 |
//hardcoded as it does not seem we need to change it ever |
|
755 |
String signature = "????"; |
|
756 |
||
757 |
try (Writer out = new BufferedWriter(new FileWriter(file))) { |
|
758 |
out.write(OS_TYPE_CODE + signature); |
|
759 |
out.flush(); |
|
760 |
} |
|
761 |
} |
|
762 |
||
763 |
public static void addNewKeychain(Map<String, ? super Object> params) |
|
764 |
throws IOException, InterruptedException { |
|
765 |
if (Platform.getMajorVersion() < 10 || |
|
766 |
(Platform.getMajorVersion() == 10 && |
|
767 |
Platform.getMinorVersion() < 12)) { |
|
768 |
// we need this for OS X 10.12+ |
|
769 |
return; |
|
770 |
} |
|
771 |
||
772 |
String keyChain = SIGNING_KEYCHAIN.fetchFrom(params); |
|
773 |
if (keyChain == null || keyChain.isEmpty()) { |
|
774 |
return; |
|
775 |
} |
|
776 |
||
777 |
// get current keychain list |
|
778 |
String keyChainPath = new File (keyChain).getAbsolutePath().toString(); |
|
779 |
List<String> keychainList = new ArrayList<>(); |
|
780 |
int ret = IOUtils.getProcessOutput( |
|
781 |
keychainList, "security", "list-keychains"); |
|
782 |
if (ret != 0) { |
|
783 |
Log.error(I18N.getString("message.keychain.error")); |
|
784 |
return; |
|
785 |
} |
|
786 |
||
787 |
boolean contains = keychainList.stream().anyMatch( |
|
788 |
str -> str.trim().equals("\""+keyChainPath.trim()+"\"")); |
|
789 |
if (contains) { |
|
790 |
// keychain is already added in the search list |
|
791 |
return; |
|
792 |
} |
|
793 |
||
794 |
keyChains = new ArrayList<>(); |
|
795 |
// remove " |
|
796 |
keychainList.forEach((String s) -> { |
|
797 |
String path = s.trim(); |
|
798 |
if (path.startsWith("\"") && path.endsWith("\"")) { |
|
799 |
path = path.substring(1, path.length()-1); |
|
800 |
} |
|
801 |
keyChains.add(path); |
|
802 |
}); |
|
803 |
||
804 |
List<String> args = new ArrayList<>(); |
|
805 |
args.add("security"); |
|
806 |
args.add("list-keychains"); |
|
807 |
args.add("-s"); |
|
808 |
||
809 |
args.addAll(keyChains); |
|
810 |
args.add(keyChain); |
|
811 |
||
812 |
ProcessBuilder pb = new ProcessBuilder(args); |
|
813 |
IOUtils.exec(pb, false); |
|
814 |
} |
|
815 |
||
816 |
public static void restoreKeychainList(Map<String, ? super Object> params) |
|
817 |
throws IOException{ |
|
818 |
if (Platform.getMajorVersion() < 10 || |
|
819 |
(Platform.getMajorVersion() == 10 && |
|
820 |
Platform.getMinorVersion() < 12)) { |
|
821 |
// we need this for OS X 10.12+ |
|
822 |
return; |
|
823 |
} |
|
824 |
||
825 |
if (keyChains == null || keyChains.isEmpty()) { |
|
826 |
return; |
|
827 |
} |
|
828 |
||
829 |
List<String> args = new ArrayList<>(); |
|
830 |
args.add("security"); |
|
831 |
args.add("list-keychains"); |
|
832 |
args.add("-s"); |
|
833 |
||
834 |
args.addAll(keyChains); |
|
835 |
||
836 |
ProcessBuilder pb = new ProcessBuilder(args); |
|
837 |
IOUtils.exec(pb, false); |
|
838 |
} |
|
839 |
||
840 |
public static void signAppBundle( |
|
841 |
Map<String, ? super Object> params, Path appLocation, |
|
842 |
String signingIdentity, String identifierPrefix, |
|
843 |
String entitlementsFile, String inheritedEntitlements) |
|
844 |
throws IOException { |
|
845 |
AtomicReference<IOException> toThrow = new AtomicReference<>(); |
|
846 |
String appExecutable = "/Contents/MacOS/" + APP_NAME.fetchFrom(params); |
|
847 |
String keyChain = SIGNING_KEYCHAIN.fetchFrom(params); |
|
848 |
||
849 |
// sign all dylibs and jars |
|
850 |
Files.walk(appLocation) |
|
851 |
// fix permissions |
|
852 |
.peek(path -> { |
|
853 |
try { |
|
854 |
Set<PosixFilePermission> pfp = |
|
855 |
Files.getPosixFilePermissions(path); |
|
856 |
if (!pfp.contains(PosixFilePermission.OWNER_WRITE)) { |
|
857 |
pfp = EnumSet.copyOf(pfp); |
|
858 |
pfp.add(PosixFilePermission.OWNER_WRITE); |
|
859 |
Files.setPosixFilePermissions(path, pfp); |
|
860 |
} |
|
861 |
} catch (IOException e) { |
|
862 |
Log.debug(e); |
|
863 |
} |
|
864 |
}) |
|
865 |
.filter(p -> Files.isRegularFile(p) && |
|
866 |
!(p.toString().contains("/Contents/MacOS/libjli.dylib") |
|
867 |
|| p.toString().contains( |
|
868 |
"/Contents/MacOS/JavaAppletPlugin") |
|
869 |
|| p.toString().endsWith(appExecutable)) |
|
870 |
).forEach(p -> { |
|
871 |
//noinspection ThrowableResultOfMethodCallIgnored |
|
872 |
if (toThrow.get() != null) return; |
|
873 |
||
874 |
// If p is a symlink then skip the signing process. |
|
875 |
if (Files.isSymbolicLink(p)) { |
|
876 |
if (VERBOSE.fetchFrom(params)) { |
|
877 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
878 |
"message.ignoring.symlink"), p.toString())); |
|
879 |
} |
|
880 |
} |
|
881 |
else { |
|
882 |
List<String> args = new ArrayList<>(); |
|
883 |
args.addAll(Arrays.asList("codesign", |
|
884 |
"-s", signingIdentity, // sign with this key |
|
885 |
"--prefix", identifierPrefix, |
|
886 |
// use the identifier as a prefix |
|
887 |
"-vvvv")); |
|
888 |
if (entitlementsFile != null && |
|
889 |
(p.toString().endsWith(".jar") |
|
890 |
|| p.toString().endsWith(".dylib"))) { |
|
891 |
args.add("--entitlements"); |
|
892 |
args.add(entitlementsFile); // entitlements |
|
893 |
} else if (inheritedEntitlements != null && |
|
894 |
Files.isExecutable(p)) { |
|
895 |
args.add("--entitlements"); |
|
896 |
args.add(inheritedEntitlements); |
|
897 |
// inherited entitlements for executable processes |
|
898 |
} |
|
899 |
if (keyChain != null && !keyChain.isEmpty()) { |
|
900 |
args.add("--keychain"); |
|
901 |
args.add(keyChain); |
|
902 |
} |
|
903 |
args.add(p.toString()); |
|
904 |
||
905 |
try { |
|
906 |
Set<PosixFilePermission> oldPermissions = |
|
907 |
Files.getPosixFilePermissions(p); |
|
908 |
File f = p.toFile(); |
|
909 |
f.setWritable(true, true); |
|
910 |
||
911 |
ProcessBuilder pb = new ProcessBuilder(args); |
|
912 |
IOUtils.exec(pb, false); |
|
913 |
||
914 |
Files.setPosixFilePermissions(p, oldPermissions); |
|
915 |
} catch (IOException ioe) { |
|
916 |
toThrow.set(ioe); |
|
917 |
} |
|
918 |
} |
|
919 |
}); |
|
920 |
||
921 |
IOException ioe = toThrow.get(); |
|
922 |
if (ioe != null) { |
|
923 |
throw ioe; |
|
924 |
} |
|
925 |
||
926 |
// sign all plugins and frameworks |
|
927 |
Consumer<? super Path> signIdentifiedByPList = path -> { |
|
928 |
//noinspection ThrowableResultOfMethodCallIgnored |
|
929 |
if (toThrow.get() != null) return; |
|
930 |
||
931 |
try { |
|
932 |
List<String> args = new ArrayList<>(); |
|
933 |
args.addAll(Arrays.asList("codesign", |
|
934 |
"-s", signingIdentity, // sign with this key |
|
935 |
"--prefix", identifierPrefix, |
|
936 |
// use the identifier as a prefix |
|
937 |
"-vvvv")); |
|
938 |
if (keyChain != null && !keyChain.isEmpty()) { |
|
939 |
args.add("--keychain"); |
|
940 |
args.add(keyChain); |
|
941 |
} |
|
942 |
args.add(path.toString()); |
|
943 |
ProcessBuilder pb = new ProcessBuilder(args); |
|
944 |
IOUtils.exec(pb, false); |
|
945 |
||
946 |
args = new ArrayList<>(); |
|
947 |
args.addAll(Arrays.asList("codesign", |
|
948 |
"-s", signingIdentity, // sign with this key |
|
949 |
"--prefix", identifierPrefix, |
|
950 |
// use the identifier as a prefix |
|
951 |
"-vvvv")); |
|
952 |
if (keyChain != null && !keyChain.isEmpty()) { |
|
953 |
args.add("--keychain"); |
|
954 |
args.add(keyChain); |
|
955 |
} |
|
956 |
args.add(path.toString() |
|
957 |
+ "/Contents/_CodeSignature/CodeResources"); |
|
958 |
pb = new ProcessBuilder(args); |
|
959 |
IOUtils.exec(pb, false); |
|
960 |
} catch (IOException e) { |
|
961 |
toThrow.set(e); |
|
962 |
} |
|
963 |
}; |
|
964 |
||
965 |
Path pluginsPath = appLocation.resolve("Contents/PlugIns"); |
|
966 |
if (Files.isDirectory(pluginsPath)) { |
|
967 |
Files.list(pluginsPath) |
|
968 |
.forEach(signIdentifiedByPList); |
|
969 |
||
970 |
ioe = toThrow.get(); |
|
971 |
if (ioe != null) { |
|
972 |
throw ioe; |
|
973 |
} |
|
974 |
} |
|
975 |
Path frameworkPath = appLocation.resolve("Contents/Frameworks"); |
|
976 |
if (Files.isDirectory(frameworkPath)) { |
|
977 |
Files.list(frameworkPath) |
|
978 |
.forEach(signIdentifiedByPList); |
|
979 |
||
980 |
ioe = toThrow.get(); |
|
981 |
if (ioe != null) { |
|
982 |
throw ioe; |
|
983 |
} |
|
984 |
} |
|
985 |
||
986 |
// sign the app itself |
|
987 |
List<String> args = new ArrayList<>(); |
|
988 |
args.addAll(Arrays.asList("codesign", |
|
989 |
"-s", signingIdentity, // sign with this key |
|
990 |
"-vvvv")); // super verbose output |
|
991 |
if (entitlementsFile != null) { |
|
992 |
args.add("--entitlements"); |
|
993 |
args.add(entitlementsFile); // entitlements |
|
994 |
} |
|
995 |
if (keyChain != null && !keyChain.isEmpty()) { |
|
996 |
args.add("--keychain"); |
|
997 |
args.add(keyChain); |
|
998 |
} |
|
999 |
args.add(appLocation.toString()); |
|
1000 |
||
1001 |
ProcessBuilder pb = |
|
1002 |
new ProcessBuilder(args.toArray(new String[args.size()])); |
|
1003 |
IOUtils.exec(pb, false); |
|
1004 |
} |
|
1005 |
||
1006 |
} |