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