23 * questions.
24 */
25
26 package jdk.incubator.jpackage.internal;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.text.MessageFormat;
31 import java.util.*;
32
33 import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
34 import static jdk.incubator.jpackage.internal.MacAppBundler.*;
35 import static jdk.incubator.jpackage.internal.OverridableResource.createResource;
36
37 public class MacAppStoreBundler extends MacBaseInstallerBundler {
38
39 private static final ResourceBundle I18N = ResourceBundle.getBundle(
40 "jdk.incubator.jpackage.internal.resources.MacResources");
41
42 private static final String TEMPLATE_BUNDLE_ICON_HIDPI = "java.icns";
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 -> {
53 String result = MacBaseInstallerBundler.findKey(
54 "3rd Party Mac Developer Application: " +
55 SIGNING_KEY_USER.fetchFrom(params),
56 SIGNING_KEYCHAIN.fetchFrom(params),
57 VERBOSE.fetchFrom(params));
58 if (result != null) {
59 MacCertificate certificate = new MacCertificate(result);
60
61 if (!certificate.isValid()) {
62 Log.error(MessageFormat.format(
63 I18N.getString("error.certificate.expired"),
64 result));
65 }
66 }
77 String result = MacBaseInstallerBundler.findKey(
78 "3rd Party Mac Developer Installer: " +
79 SIGNING_KEY_USER.fetchFrom(params),
80 SIGNING_KEYCHAIN.fetchFrom(params),
81 VERBOSE.fetchFrom(params));
82
83 if (result != null) {
84 MacCertificate certificate = new MacCertificate(result);
85
86 if (!certificate.isValid()) {
87 Log.error(MessageFormat.format(
88 I18N.getString("error.certificate.expired"),
89 result));
90 }
91 }
92
93 return result;
94 },
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
111 public File bundle(Map<String, ? super Object> params,
112 File outdir) throws PackagerException {
113 Log.verbose(MessageFormat.format(I18N.getString(
114 "message.building-bundle"), APP_NAME.fetchFrom(params)));
115
116 IOUtils.writableOutputDir(outdir.toPath());
117
118 // first, load in some overrides
119 // icns needs @2 versions, so load in the @2 default
120 params.put(DEFAULT_ICNS_ICON.getID(), TEMPLATE_BUNDLE_ICON_HIDPI);
121
122 // now we create the app
123 File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
124 try {
125 appImageDir.mkdirs();
126
127 try {
128 MacAppImageBuilder.addNewKeychain(params);
129 } catch (InterruptedException e) {
130 Log.error(e.getMessage());
131 }
132 // first, make sure we don't use the local signing key
133 params.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null);
134 File appLocation = prepareAppBundle(params);
135
136 prepareEntitlements(params);
137
138 String signingIdentity =
139 MAC_APP_STORE_APP_SIGNING_KEY.fetchFrom(params);
140 String identifierPrefix =
141 BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params);
142 String entitlementsFile =
143 getConfig_Entitlements(params).toString();
144 String inheritEntitlements =
145 getConfig_Inherit_Entitlements(params).toString();
146
147 MacAppImageBuilder.signAppBundle(params, appLocation.toPath(),
148 signingIdentity, identifierPrefix,
149 entitlementsFile, inheritEntitlements);
150 MacAppImageBuilder.restoreKeychainList(params);
151
152 ProcessBuilder pb;
153
154 // create the final pkg file
155 File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
156 + INSTALLER_SUFFIX.fetchFrom(params)
157 + ".pkg");
158 outdir.mkdirs();
159
160 String installIdentify =
161 MAC_APP_STORE_PKG_SIGNING_KEY.fetchFrom(params);
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");
172 String keychainName = SIGNING_KEYCHAIN.fetchFrom(params);
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
181 IOUtils.exec(pb);
182 return finalPKG;
183 } catch (PackagerException pe) {
184 throw pe;
185 } catch (Exception ex) {
186 Log.verbose(ex);
187 throw new PackagerException(ex);
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 {
204 createResource(DEFAULT_ENTITLEMENTS, params)
205 .setCategory(
206 I18N.getString("resource.mac-app-store-entitlements"))
207 .setExternal(MAC_APP_STORE_ENTITLEMENTS.fetchFrom(params))
208 .saveToFile(getConfig_Entitlements(params));
209
210 createResource(DEFAULT_INHERIT_ENTITLEMENTS, params)
211 .setCategory(I18N.getString(
212 "resource.mac-app-store-inherit-entitlements"))
213 .saveToFile(getConfig_Entitlements(params));
214 }
215
216 ///////////////////////////////////////////////////////////////////////
217 // Implement Bundler
218 ///////////////////////////////////////////////////////////////////////
219
220 @Override
221 public String getName() {
222 return I18N.getString("store.bundler.name");
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)
232 throws ConfigException {
233 try {
|
23 * questions.
24 */
25
26 package jdk.incubator.jpackage.internal;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.text.MessageFormat;
31 import java.util.*;
32
33 import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
34 import static jdk.incubator.jpackage.internal.MacAppBundler.*;
35 import static jdk.incubator.jpackage.internal.OverridableResource.createResource;
36
37 public class MacAppStoreBundler extends MacBaseInstallerBundler {
38
39 private static final ResourceBundle I18N = ResourceBundle.getBundle(
40 "jdk.incubator.jpackage.internal.resources.MacResources");
41
42 private static final String TEMPLATE_BUNDLE_ICON_HIDPI = "java.icns";
43
44 public static final BundlerParamInfo<String> MAC_APP_STORE_APP_SIGNING_KEY =
45 new StandardBundlerParam<>(
46 "mac.signing-key-app",
47 String.class,
48 params -> {
49 String result = MacBaseInstallerBundler.findKey(
50 "3rd Party Mac Developer Application: " +
51 SIGNING_KEY_USER.fetchFrom(params),
52 SIGNING_KEYCHAIN.fetchFrom(params),
53 VERBOSE.fetchFrom(params));
54 if (result != null) {
55 MacCertificate certificate = new MacCertificate(result);
56
57 if (!certificate.isValid()) {
58 Log.error(MessageFormat.format(
59 I18N.getString("error.certificate.expired"),
60 result));
61 }
62 }
73 String result = MacBaseInstallerBundler.findKey(
74 "3rd Party Mac Developer Installer: " +
75 SIGNING_KEY_USER.fetchFrom(params),
76 SIGNING_KEYCHAIN.fetchFrom(params),
77 VERBOSE.fetchFrom(params));
78
79 if (result != null) {
80 MacCertificate certificate = new MacCertificate(result);
81
82 if (!certificate.isValid()) {
83 Log.error(MessageFormat.format(
84 I18N.getString("error.certificate.expired"),
85 result));
86 }
87 }
88
89 return result;
90 },
91 (s, p) -> s);
92
93 public static final BundlerParamInfo<String> INSTALLER_SUFFIX =
94 new StandardBundlerParam<> (
95 "mac.app-store.installerName.suffix",
96 String.class,
97 params -> "-MacAppStore",
98 (s, p) -> s);
99
100 public File bundle(Map<String, ? super Object> params,
101 File outdir) throws PackagerException {
102 Log.verbose(MessageFormat.format(I18N.getString(
103 "message.building-bundle"), APP_NAME.fetchFrom(params)));
104
105 IOUtils.writableOutputDir(outdir.toPath());
106
107 // first, load in some overrides
108 // icns needs @2 versions, so load in the @2 default
109 params.put(DEFAULT_ICNS_ICON.getID(), TEMPLATE_BUNDLE_ICON_HIDPI);
110
111 // now we create the app
112 File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
113 try {
114 appImageDir.mkdirs();
115
116 try {
117 MacAppImageBuilder.addNewKeychain(params);
118 } catch (InterruptedException e) {
119 Log.error(e.getMessage());
120 }
121 // first, make sure we don't use the local signing key
122 params.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null);
123 File appLocation = prepareAppBundle(params);
124
125 String signingIdentity =
126 MAC_APP_STORE_APP_SIGNING_KEY.fetchFrom(params);
127 String identifierPrefix =
128 BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params);
129
130 MacAppImageBuilder.signAppBundle(params, appLocation.toPath(),
131 signingIdentity, identifierPrefix);
132 MacAppImageBuilder.restoreKeychainList(params);
133
134 ProcessBuilder pb;
135
136 // create the final pkg file
137 File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
138 + INSTALLER_SUFFIX.fetchFrom(params)
139 + ".pkg");
140 outdir.mkdirs();
141
142 String installIdentify =
143 MAC_APP_STORE_PKG_SIGNING_KEY.fetchFrom(params);
144
145 List<String> buildOptions = new ArrayList<>();
146 buildOptions.add("productbuild");
147 buildOptions.add("--component");
148 buildOptions.add(appLocation.toString());
149 buildOptions.add("/Applications");
150 buildOptions.add("--sign");
151 buildOptions.add(installIdentify);
152 buildOptions.add("--product");
153 buildOptions.add(appLocation + "/Contents/Info.plist");
154 String keychainName = SIGNING_KEYCHAIN.fetchFrom(params);
155 if (keychainName != null && !keychainName.isEmpty()) {
156 buildOptions.add("--keychain");
157 buildOptions.add(keychainName);
158 }
159 buildOptions.add(finalPKG.getAbsolutePath());
160
161 pb = new ProcessBuilder(buildOptions);
162
163 IOUtils.exec(pb);
164 return finalPKG;
165 } catch (PackagerException pe) {
166 throw pe;
167 } catch (Exception ex) {
168 Log.verbose(ex);
169 throw new PackagerException(ex);
170 }
171 }
172
173 ///////////////////////////////////////////////////////////////////////
174 // Implement Bundler
175 ///////////////////////////////////////////////////////////////////////
176
177 @Override
178 public String getName() {
179 return I18N.getString("store.bundler.name");
180 }
181
182 @Override
183 public String getID() {
184 return "mac.appStore";
185 }
186
187 @Override
188 public boolean validate(Map<String, ? super Object> params)
189 throws ConfigException {
190 try {
|