author | herrick |
Wed, 16 Oct 2019 09:57:23 -0400 | |
branch | JDK-8200758-branch |
changeset 58647 | 2c43b89b1679 |
parent 58114 | 42df7de58e39 |
child 58762 | 0fe62353385b |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57096
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 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 |
|
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.text.MessageFormat; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Map; |
|
34 |
import java.util.Optional; |
|
35 |
import java.util.ResourceBundle; |
|
36 |
||
57039 | 37 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
38 |
import static jdk.jpackage.internal.MacAppBundler.*; |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
39 |
import static jdk.jpackage.internal.OverridableResource.createResource; |
57038 | 40 |
|
41 |
public class MacAppStoreBundler extends MacBaseInstallerBundler { |
|
42 |
||
57059 | 43 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
44 |
"jdk.jpackage.internal.resources.MacResources"); |
|
57038 | 45 |
|
57908
9a005146bc1c
8230191: Replace javacup logo with duke everywhere in jpackage
herrick
parents:
57554
diff
changeset
|
46 |
private static final String TEMPLATE_BUNDLE_ICON_HIDPI = "java.icns"; |
57038 | 47 |
private final static String DEFAULT_ENTITLEMENTS = |
48 |
"MacAppStore.entitlements"; |
|
49 |
private final static String DEFAULT_INHERIT_ENTITLEMENTS = |
|
50 |
"MacAppStore_Inherit.entitlements"; |
|
51 |
||
52 |
public static final BundlerParamInfo<String> MAC_APP_STORE_APP_SIGNING_KEY = |
|
53 |
new StandardBundlerParam<>( |
|
54 |
"mac.signing-key-app", |
|
55 |
String.class, |
|
56 |
params -> { |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
57 |
String result = MacBaseInstallerBundler.findKey( |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
58 |
"3rd Party Mac Developer Application: " + |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
59 |
SIGNING_KEY_USER.fetchFrom(params), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
60 |
SIGNING_KEYCHAIN.fetchFrom(params), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
61 |
VERBOSE.fetchFrom(params)); |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
62 |
if (result != null) { |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
63 |
MacCertificate certificate = new MacCertificate(result); |
57038 | 64 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
65 |
if (!certificate.isValid()) { |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
66 |
Log.error(MessageFormat.format( |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
67 |
I18N.getString("error.certificate.expired"), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
68 |
result)); |
57038 | 69 |
} |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
70 |
} |
57038 | 71 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
72 |
return result; |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
73 |
}, |
57038 | 74 |
(s, p) -> s); |
75 |
||
76 |
public static final BundlerParamInfo<String> MAC_APP_STORE_PKG_SIGNING_KEY = |
|
77 |
new StandardBundlerParam<>( |
|
78 |
"mac.signing-key-pkg", |
|
79 |
String.class, |
|
80 |
params -> { |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
81 |
String result = MacBaseInstallerBundler.findKey( |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
82 |
"3rd Party Mac Developer Installer: " + |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
83 |
SIGNING_KEY_USER.fetchFrom(params), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
84 |
SIGNING_KEYCHAIN.fetchFrom(params), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
85 |
VERBOSE.fetchFrom(params)); |
57038 | 86 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
87 |
if (result != null) { |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
88 |
MacCertificate certificate = new MacCertificate(result); |
57038 | 89 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
90 |
if (!certificate.isValid()) { |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
91 |
Log.error(MessageFormat.format( |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
92 |
I18N.getString("error.certificate.expired"), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
93 |
result)); |
57038 | 94 |
} |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
95 |
} |
57038 | 96 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
97 |
return result; |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
98 |
}, |
57038 | 99 |
(s, p) -> s); |
100 |
||
101 |
public static final StandardBundlerParam<File> MAC_APP_STORE_ENTITLEMENTS = |
|
102 |
new StandardBundlerParam<>( |
|
103 |
Arguments.CLIOptions.MAC_APP_STORE_ENTITLEMENTS.getId(), |
|
104 |
File.class, |
|
105 |
params -> null, |
|
106 |
(s, p) -> new File(s)); |
|
107 |
||
108 |
public static final BundlerParamInfo<String> INSTALLER_SUFFIX = |
|
109 |
new StandardBundlerParam<> ( |
|
110 |
"mac.app-store.installerName.suffix", |
|
111 |
String.class, |
|
112 |
params -> "-MacAppStore", |
|
113 |
(s, p) -> s); |
|
114 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
115 |
public File bundle(Map<String, ? super Object> params, |
57140 | 116 |
File outdir) throws PackagerException { |
57038 | 117 |
Log.verbose(MessageFormat.format(I18N.getString( |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
118 |
"message.building-bundle"), APP_NAME.fetchFrom(params))); |
57407 | 119 |
|
120 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 121 |
|
122 |
// first, load in some overrides |
|
123 |
// icns needs @2 versions, so load in the @2 default |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
124 |
params.put(DEFAULT_ICNS_ICON.getID(), TEMPLATE_BUNDLE_ICON_HIDPI); |
57038 | 125 |
|
126 |
// now we create the app |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
127 |
File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params); |
57038 | 128 |
try { |
129 |
appImageDir.mkdirs(); |
|
130 |
||
131 |
try { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
132 |
MacAppImageBuilder.addNewKeychain(params); |
57038 | 133 |
} catch (InterruptedException e) { |
134 |
Log.error(e.getMessage()); |
|
135 |
} |
|
136 |
// first, make sure we don't use the local signing key |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
137 |
params.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null); |
57554 | 138 |
File appLocation = prepareAppBundle(params); |
57038 | 139 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
140 |
prepareEntitlements(params); |
57038 | 141 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
142 |
String signingIdentity = |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
143 |
MAC_APP_STORE_APP_SIGNING_KEY.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
144 |
String identifierPrefix = |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
145 |
BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
146 |
String entitlementsFile = |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
147 |
getConfig_Entitlements(params).toString(); |
57038 | 148 |
String inheritEntitlements = |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
149 |
getConfig_Inherit_Entitlements(params).toString(); |
57038 | 150 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
151 |
MacAppImageBuilder.signAppBundle(params, appLocation.toPath(), |
57038 | 152 |
signingIdentity, identifierPrefix, |
153 |
entitlementsFile, inheritEntitlements); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
154 |
MacAppImageBuilder.restoreKeychainList(params); |
57038 | 155 |
|
156 |
ProcessBuilder pb; |
|
157 |
||
158 |
// create the final pkg file |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
159 |
File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params) |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
160 |
+ INSTALLER_SUFFIX.fetchFrom(params) |
57038 | 161 |
+ ".pkg"); |
162 |
outdir.mkdirs(); |
|
163 |
||
164 |
String installIdentify = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
165 |
MAC_APP_STORE_PKG_SIGNING_KEY.fetchFrom(params); |
57038 | 166 |
|
167 |
List<String> buildOptions = new ArrayList<>(); |
|
168 |
buildOptions.add("productbuild"); |
|
169 |
buildOptions.add("--component"); |
|
170 |
buildOptions.add(appLocation.toString()); |
|
171 |
buildOptions.add("/Applications"); |
|
172 |
buildOptions.add("--sign"); |
|
173 |
buildOptions.add(installIdentify); |
|
174 |
buildOptions.add("--product"); |
|
175 |
buildOptions.add(appLocation + "/Contents/Info.plist"); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
176 |
String keychainName = SIGNING_KEYCHAIN.fetchFrom(params); |
57038 | 177 |
if (keychainName != null && !keychainName.isEmpty()) { |
178 |
buildOptions.add("--keychain"); |
|
179 |
buildOptions.add(keychainName); |
|
180 |
} |
|
181 |
buildOptions.add(finalPKG.getAbsolutePath()); |
|
182 |
||
183 |
pb = new ProcessBuilder(buildOptions); |
|
184 |
||
57391 | 185 |
IOUtils.exec(pb); |
57038 | 186 |
return finalPKG; |
57140 | 187 |
} catch (PackagerException pe) { |
188 |
throw pe; |
|
57038 | 189 |
} catch (Exception ex) { |
190 |
Log.verbose(ex); |
|
57140 | 191 |
throw new PackagerException(ex); |
57038 | 192 |
} |
193 |
} |
|
194 |
||
195 |
private File getConfig_Entitlements(Map<String, ? super Object> params) { |
|
196 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
197 |
APP_NAME.fetchFrom(params) + ".entitlements"); |
|
198 |
} |
|
199 |
||
200 |
private File getConfig_Inherit_Entitlements( |
|
201 |
Map<String, ? super Object> params) { |
|
202 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
203 |
APP_NAME.fetchFrom(params) + "_Inherit.entitlements"); |
|
204 |
} |
|
205 |
||
206 |
private void prepareEntitlements(Map<String, ? super Object> params) |
|
207 |
throws IOException { |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
208 |
createResource(DEFAULT_ENTITLEMENTS, params) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
209 |
.setCategory( |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
210 |
I18N.getString("resource.mac-app-store-entitlements")) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
211 |
.setExternal(MAC_APP_STORE_ENTITLEMENTS.fetchFrom(params)) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
212 |
.saveToFile(getConfig_Entitlements(params)); |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
213 |
|
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
214 |
createResource(DEFAULT_INHERIT_ENTITLEMENTS, params) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
215 |
.setCategory(I18N.getString( |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
216 |
"resource.mac-app-store-inherit-entitlements")) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
217 |
.saveToFile(getConfig_Entitlements(params)); |
57038 | 218 |
} |
219 |
||
220 |
/////////////////////////////////////////////////////////////////////// |
|
221 |
// Implement Bundler |
|
222 |
/////////////////////////////////////////////////////////////////////// |
|
223 |
||
224 |
@Override |
|
225 |
public String getName() { |
|
57059 | 226 |
return I18N.getString("store.bundler.name"); |
57038 | 227 |
} |
228 |
||
229 |
@Override |
|
230 |
public String getID() { |
|
231 |
return "mac.appStore"; |
|
232 |
} |
|
233 |
||
234 |
@Override |
|
235 |
public boolean validate(Map<String, ? super Object> params) |
|
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
236 |
throws ConfigException { |
57038 | 237 |
try { |
238 |
if (params == null) { |
|
239 |
throw new ConfigException( |
|
240 |
I18N.getString("error.parameters-null"), |
|
241 |
I18N.getString("error.parameters-null.advice")); |
|
242 |
} |
|
243 |
||
244 |
// hdiutil is always available so there's no need to test for |
|
245 |
// availability. |
|
246 |
// run basic validation to ensure requirements are met |
|
247 |
||
248 |
// we are not interested in return code, only possible exception |
|
249 |
validateAppImageAndBundeler(params); |
|
250 |
||
251 |
// reject explicitly set to not sign |
|
252 |
if (!Optional.ofNullable(MacAppImageBuilder. |
|
253 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { |
|
254 |
throw new ConfigException( |
|
255 |
I18N.getString("error.must-sign-app-store"), |
|
256 |
I18N.getString("error.must-sign-app-store.advice")); |
|
257 |
} |
|
258 |
||
259 |
// make sure we have settings for signatures |
|
260 |
if (MAC_APP_STORE_APP_SIGNING_KEY.fetchFrom(params) == null) { |
|
261 |
throw new ConfigException( |
|
262 |
I18N.getString("error.no-app-signing-key"), |
|
263 |
I18N.getString("error.no-app-signing-key.advice")); |
|
264 |
} |
|
265 |
if (MAC_APP_STORE_PKG_SIGNING_KEY.fetchFrom(params) == null) { |
|
266 |
throw new ConfigException( |
|
267 |
I18N.getString("error.no-pkg-signing-key"), |
|
268 |
I18N.getString("error.no-pkg-signing-key.advice")); |
|
269 |
} |
|
270 |
||
271 |
// things we could check... |
|
272 |
// check the icons, make sure it has hidpi icons |
|
273 |
// check the category, |
|
274 |
// make sure it fits in the list apple has provided |
|
275 |
// validate bundle identifier is reverse dns |
|
276 |
// check for \a+\.\a+\.. |
|
277 |
||
278 |
return true; |
|
279 |
} catch (RuntimeException re) { |
|
280 |
if (re.getCause() instanceof ConfigException) { |
|
281 |
throw (ConfigException) re.getCause(); |
|
282 |
} else { |
|
283 |
throw new ConfigException(re); |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
@Override |
|
289 |
public File execute(Map<String, ? super Object> params, |
|
57140 | 290 |
File outputParentDir) throws PackagerException { |
57038 | 291 |
return bundle(params, outputParentDir); |
292 |
} |
|
293 |
||
294 |
@Override |
|
57150 | 295 |
public boolean supported(boolean runtimeInstaller) { |
57256 | 296 |
// return (!runtimeInstaller && |
297 |
// Platform.getPlatform() == Platform.MAC); |
|
298 |
return false; // mac-app-store not yet supported |
|
57038 | 299 |
} |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
300 |
|
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
301 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
302 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
303 |
return false; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
304 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
305 |
|
57038 | 306 |
} |