57038
|
1 |
/*
|
|
2 |
* Copyright (c) 2014, 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.AbstractBundler;
|
|
29 |
import jdk.jpackage.internal.BundlerParamInfo;
|
|
30 |
import jdk.jpackage.internal.StandardBundlerParam;
|
|
31 |
import jdk.jpackage.internal.Arguments;
|
|
32 |
import jdk.jpackage.internal.Log;
|
|
33 |
import jdk.jpackage.internal.ConfigException;
|
|
34 |
import jdk.jpackage.internal.IOUtils;
|
|
35 |
import jdk.jpackage.internal.Platform;
|
|
36 |
import jdk.jpackage.internal.UnsupportedPlatformException;
|
57038
|
37 |
|
|
38 |
import java.io.ByteArrayOutputStream;
|
|
39 |
import java.io.File;
|
|
40 |
import java.io.IOException;
|
|
41 |
import java.io.PrintStream;
|
|
42 |
import java.nio.file.Files;
|
|
43 |
import java.text.MessageFormat;
|
|
44 |
import java.util.ArrayList;
|
|
45 |
import java.util.Arrays;
|
|
46 |
import java.util.Collection;
|
|
47 |
import java.util.LinkedHashSet;
|
|
48 |
import java.util.List;
|
|
49 |
import java.util.Map;
|
|
50 |
import java.util.ResourceBundle;
|
|
51 |
import java.util.regex.Matcher;
|
|
52 |
import java.util.regex.Pattern;
|
|
53 |
|
57039
|
54 |
import static jdk.jpackage.internal.StandardBundlerParam.*;
|
57038
|
55 |
|
|
56 |
public abstract class MacBaseInstallerBundler extends AbstractBundler {
|
|
57 |
|
57059
|
58 |
private static final ResourceBundle I18N = ResourceBundle.getBundle(
|
|
59 |
"jdk.jpackage.internal.resources.MacResources");
|
57038
|
60 |
|
|
61 |
// This could be generalized more to be for any type of Image Bundler
|
|
62 |
public static final BundlerParamInfo<MacAppBundler> APP_BUNDLER =
|
|
63 |
new StandardBundlerParam<>(
|
|
64 |
I18N.getString("param.app-bundler.name"),
|
|
65 |
I18N.getString("param.app-bundle.description"),
|
|
66 |
"mac.app.bundler",
|
|
67 |
MacAppBundler.class,
|
|
68 |
params -> new MacAppBundler(),
|
|
69 |
(s, p) -> null);
|
|
70 |
|
|
71 |
public final BundlerParamInfo<File> APP_IMAGE_BUILD_ROOT =
|
|
72 |
new StandardBundlerParam<>(
|
|
73 |
I18N.getString("param.app-image-build-root.name"),
|
|
74 |
I18N.getString("param.app-image-build-root.description"),
|
|
75 |
"mac.app.imageRoot",
|
|
76 |
File.class,
|
|
77 |
params -> {
|
|
78 |
File imageDir = IMAGES_ROOT.fetchFrom(params);
|
|
79 |
if (!imageDir.exists()) imageDir.mkdirs();
|
|
80 |
try {
|
|
81 |
return Files.createTempDirectory(
|
|
82 |
imageDir.toPath(), "image-").toFile();
|
|
83 |
} catch (IOException e) {
|
|
84 |
return new File(imageDir, getID()+ ".image");
|
|
85 |
}
|
|
86 |
},
|
|
87 |
(s, p) -> new File(s));
|
|
88 |
|
|
89 |
public static final BundlerParamInfo<File> CONFIG_ROOT =
|
|
90 |
new StandardBundlerParam<>(
|
|
91 |
I18N.getString("param.config-root.name"),
|
|
92 |
I18N.getString("param.config-root.description"),
|
|
93 |
"configRoot",
|
|
94 |
File.class,
|
|
95 |
params -> {
|
|
96 |
File imagesRoot =
|
|
97 |
new File(BUILD_ROOT.fetchFrom(params), "macosx");
|
|
98 |
imagesRoot.mkdirs();
|
|
99 |
return imagesRoot;
|
|
100 |
},
|
|
101 |
(s, p) -> null);
|
|
102 |
|
|
103 |
public static final BundlerParamInfo<String> SIGNING_KEY_USER =
|
|
104 |
new StandardBundlerParam<>(
|
|
105 |
I18N.getString("param.signing-key-name.name"),
|
|
106 |
I18N.getString("param.signing-key-name.description"),
|
|
107 |
Arguments.CLIOptions.MAC_SIGNING_KEY_NAME.getId(),
|
|
108 |
String.class,
|
|
109 |
params -> "",
|
|
110 |
null);
|
|
111 |
|
|
112 |
public static final BundlerParamInfo<String> SIGNING_KEYCHAIN =
|
|
113 |
new StandardBundlerParam<>(
|
|
114 |
I18N.getString("param.signing-keychain.name"),
|
|
115 |
I18N.getString("param.signing-keychain.description"),
|
|
116 |
Arguments.CLIOptions.MAC_SIGNING_KEYCHAIN.getId(),
|
|
117 |
String.class,
|
|
118 |
params -> "",
|
|
119 |
null);
|
|
120 |
|
|
121 |
public static final BundlerParamInfo<String> INSTALLER_NAME =
|
|
122 |
new StandardBundlerParam<> (
|
|
123 |
I18N.getString("param.installer-name.name"),
|
|
124 |
I18N.getString("param.installer-name.description"),
|
|
125 |
"mac.installerName",
|
|
126 |
String.class,
|
|
127 |
params -> {
|
|
128 |
String nm = APP_NAME.fetchFrom(params);
|
|
129 |
if (nm == null) return null;
|
|
130 |
|
|
131 |
String version = VERSION.fetchFrom(params);
|
|
132 |
if (version == null) {
|
|
133 |
return nm;
|
|
134 |
} else {
|
|
135 |
return nm + "-" + version;
|
|
136 |
}
|
|
137 |
},
|
|
138 |
(s, p) -> s);
|
|
139 |
|
|
140 |
protected void validateAppImageAndBundeler(
|
|
141 |
Map<String, ? super Object> params)
|
|
142 |
throws ConfigException, UnsupportedPlatformException {
|
|
143 |
if (PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
|
|
144 |
File applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
|
|
145 |
if (!applicationImage.exists()) {
|
|
146 |
throw new ConfigException(
|
|
147 |
MessageFormat.format(I18N.getString(
|
|
148 |
"message.app-image-dir-does-not-exist"),
|
|
149 |
PREDEFINED_APP_IMAGE.getID(),
|
|
150 |
applicationImage.toString()),
|
|
151 |
MessageFormat.format(I18N.getString(
|
|
152 |
"message.app-image-dir-does-not-exist.advice"),
|
|
153 |
PREDEFINED_APP_IMAGE.getID()));
|
|
154 |
}
|
|
155 |
if (APP_NAME.fetchFrom(params) == null) {
|
|
156 |
throw new ConfigException(
|
|
157 |
I18N.getString("message.app-image-requires-app-name"),
|
|
158 |
I18N.getString(
|
|
159 |
"message.app-image-requires-app-name.advice"));
|
|
160 |
}
|
|
161 |
if (IDENTIFIER.fetchFrom(params) == null) {
|
|
162 |
throw new ConfigException(
|
|
163 |
I18N.getString("message.app-image-requires-identifier"),
|
|
164 |
I18N.getString(
|
|
165 |
"message.app-image-requires-identifier.advice"));
|
|
166 |
}
|
|
167 |
} else {
|
|
168 |
APP_BUNDLER.fetchFrom(params).doValidate(params);
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
protected File prepareAppBundle(
|
|
173 |
Map<String, ? super Object> p, boolean pkg) {
|
|
174 |
File predefinedImage = StandardBundlerParam.getPredefinedAppImage(p);
|
|
175 |
if (predefinedImage != null) {
|
|
176 |
return predefinedImage;
|
|
177 |
}
|
|
178 |
File appImageRoot = APP_IMAGE_BUILD_ROOT.fetchFrom(p);
|
|
179 |
if (pkg) {
|
|
180 |
// create pkg in dmg
|
|
181 |
return new MacPkgBundler().bundle(p, appImageRoot);
|
|
182 |
} else {
|
|
183 |
return APP_BUNDLER.fetchFrom(p).doBundle(p, appImageRoot, true);
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
@Override
|
|
188 |
public Collection<BundlerParamInfo<?>> getBundleParameters() {
|
|
189 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
|
|
190 |
|
|
191 |
results.addAll(MacAppBundler.getAppBundleParameters());
|
|
192 |
results.addAll(Arrays.asList(
|
|
193 |
APP_BUNDLER,
|
|
194 |
CONFIG_ROOT,
|
|
195 |
APP_IMAGE_BUILD_ROOT,
|
|
196 |
PREDEFINED_APP_IMAGE
|
|
197 |
));
|
|
198 |
|
|
199 |
return results;
|
|
200 |
}
|
|
201 |
|
|
202 |
@Override
|
|
203 |
public String getBundleType() {
|
|
204 |
return "INSTALLER";
|
|
205 |
}
|
|
206 |
|
|
207 |
public static String findKey(String key, String keychainName,
|
|
208 |
boolean verbose) {
|
|
209 |
if (Platform.getPlatform() != Platform.MAC) {
|
|
210 |
return null;
|
|
211 |
}
|
|
212 |
|
|
213 |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
214 |
PrintStream ps = new PrintStream(baos)) {
|
|
215 |
List<String> searchOptions = new ArrayList<>();
|
|
216 |
searchOptions.add("security");
|
|
217 |
searchOptions.add("find-certificate");
|
|
218 |
searchOptions.add("-c");
|
|
219 |
searchOptions.add(key);
|
|
220 |
searchOptions.add("-a");
|
|
221 |
if (keychainName != null && !keychainName.isEmpty()) {
|
|
222 |
searchOptions.add(keychainName);
|
|
223 |
}
|
|
224 |
|
|
225 |
ProcessBuilder pb = new ProcessBuilder(searchOptions);
|
|
226 |
|
|
227 |
IOUtils.exec(pb, verbose, false, ps);
|
|
228 |
Pattern p = Pattern.compile("\"alis\"<blob>=\"([^\"]+)\"");
|
|
229 |
Matcher m = p.matcher(baos.toString());
|
|
230 |
if (!m.find()) {
|
|
231 |
Log.error("Did not find a key matching '" + key + "'");
|
|
232 |
return null;
|
|
233 |
}
|
|
234 |
String matchedKey = m.group(1);
|
|
235 |
if (m.find()) {
|
|
236 |
Log.error("Found more than one key matching '" + key + "'");
|
|
237 |
return null;
|
|
238 |
}
|
|
239 |
Log.debug("Using key '" + matchedKey + "'");
|
|
240 |
return matchedKey;
|
|
241 |
} catch (IOException ioe) {
|
|
242 |
Log.verbose(ioe);
|
|
243 |
return null;
|
|
244 |
}
|
|
245 |
}
|
|
246 |
}
|