author | herrick |
Fri, 14 Jun 2019 12:04:12 -0400 | |
branch | JDK-8200758-branch |
changeset 57407 | 2c14fbeff1dc |
parent 57404 | a477b26bf888 |
child 57414 | 6eda749d3117 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57103
diff
changeset
|
2 |
* Copyright (c) 2012, 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.*; |
|
29 |
import java.nio.charset.Charset; |
|
30 |
import java.nio.file.Files; |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
31 |
import java.nio.file.Paths; |
57038 | 32 |
import java.text.MessageFormat; |
33 |
import java.util.*; |
|
34 |
import java.util.regex.Pattern; |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
35 |
import javax.xml.stream.XMLOutputFactory; |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
36 |
import javax.xml.stream.XMLStreamException; |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
37 |
import javax.xml.stream.XMLStreamWriter; |
57038 | 38 |
|
57039 | 39 |
import static jdk.jpackage.internal.WindowsBundlerParam.*; |
57038 | 40 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
41 |
/** |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
42 |
* WinMsiBundler |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
43 |
* |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
44 |
* Produces .msi installer from application image. Uses WiX Toolkit to build |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
45 |
* .msi installer. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
46 |
* <p> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
47 |
* {@link #execute} method creates a number of source files with the description |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
48 |
* of installer to be processed by WiX tools. Generated source files are stored |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
49 |
* in "config" subdirectory next to "app" subdirectory in the root work |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
50 |
* directory. The following WiX source files are generated: |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
51 |
* <ul> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
52 |
* <li>main.wxs. Main source file with the installer description |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
53 |
* <li>bundle.wxi. Source file with application and Java run-time directory tree |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
54 |
* description. This source file is included from main.wxs |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
55 |
* <li>icons.wxi. Source file with the list of icons used by the application. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
56 |
* This source file is included from main.wxs |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
57 |
* </ul> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
58 |
* <p> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
59 |
* main.wxs file is a copy of main.wxs resource from |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
60 |
* jdk.jpackage.internal.resources package. It is parametrized with the |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
61 |
* following WiX variables: |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
62 |
* <ul> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
63 |
* <li>JpAppName. Name of the application. Set to the value of --name command |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
64 |
* line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
65 |
* <li>JpAppVersion. Version of the application. Set to the value of |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
66 |
* --app-version command line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
67 |
* <li>JpAppVendor. Vendor of the application. Set to the value of --vendor |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
68 |
* command line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
69 |
* <li>JpAppDescription. Description of the application. Set to the value of |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
70 |
* --description command line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
71 |
* <li>JpProductCode. Set to product code UUID of the application. Random value |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
72 |
* generated by jpackage every time {@link #execute} method is called |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
73 |
* <li>JpProductUpgradeCode. Set to upgrade code UUID of the application. Random |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
74 |
* value generated by jpackage every time {@link #execute} method is called if |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
75 |
* --win-upgrade-uuid command line option is not specified. Otherwise this |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
76 |
* variable is set to the value of --win-upgrade-uuid command line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
77 |
* <li>JpAllowDowngrades. Set to "yes" if --win-upgrade-uuid command line option |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
78 |
* was specified. Undefined otherwise |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
79 |
* <li>JpLicenseRtf. Set to the value of --license-file command line option. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
80 |
* Undefined is --license-file command line option was not specified |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
81 |
* <li>JpInstallDirChooser. Set to "yes" if --win-dir-chooser command line |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
82 |
* option was specified. Undefined otherwise |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
83 |
* <li>JpConfigDir. Absolute path to the directory with generated WiX source |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
84 |
* files. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
85 |
* <li>JpIsSystemWide. Set to "yes" if --win-per-user-install command line |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
86 |
* option was not specified. Undefined otherwise |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
87 |
* <li>JpWixVersion36OrNewer. Set to "yes" if WiX Toolkit v3.6 or newer is used. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
88 |
* Undefined otherwise |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
89 |
* </ul> |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
90 |
*/ |
57038 | 91 |
public class WinMsiBundler extends AbstractBundler { |
92 |
||
57059 | 93 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
94 |
"jdk.jpackage.internal.resources.WinResources"); |
|
57038 | 95 |
|
96 |
public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER = |
|
97 |
new WindowsBundlerParam<>( |
|
98 |
"win.app.bundler", |
|
99 |
WinAppBundler.class, |
|
100 |
params -> new WinAppBundler(), |
|
101 |
null); |
|
102 |
||
103 |
public static final BundlerParamInfo<Boolean> CAN_USE_WIX36 = |
|
104 |
new WindowsBundlerParam<>( |
|
105 |
"win.msi.canUseWix36", |
|
106 |
Boolean.class, |
|
107 |
params -> false, |
|
108 |
(s, p) -> Boolean.valueOf(s)); |
|
109 |
||
110 |
public static final BundlerParamInfo<File> MSI_IMAGE_DIR = |
|
111 |
new WindowsBundlerParam<>( |
|
112 |
"win.msi.imageDir", |
|
113 |
File.class, |
|
114 |
params -> { |
|
115 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
|
116 |
if (!imagesRoot.exists()) imagesRoot.mkdirs(); |
|
117 |
return new File(imagesRoot, "win-msi.image"); |
|
118 |
}, |
|
119 |
(s, p) -> null); |
|
120 |
||
121 |
public static final BundlerParamInfo<File> WIN_APP_IMAGE = |
|
122 |
new WindowsBundlerParam<>( |
|
123 |
"win.app.image", |
|
124 |
File.class, |
|
125 |
null, |
|
126 |
(s, p) -> null); |
|
127 |
||
128 |
public static final StandardBundlerParam<Boolean> MSI_SYSTEM_WIDE = |
|
129 |
new StandardBundlerParam<>( |
|
130 |
Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(), |
|
131 |
Boolean.class, |
|
132 |
params -> true, // MSIs default to system wide |
|
133 |
// valueOf(null) is false, |
|
134 |
// and we actually do want null |
|
135 |
(s, p) -> (s == null || "null".equalsIgnoreCase(s))? null |
|
136 |
: Boolean.valueOf(s) |
|
137 |
); |
|
138 |
||
139 |
||
140 |
public static final StandardBundlerParam<String> PRODUCT_VERSION = |
|
141 |
new StandardBundlerParam<>( |
|
142 |
"win.msi.productVersion", |
|
143 |
String.class, |
|
144 |
VERSION::fetchFrom, |
|
145 |
(s, p) -> s |
|
146 |
); |
|
147 |
||
148 |
public static final BundlerParamInfo<UUID> UPGRADE_UUID = |
|
149 |
new WindowsBundlerParam<>( |
|
57062
044e7a644ee3
8214575: Exe installers will install application to already existing instalation
herrick
parents:
57059
diff
changeset
|
150 |
Arguments.CLIOptions.WIN_UPGRADE_UUID.getId(), |
57038 | 151 |
UUID.class, |
57062
044e7a644ee3
8214575: Exe installers will install application to already existing instalation
herrick
parents:
57059
diff
changeset
|
152 |
params -> UUID.randomUUID(), |
57038 | 153 |
(s, p) -> UUID.fromString(s)); |
154 |
||
155 |
private static final String TOOL_CANDLE = "candle.exe"; |
|
156 |
private static final String TOOL_LIGHT = "light.exe"; |
|
157 |
// autodetect just v3.7, v3.8, 3.9, 3.10 and 3.11 |
|
158 |
private static final String AUTODETECT_DIRS = |
|
159 |
";C:\\Program Files (x86)\\WiX Toolset v3.11\\bin;" |
|
160 |
+ "C:\\Program Files\\WiX Toolset v3.11\\bin;" |
|
161 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.10\\bin;" |
|
162 |
+ "C:\\Program Files\\WiX Toolset v3.10\\bin;" |
|
163 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.9\\bin;" |
|
164 |
+ "C:\\Program Files\\WiX Toolset v3.9\\bin;" |
|
165 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.8\\bin;" |
|
166 |
+ "C:\\Program Files\\WiX Toolset v3.8\\bin;" |
|
167 |
+ "C:\\Program Files (x86)\\WiX Toolset v3.7\\bin;" |
|
168 |
+ "C:\\Program Files\\WiX Toolset v3.7\\bin"; |
|
169 |
||
170 |
public static final BundlerParamInfo<String> TOOL_CANDLE_EXECUTABLE = |
|
171 |
new WindowsBundlerParam<>( |
|
172 |
"win.msi.candle.exe", |
|
173 |
String.class, |
|
174 |
params -> { |
|
175 |
for (String dirString : (System.getenv("PATH") + |
|
176 |
AUTODETECT_DIRS).split(";")) { |
|
177 |
File f = new File(dirString.replace("\"", ""), TOOL_CANDLE); |
|
178 |
if (f.isFile()) { |
|
179 |
return f.toString(); |
|
180 |
} |
|
181 |
} |
|
182 |
return null; |
|
183 |
}, |
|
184 |
null); |
|
185 |
||
186 |
public static final BundlerParamInfo<String> TOOL_LIGHT_EXECUTABLE = |
|
187 |
new WindowsBundlerParam<>( |
|
188 |
"win.msi.light.exe", |
|
189 |
String.class, |
|
190 |
params -> { |
|
191 |
for (String dirString : (System.getenv("PATH") + |
|
192 |
AUTODETECT_DIRS).split(";")) { |
|
193 |
File f = new File(dirString.replace("\"", ""), TOOL_LIGHT); |
|
194 |
if (f.isFile()) { |
|
195 |
return f.toString(); |
|
196 |
} |
|
197 |
} |
|
198 |
return null; |
|
199 |
}, |
|
200 |
null); |
|
201 |
||
202 |
public static final StandardBundlerParam<Boolean> MENU_HINT = |
|
203 |
new WindowsBundlerParam<>( |
|
204 |
Arguments.CLIOptions.WIN_MENU_HINT.getId(), |
|
205 |
Boolean.class, |
|
206 |
params -> false, |
|
207 |
// valueOf(null) is false, |
|
208 |
// and we actually do want null in some cases |
|
209 |
(s, p) -> (s == null || |
|
210 |
"null".equalsIgnoreCase(s))? true : Boolean.valueOf(s) |
|
211 |
); |
|
212 |
||
213 |
public static final StandardBundlerParam<Boolean> SHORTCUT_HINT = |
|
214 |
new WindowsBundlerParam<>( |
|
215 |
Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(), |
|
216 |
Boolean.class, |
|
217 |
params -> false, |
|
218 |
// valueOf(null) is false, |
|
219 |
// and we actually do want null in some cases |
|
220 |
(s, p) -> (s == null || |
|
221 |
"null".equalsIgnoreCase(s))? false : Boolean.valueOf(s) |
|
222 |
); |
|
223 |
||
224 |
@Override |
|
225 |
public String getName() { |
|
57059 | 226 |
return I18N.getString("msi.bundler.name"); |
57038 | 227 |
} |
228 |
||
229 |
@Override |
|
230 |
public String getDescription() { |
|
57059 | 231 |
return I18N.getString("msi.bundler.description"); |
57038 | 232 |
} |
233 |
||
234 |
@Override |
|
235 |
public String getID() { |
|
236 |
return "msi"; |
|
237 |
} |
|
238 |
||
239 |
@Override |
|
240 |
public String getBundleType() { |
|
241 |
return "INSTALLER"; |
|
242 |
} |
|
243 |
||
244 |
@Override |
|
245 |
public Collection<BundlerParamInfo<?>> getBundleParameters() { |
|
246 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>(); |
|
247 |
results.addAll(WinAppBundler.getAppBundleParameters()); |
|
248 |
results.addAll(getMsiBundleParameters()); |
|
249 |
return results; |
|
250 |
} |
|
251 |
||
252 |
public static Collection<BundlerParamInfo<?>> getMsiBundleParameters() { |
|
253 |
return Arrays.asList( |
|
254 |
DESCRIPTION, |
|
255 |
MENU_GROUP, |
|
256 |
MENU_HINT, |
|
257 |
PRODUCT_VERSION, |
|
258 |
SHORTCUT_HINT, |
|
259 |
MSI_SYSTEM_WIDE, |
|
260 |
VENDOR, |
|
261 |
LICENSE_FILE, |
|
262 |
INSTALLDIR_CHOOSER |
|
263 |
); |
|
264 |
} |
|
265 |
||
266 |
@Override |
|
57140 | 267 |
public File execute(Map<String, ? super Object> params, |
268 |
File outputParentDir) throws PackagerException { |
|
57038 | 269 |
return bundle(params, outputParentDir); |
270 |
} |
|
271 |
||
272 |
@Override |
|
57150 | 273 |
public boolean supported(boolean platformInstaller) { |
57038 | 274 |
return (Platform.getPlatform() == Platform.WINDOWS); |
275 |
} |
|
276 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
277 |
private static String findToolVersion(String toolName) { |
57038 | 278 |
try { |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
279 |
if (toolName == null || "".equals(toolName)) return null; |
57038 | 280 |
|
281 |
ProcessBuilder pb = new ProcessBuilder( |
|
282 |
toolName, |
|
283 |
"/?"); |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
284 |
VersionExtractor ve = new VersionExtractor("version (\\d+.\\d+)"); |
57038 | 285 |
// not interested in the output |
57391 | 286 |
IOUtils.exec(pb, true, ve); |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
287 |
String version = ve.getVersion(); |
57038 | 288 |
Log.verbose(MessageFormat.format( |
289 |
I18N.getString("message.tool-version"), |
|
290 |
toolName, version)); |
|
291 |
return version; |
|
292 |
} catch (Exception e) { |
|
293 |
if (Log.isDebug()) { |
|
294 |
Log.verbose(e); |
|
295 |
} |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
296 |
return null; |
57038 | 297 |
} |
298 |
} |
|
299 |
||
300 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
301 |
public boolean validate(Map<String, ? super Object> params) |
57038 | 302 |
throws UnsupportedPlatformException, ConfigException { |
303 |
try { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
304 |
if (params == null) throw new ConfigException( |
57038 | 305 |
I18N.getString("error.parameters-null"), |
306 |
I18N.getString("error.parameters-null.advice")); |
|
307 |
||
308 |
// run basic validation to ensure requirements are met |
|
309 |
// we are not interested in return code, only possible exception |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
310 |
APP_BUNDLER.fetchFrom(params).validate(params); |
57038 | 311 |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
312 |
String candleVersion = |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
313 |
findToolVersion(TOOL_CANDLE_EXECUTABLE.fetchFrom(params)); |
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
314 |
String lightVersion = |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
315 |
findToolVersion(TOOL_LIGHT_EXECUTABLE.fetchFrom(params)); |
57038 | 316 |
|
317 |
// WiX 3.0+ is required |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
318 |
String minVersion = "3.0"; |
57038 | 319 |
boolean bad = false; |
320 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
321 |
if (VersionExtractor.isLessThan(candleVersion, minVersion)) { |
57038 | 322 |
Log.verbose(MessageFormat.format( |
323 |
I18N.getString("message.wrong-tool-version"), |
|
324 |
TOOL_CANDLE, candleVersion, minVersion)); |
|
325 |
bad = true; |
|
326 |
} |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
327 |
if (VersionExtractor.isLessThan(lightVersion, minVersion)) { |
57038 | 328 |
Log.verbose(MessageFormat.format( |
329 |
I18N.getString("message.wrong-tool-version"), |
|
330 |
TOOL_LIGHT, lightVersion, minVersion)); |
|
331 |
bad = true; |
|
332 |
} |
|
333 |
||
334 |
if (bad){ |
|
335 |
throw new ConfigException( |
|
336 |
I18N.getString("error.no-wix-tools"), |
|
337 |
I18N.getString("error.no-wix-tools.advice")); |
|
338 |
} |
|
339 |
||
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
340 |
if (!VersionExtractor.isLessThan(lightVersion, "3.6")) { |
57038 | 341 |
Log.verbose(I18N.getString("message.use-wix36-features")); |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
342 |
params.put(CAN_USE_WIX36.getID(), Boolean.TRUE); |
57038 | 343 |
} |
344 |
||
345 |
/********* validate bundle parameters *************/ |
|
346 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
347 |
String version = PRODUCT_VERSION.fetchFrom(params); |
57038 | 348 |
if (!isVersionStringValid(version)) { |
349 |
throw new ConfigException( |
|
350 |
MessageFormat.format(I18N.getString( |
|
351 |
"error.version-string-wrong-format"), version), |
|
352 |
MessageFormat.format(I18N.getString( |
|
353 |
"error.version-string-wrong-format.advice"), |
|
354 |
PRODUCT_VERSION.getID())); |
|
355 |
} |
|
356 |
||
357 |
// only one mime type per association, at least one file extension |
|
358 |
List<Map<String, ? super Object>> associations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
359 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 360 |
if (associations != null) { |
361 |
for (int i = 0; i < associations.size(); i++) { |
|
362 |
Map<String, ? super Object> assoc = associations.get(i); |
|
363 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
364 |
if (mimes.size() > 1) { |
|
365 |
throw new ConfigException(MessageFormat.format( |
|
366 |
I18N.getString("error.too-many-content-" |
|
367 |
+ "types-for-file-association"), i), |
|
368 |
I18N.getString("error.too-many-content-" |
|
369 |
+ "types-for-file-association.advice")); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
return true; |
|
375 |
} catch (RuntimeException re) { |
|
376 |
if (re.getCause() instanceof ConfigException) { |
|
377 |
throw (ConfigException) re.getCause(); |
|
378 |
} else { |
|
379 |
throw new ConfigException(re); |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
// http://msdn.microsoft.com/en-us/library/aa370859%28v=VS.85%29.aspx |
|
385 |
// The format of the string is as follows: |
|
386 |
// major.minor.build |
|
387 |
// The first field is the major version and has a maximum value of 255. |
|
388 |
// The second field is the minor version and has a maximum value of 255. |
|
389 |
// The third field is called the build version or the update version and |
|
390 |
// has a maximum value of 65,535. |
|
391 |
static boolean isVersionStringValid(String v) { |
|
392 |
if (v == null) { |
|
393 |
return true; |
|
394 |
} |
|
395 |
||
396 |
String p[] = v.split("\\."); |
|
397 |
if (p.length > 3) { |
|
398 |
Log.verbose(I18N.getString( |
|
399 |
"message.version-string-too-many-components")); |
|
400 |
return false; |
|
401 |
} |
|
402 |
||
403 |
try { |
|
404 |
int val = Integer.parseInt(p[0]); |
|
405 |
if (val < 0 || val > 255) { |
|
406 |
Log.verbose(I18N.getString( |
|
407 |
"error.version-string-major-out-of-range")); |
|
408 |
return false; |
|
409 |
} |
|
410 |
if (p.length > 1) { |
|
411 |
val = Integer.parseInt(p[1]); |
|
412 |
if (val < 0 || val > 255) { |
|
413 |
Log.verbose(I18N.getString( |
|
414 |
"error.version-string-minor-out-of-range")); |
|
415 |
return false; |
|
416 |
} |
|
417 |
} |
|
418 |
if (p.length > 2) { |
|
419 |
val = Integer.parseInt(p[2]); |
|
420 |
if (val < 0 || val > 65535) { |
|
421 |
Log.verbose(I18N.getString( |
|
422 |
"error.version-string-build-out-of-range")); |
|
423 |
return false; |
|
424 |
} |
|
425 |
} |
|
426 |
} catch (NumberFormatException ne) { |
|
427 |
Log.verbose(I18N.getString("error.version-string-part-not-number")); |
|
428 |
Log.verbose(ne); |
|
429 |
return false; |
|
430 |
} |
|
431 |
||
432 |
return true; |
|
433 |
} |
|
434 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
435 |
private boolean prepareProto(Map<String, ? super Object> params) |
57140 | 436 |
throws PackagerException, IOException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
437 |
File appImage = StandardBundlerParam.getPredefinedAppImage(params); |
57038 | 438 |
File appDir = null; |
439 |
||
440 |
// we either have an application image or need to build one |
|
441 |
if (appImage != null) { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
442 |
appDir = new File(MSI_IMAGE_DIR.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
443 |
APP_NAME.fetchFrom(params)); |
57038 | 444 |
// copy everything from appImage dir into appDir/name |
445 |
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath()); |
|
446 |
} else { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
447 |
appDir = APP_BUNDLER.fetchFrom(params).doBundle(params, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
448 |
MSI_IMAGE_DIR.fetchFrom(params), true); |
57038 | 449 |
} |
450 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
451 |
params.put(WIN_APP_IMAGE.getID(), appDir); |
57038 | 452 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
453 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
57080 | 454 |
if (licenseFile != null) { |
455 |
// need to copy license file to the working directory and convert to rtf if needed |
|
456 |
File lfile = new File(licenseFile); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
457 |
File destFile = new File(CONFIG_ROOT.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
458 |
lfile.getName()); |
57080 | 459 |
IOUtils.copyFile(lfile, destFile); |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
460 |
destFile.setWritable(true); |
57080 | 461 |
ensureByMutationFileIsRTF(destFile); |
57038 | 462 |
} |
463 |
||
464 |
// copy file association icons |
|
465 |
List<Map<String, ? super Object>> fileAssociations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
466 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 467 |
for (Map<String, ? super Object> fa : fileAssociations) { |
57397
89549ecec1c7
8223212: Code cleanup found during jpackage review
herrick
parents:
57396
diff
changeset
|
468 |
File icon = FA_ICON.fetchFrom(fa); |
57038 | 469 |
if (icon == null) { |
470 |
continue; |
|
471 |
} |
|
472 |
||
473 |
File faIconFile = new File(appDir, icon.getName()); |
|
474 |
||
475 |
if (icon.exists()) { |
|
476 |
try { |
|
477 |
IOUtils.copyFile(icon, faIconFile); |
|
478 |
} catch (IOException e) { |
|
57140 | 479 |
Log.verbose(e); |
57038 | 480 |
} |
481 |
} |
|
482 |
} |
|
483 |
||
484 |
return appDir != null; |
|
485 |
} |
|
486 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
487 |
public File bundle(Map<String, ? super Object> params, File outdir) |
57140 | 488 |
throws PackagerException { |
57407 | 489 |
|
490 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 491 |
|
492 |
// validate we have valid tools before continuing |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
493 |
String light = TOOL_LIGHT_EXECUTABLE.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
494 |
String candle = TOOL_CANDLE_EXECUTABLE.fetchFrom(params); |
57038 | 495 |
if (light == null || !new File(light).isFile() || |
496 |
candle == null || !new File(candle).isFile()) { |
|
497 |
Log.verbose(MessageFormat.format( |
|
498 |
I18N.getString("message.light-file-string"), light)); |
|
499 |
Log.verbose(MessageFormat.format( |
|
500 |
I18N.getString("message.candle-file-string"), candle)); |
|
57140 | 501 |
throw new PackagerException("error.no-wix-tools"); |
57038 | 502 |
} |
503 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
504 |
Map<String, String> wixVars = null; |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
505 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
506 |
File imageDir = MSI_IMAGE_DIR.fetchFrom(params); |
57038 | 507 |
try { |
508 |
imageDir.mkdirs(); |
|
509 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
510 |
boolean menuShortcut = MENU_HINT.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
511 |
boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(params); |
57038 | 512 |
if (!menuShortcut && !desktopShortcut) { |
513 |
// both can not be false - user will not find the app |
|
514 |
Log.verbose(I18N.getString("message.one-shortcut-required")); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
515 |
params.put(MENU_HINT.getID(), true); |
57038 | 516 |
} |
517 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
518 |
prepareBasicProjectConfig(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
519 |
if (prepareProto(params)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
520 |
wixVars = prepareWiXConfig(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
521 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
522 |
File configScriptSrc = getConfig_Script(params); |
57038 | 523 |
if (configScriptSrc.exists()) { |
524 |
// we need to be running post script in the image folder |
|
525 |
||
526 |
// NOTE: Would it be better to generate it to the image |
|
527 |
// folder and save only if "verbose" is requested? |
|
528 |
||
529 |
// for now we replicate it |
|
530 |
File configScript = |
|
531 |
new File(imageDir, configScriptSrc.getName()); |
|
532 |
IOUtils.copyFile(configScriptSrc, configScript); |
|
533 |
Log.verbose(MessageFormat.format( |
|
534 |
I18N.getString("message.running-wsh-script"), |
|
535 |
configScript.getAbsolutePath())); |
|
57391 | 536 |
IOUtils.run("wscript", configScript); |
57038 | 537 |
} |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
538 |
return buildMSI(params, wixVars, outdir); |
57038 | 539 |
} |
540 |
return null; |
|
541 |
} catch (IOException ex) { |
|
542 |
Log.verbose(ex); |
|
57140 | 543 |
throw new PackagerException(ex); |
57038 | 544 |
} |
545 |
} |
|
546 |
||
547 |
// name of post-image script |
|
548 |
private File getConfig_Script(Map<String, ? super Object> params) { |
|
549 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
57119 | 550 |
APP_NAME.fetchFrom(params) + "-post-image.wsf"); |
57038 | 551 |
} |
552 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
553 |
private void prepareBasicProjectConfig( |
57038 | 554 |
Map<String, ? super Object> params) throws IOException { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
555 |
fetchResource(getConfig_Script(params).getName(), |
57038 | 556 |
I18N.getString("resource.post-install-script"), |
557 |
(String) null, |
|
558 |
getConfig_Script(params), |
|
559 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
560 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 561 |
} |
562 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
563 |
private static String relativePath(File basedir, File file) { |
57038 | 564 |
return file.getAbsolutePath().substring( |
565 |
basedir.getAbsolutePath().length() + 1); |
|
566 |
} |
|
567 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
568 |
private void prepareIconsFile( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
569 |
Map<String, ? super Object> params) throws IOException { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
570 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
571 |
File imageRootDir = WIN_APP_IMAGE.fetchFrom(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
572 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
573 |
List<Map<String, ? super Object>> addLaunchers = |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
574 |
ADD_LAUNCHERS.fetchFrom(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
575 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
576 |
XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
577 |
try (Writer w = new BufferedWriter(new FileWriter(new File( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
578 |
CONFIG_ROOT.fetchFrom(params), "icons.wxi")))) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
579 |
XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
580 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
581 |
xml.writeStartDocument(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
582 |
xml.writeStartElement("Include"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
583 |
|
57407 | 584 |
File launcher = new File(imageRootDir, |
585 |
WinAppBundler.getLauncherRelativePath(params)); |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
586 |
if (launcher.exists()) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
587 |
String iconPath = launcher.getAbsolutePath().replace(".exe", ".ico"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
588 |
if (MENU_HINT.fetchFrom(params)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
589 |
xml.writeStartElement("Icon"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
590 |
xml.writeAttribute("Id", "StartMenuIcon.exe"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
591 |
xml.writeAttribute("SourceFile", iconPath); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
592 |
xml.writeEndElement(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
593 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
594 |
if (SHORTCUT_HINT.fetchFrom(params)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
595 |
xml.writeStartElement("Icon"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
596 |
xml.writeAttribute("Id", "DesktopIcon.exe"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
597 |
xml.writeAttribute("SourceFile", iconPath); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
598 |
xml.writeEndElement(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
599 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
600 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
601 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
602 |
for (int i = 0; i < addLaunchers.size(); i++) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
603 |
Map<String, ? super Object> sl = addLaunchers.get(i); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
604 |
if (SHORTCUT_HINT.fetchFrom(sl) || MENU_HINT.fetchFrom(sl)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
605 |
File addLauncher = new File(imageRootDir, |
57407 | 606 |
WinAppBundler.getLauncherRelativePath(sl)); |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
607 |
String addLauncherPath |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
608 |
= relativePath(imageRootDir, addLauncher); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
609 |
String addLauncherIconPath |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
610 |
= addLauncherPath.replace(".exe", ".ico"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
611 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
612 |
xml.writeStartElement("Icon"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
613 |
xml.writeAttribute("Id", "Launcher" + i + ".exe"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
614 |
xml.writeAttribute("SourceFile", addLauncherIconPath); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
615 |
xml.writeEndElement(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
616 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
617 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
618 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
619 |
xml.writeEndElement(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
620 |
xml.writeEndDocument(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
621 |
xml.flush(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
622 |
xml.close(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
623 |
} catch (XMLStreamException ex) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
624 |
Log.verbose(ex); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
625 |
throw new IOException(ex); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
626 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
627 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
628 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
629 |
Map<String, String> prepareMainProjectFile( |
57038 | 630 |
Map<String, ? super Object> params) throws IOException { |
631 |
Map<String, String> data = new HashMap<>(); |
|
632 |
||
633 |
UUID productGUID = UUID.randomUUID(); |
|
634 |
||
635 |
Log.verbose(MessageFormat.format( |
|
636 |
I18N.getString("message.generated-product-guid"), |
|
637 |
productGUID.toString())); |
|
638 |
||
639 |
// we use random GUID for product itself but |
|
640 |
// user provided for upgrade guid |
|
641 |
// Upgrade guid is important to decide whether it is an upgrade of |
|
642 |
// installed app. I.e. we need it to be the same for |
|
643 |
// 2 different versions of app if possible |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
644 |
data.put("JpProductCode", productGUID.toString()); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
645 |
data.put("JpProductUpgradeCode", |
57038 | 646 |
UPGRADE_UUID.fetchFrom(params).toString()); |
647 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
648 |
if (!UPGRADE_UUID.getIsDefaultValue()) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
649 |
data.put("JpAllowDowngrades", "yes"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
650 |
} |
57038 | 651 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
652 |
if (CAN_USE_WIX36.fetchFrom(params)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
653 |
data.put("JpWixVersion36OrNewer", "yes"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
654 |
} |
57038 | 655 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
656 |
data.put("JpAppName", APP_NAME.fetchFrom(params)); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
657 |
data.put("JpAppDescription", DESCRIPTION.fetchFrom(params)); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
658 |
data.put("JpAppVendor", VENDOR.fetchFrom(params)); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
659 |
data.put("JpAppVersion", PRODUCT_VERSION.fetchFrom(params)); |
57038 | 660 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
661 |
data.put("JpConfigDir", CONFIG_ROOT.fetchFrom(params).getAbsolutePath()); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
662 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
663 |
File imageRootDir = WIN_APP_IMAGE.fetchFrom(params); |
57038 | 664 |
|
665 |
if (MSI_SYSTEM_WIDE.fetchFrom(params)) { |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
666 |
data.put("JpIsSystemWide", "yes"); |
57038 | 667 |
} |
668 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
669 |
if (LICENSE_FILE.fetchFrom(params) != null) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
670 |
data.put("JpLicenseRtf", LICENSE_FILE.fetchFrom(params)); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
671 |
} |
57038 | 672 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
673 |
// Copy CA dll to include with installer |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
674 |
if (INSTALLDIR_CHOOSER.fetchFrom(params)) { |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
675 |
data.put("JpInstallDirChooser", "yes"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
676 |
String fname = "wixhelper.dll"; |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
677 |
try (InputStream is = getResourceAsStream(fname)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
678 |
Files.copy(is, Paths.get( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
679 |
CONFIG_ROOT.fetchFrom(params).getAbsolutePath(), fname)); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
680 |
} |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
681 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
682 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
683 |
// Copy l10n files. |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
684 |
for (String loc : Arrays.asList("en", "ja", "zh_CN")) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
685 |
String fname = "MsiInstallerStrings_" + loc + ".wxl"; |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
686 |
try (InputStream is = getResourceAsStream(fname)) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
687 |
Files.copy(is, Paths.get( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
688 |
CONFIG_ROOT.fetchFrom(params).getAbsolutePath(), fname)); |
57038 | 689 |
} |
690 |
} |
|
691 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
692 |
try (InputStream is = getResourceAsStream("main.wxs")) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
693 |
Files.copy(is, Paths.get( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
694 |
getConfig_ProjectFile(params).getAbsolutePath())); |
57390 | 695 |
} |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
696 |
|
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
697 |
return data; |
57038 | 698 |
} |
699 |
private int id; |
|
700 |
private int compId; |
|
701 |
private final static String LAUNCHER_ID = "LauncherId"; |
|
702 |
||
703 |
private void walkFileTree(Map<String, ? super Object> params, |
|
704 |
File root, PrintStream out, String prefix) { |
|
705 |
List<File> dirs = new ArrayList<>(); |
|
706 |
List<File> files = new ArrayList<>(); |
|
707 |
||
708 |
if (!root.isDirectory()) { |
|
709 |
throw new RuntimeException( |
|
710 |
MessageFormat.format( |
|
711 |
I18N.getString("error.cannot-walk-directory"), |
|
712 |
root.getAbsolutePath())); |
|
713 |
} |
|
714 |
||
715 |
// sort to files and dirs |
|
716 |
File[] children = root.listFiles(); |
|
717 |
if (children != null) { |
|
718 |
for (File f : children) { |
|
719 |
if (f.isDirectory()) { |
|
720 |
dirs.add(f); |
|
721 |
} else { |
|
722 |
files.add(f); |
|
723 |
} |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
// have files => need to output component |
|
728 |
out.println(prefix + " <Component Id=\"comp" + (compId++) |
|
729 |
+ "\" DiskId=\"1\"" |
|
730 |
+ " Guid=\"" + UUID.randomUUID().toString() + "\"" |
|
57219
bfa094e6ce15
8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code
herrick
parents:
57213
diff
changeset
|
731 |
+ " Win64=\"yes\"" |
57038 | 732 |
+ ">"); |
733 |
out.println(prefix + " <CreateFolder/>"); |
|
734 |
out.println(prefix + " <RemoveFolder Id=\"RemoveDir" |
|
735 |
+ (id++) + "\" On=\"uninstall\" />"); |
|
736 |
||
737 |
boolean needRegistryKey = !MSI_SYSTEM_WIDE.fetchFrom(params); |
|
738 |
File imageRootDir = WIN_APP_IMAGE.fetchFrom(params); |
|
57407 | 739 |
File launcherFile = new File(imageRootDir, |
740 |
WinAppBundler.getLauncherRelativePath(params)); |
|
57038 | 741 |
|
742 |
// Find out if we need to use registry. We need it if |
|
743 |
// - we doing user level install as file can not serve as KeyPath |
|
744 |
// - if we adding shortcut in this component |
|
745 |
||
746 |
for (File f: files) { |
|
747 |
boolean isLauncher = f.equals(launcherFile); |
|
748 |
if (isLauncher) { |
|
749 |
needRegistryKey = true; |
|
750 |
} |
|
751 |
} |
|
752 |
||
753 |
if (needRegistryKey) { |
|
754 |
// has to be under HKCU to make WiX happy |
|
755 |
out.println(prefix + " <RegistryKey Root=\"HKCU\" " |
|
756 |
+ " Key=\"Software\\" + VENDOR.fetchFrom(params) + "\\" |
|
757 |
+ APP_NAME.fetchFrom(params) + "\"" |
|
758 |
+ (CAN_USE_WIX36.fetchFrom(params) ? |
|
759 |
">" : " Action=\"createAndRemoveOnUninstall\">")); |
|
760 |
out.println(prefix |
|
761 |
+ " <RegistryValue Name=\"Version\" Value=\"" |
|
762 |
+ VERSION.fetchFrom(params) |
|
763 |
+ "\" Type=\"string\" KeyPath=\"yes\"/>"); |
|
764 |
out.println(prefix + " </RegistryKey>"); |
|
765 |
} |
|
766 |
||
767 |
boolean menuShortcut = MENU_HINT.fetchFrom(params); |
|
768 |
boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(params); |
|
769 |
||
770 |
Map<String, String> idToFileMap = new TreeMap<>(); |
|
771 |
boolean launcherSet = false; |
|
772 |
||
773 |
for (File f : files) { |
|
774 |
boolean isLauncher = f.equals(launcherFile); |
|
775 |
||
776 |
launcherSet = launcherSet || isLauncher; |
|
777 |
||
778 |
boolean doShortcuts = |
|
779 |
isLauncher && (menuShortcut || desktopShortcut); |
|
780 |
||
781 |
String thisFileId = isLauncher ? LAUNCHER_ID : ("FileId" + (id++)); |
|
782 |
idToFileMap.put(f.getName(), thisFileId); |
|
783 |
||
784 |
out.println(prefix + " <File Id=\"" + |
|
785 |
thisFileId + "\"" |
|
786 |
+ " Name=\"" + f.getName() + "\" " |
|
787 |
+ " Source=\"" + relativePath(imageRootDir, f) + "\"" |
|
57213
8ff0a29bf9bc
8218055: Use ToolProvider instead of AppRuntimeImageBuilder.
herrick
parents:
57181
diff
changeset
|
788 |
+ " ProcessorArchitecture=\"x64\"" + ">"); |
57038 | 789 |
if (doShortcuts && desktopShortcut) { |
790 |
out.println(prefix |
|
791 |
+ " <Shortcut Id=\"desktopShortcut\" Directory=" |
|
792 |
+ "\"DesktopFolder\"" |
|
793 |
+ " Name=\"" + APP_NAME.fetchFrom(params) |
|
794 |
+ "\" WorkingDirectory=\"INSTALLDIR\"" |
|
795 |
+ " Advertise=\"no\" Icon=\"DesktopIcon.exe\"" |
|
796 |
+ " IconIndex=\"0\" />"); |
|
797 |
} |
|
798 |
if (doShortcuts && menuShortcut) { |
|
799 |
out.println(prefix |
|
800 |
+ " <Shortcut Id=\"ExeShortcut\" Directory=" |
|
801 |
+ "\"ProgramMenuDir\"" |
|
802 |
+ " Name=\"" + APP_NAME.fetchFrom(params) |
|
803 |
+ "\" Advertise=\"no\" Icon=\"StartMenuIcon.exe\"" |
|
804 |
+ " IconIndex=\"0\" />"); |
|
805 |
} |
|
806 |
||
57256 | 807 |
List<Map<String, ? super Object>> addLaunchers = |
808 |
ADD_LAUNCHERS.fetchFrom(params); |
|
809 |
for (int i = 0; i < addLaunchers.size(); i++) { |
|
810 |
Map<String, ? super Object> sl = addLaunchers.get(i); |
|
811 |
File addLauncherFile = new File(imageRootDir, |
|
57407 | 812 |
WinAppBundler.getLauncherRelativePath(sl)); |
57256 | 813 |
if (f.equals(addLauncherFile)) { |
57038 | 814 |
if (SHORTCUT_HINT.fetchFrom(sl)) { |
815 |
out.println(prefix |
|
816 |
+ " <Shortcut Id=\"desktopShortcut" |
|
817 |
+ i + "\" Directory=\"DesktopFolder\"" |
|
818 |
+ " Name=\"" + APP_NAME.fetchFrom(sl) |
|
819 |
+ "\" WorkingDirectory=\"INSTALLDIR\"" |
|
820 |
+ " Advertise=\"no\" Icon=\"Launcher" |
|
821 |
+ i + ".exe\" IconIndex=\"0\" />"); |
|
822 |
} |
|
823 |
if (MENU_HINT.fetchFrom(sl)) { |
|
824 |
out.println(prefix |
|
825 |
+ " <Shortcut Id=\"ExeShortcut" |
|
826 |
+ i + "\" Directory=\"ProgramMenuDir\"" |
|
827 |
+ " Name=\"" + APP_NAME.fetchFrom(sl) |
|
828 |
+ "\" Advertise=\"no\" Icon=\"Launcher" |
|
829 |
+ i + ".exe\" IconIndex=\"0\" />"); |
|
830 |
// Should we allow different menu groups? Not for now. |
|
831 |
} |
|
832 |
} |
|
833 |
} |
|
834 |
out.println(prefix + " </File>"); |
|
835 |
} |
|
836 |
||
837 |
if (launcherSet) { |
|
838 |
List<Map<String, ? super Object>> fileAssociations = |
|
839 |
FILE_ASSOCIATIONS.fetchFrom(params); |
|
840 |
String regName = APP_REGISTRY_NAME.fetchFrom(params); |
|
841 |
Set<String> defaultedMimes = new TreeSet<>(); |
|
842 |
int count = 0; |
|
843 |
for (Map<String, ? super Object> fa : fileAssociations) { |
|
844 |
String description = FA_DESCRIPTION.fetchFrom(fa); |
|
845 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(fa); |
|
846 |
List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fa); |
|
57397
89549ecec1c7
8223212: Code cleanup found during jpackage review
herrick
parents:
57396
diff
changeset
|
847 |
File icon = FA_ICON.fetchFrom(fa); |
57038 | 848 |
|
849 |
String mime = (mimeTypes == null || |
|
850 |
mimeTypes.isEmpty()) ? null : mimeTypes.get(0); |
|
851 |
||
852 |
if (extensions == null) { |
|
853 |
Log.verbose(I18N.getString( |
|
854 |
"message.creating-association-with-null-extension")); |
|
855 |
||
856 |
String entryName = regName + "File"; |
|
857 |
if (count > 0) { |
|
858 |
entryName += "." + count; |
|
859 |
} |
|
860 |
count++; |
|
861 |
out.print(prefix + " <ProgId Id='" + entryName |
|
862 |
+ "' Description='" + description + "'"); |
|
863 |
if (icon != null && icon.exists()) { |
|
864 |
out.print(" Icon='" + idToFileMap.get(icon.getName()) |
|
865 |
+ "' IconIndex='0'"); |
|
866 |
} |
|
867 |
out.println(" />"); |
|
868 |
} else { |
|
869 |
for (String ext : extensions) { |
|
870 |
String entryName = regName + "File"; |
|
871 |
if (count > 0) { |
|
872 |
entryName += "." + count; |
|
873 |
} |
|
874 |
count++; |
|
875 |
||
876 |
out.print(prefix + " <ProgId Id='" + entryName |
|
877 |
+ "' Description='" + description + "'"); |
|
878 |
if (icon != null && icon.exists()) { |
|
879 |
out.print(" Icon='" |
|
880 |
+ idToFileMap.get(icon.getName()) |
|
881 |
+ "' IconIndex='0'"); |
|
882 |
} |
|
883 |
out.println(">"); |
|
884 |
||
885 |
if (extensions == null) { |
|
886 |
Log.verbose(I18N.getString( |
|
887 |
"message.creating-association-with-null-extension")); |
|
888 |
} else { |
|
889 |
out.print(prefix + " <Extension Id='" |
|
890 |
+ ext + "' Advertise='no'"); |
|
891 |
if (mime == null) { |
|
892 |
out.println(">"); |
|
893 |
} else { |
|
894 |
out.println(" ContentType='" + mime + "'>"); |
|
895 |
if (!defaultedMimes.contains(mime)) { |
|
896 |
out.println(prefix |
|
897 |
+ " <MIME ContentType='" |
|
898 |
+ mime + "' Default='yes' />"); |
|
899 |
defaultedMimes.add(mime); |
|
900 |
} |
|
901 |
} |
|
902 |
out.println(prefix |
|
903 |
+ " <Verb Id='open' Command='Open' " |
|
904 |
+ "TargetFile='" + LAUNCHER_ID |
|
905 |
+ "' Argument='\"%1\"' />"); |
|
906 |
out.println(prefix + " </Extension>"); |
|
907 |
} |
|
908 |
out.println(prefix + " </ProgId>"); |
|
909 |
} |
|
910 |
} |
|
911 |
} |
|
912 |
} |
|
913 |
||
914 |
out.println(prefix + " </Component>"); |
|
915 |
||
916 |
for (File d : dirs) { |
|
917 |
out.println(prefix + " <Directory Id=\"dirid" + (id++) |
|
918 |
+ "\" Name=\"" + d.getName() + "\">"); |
|
919 |
walkFileTree(params, d, out, prefix + " "); |
|
920 |
out.println(prefix + " </Directory>"); |
|
921 |
} |
|
922 |
} |
|
923 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
924 |
void prepareContentList(Map<String, ? super Object> params) |
57038 | 925 |
throws FileNotFoundException { |
926 |
File f = new File( |
|
927 |
CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE); |
|
57390 | 928 |
|
929 |
try (PrintStream out = new PrintStream(f)) { |
|
57038 | 930 |
|
57390 | 931 |
// opening |
932 |
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); |
|
933 |
out.println("<Include>"); |
|
57038 | 934 |
|
57390 | 935 |
out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">"); |
936 |
if (MSI_SYSTEM_WIDE.fetchFrom(params)) { |
|
937 |
// install to programfiles |
|
938 |
out.println(" <Directory Id=\"ProgramFiles64Folder\" " |
|
939 |
+ "Name=\"PFiles\">"); |
|
940 |
} else { |
|
941 |
// install to user folder |
|
942 |
out.println( |
|
57038 | 943 |
" <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">"); |
57390 | 944 |
} |
57283 | 945 |
|
57390 | 946 |
// We should get valid folder or subfolders |
947 |
String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params); |
|
948 |
String [] installDirs = installDir.split(Pattern.quote("\\")); |
|
949 |
for (int i = 0; i < (installDirs.length - 1); i++) { |
|
950 |
out.println(" <Directory Id=\"SUBDIR" + i + "\" Name=\"" |
|
951 |
+ installDirs[i] + "\">"); |
|
952 |
} |
|
57283 | 953 |
|
57390 | 954 |
out.println(" <Directory Id=\"APPLICATIONFOLDER\" Name=\"" |
955 |
+ installDirs[installDirs.length - 1] + "\">"); |
|
57038 | 956 |
|
57390 | 957 |
// dynamic part |
958 |
id = 0; |
|
959 |
compId = 0; // reset counters |
|
960 |
walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, " "); |
|
57038 | 961 |
|
57390 | 962 |
// closing |
963 |
for (int i = 0; i < installDirs.length; i++) { |
|
964 |
out.println(" </Directory>"); |
|
965 |
} |
|
966 |
out.println(" </Directory>"); |
|
57038 | 967 |
|
57390 | 968 |
// for shortcuts |
969 |
if (SHORTCUT_HINT.fetchFrom(params)) { |
|
970 |
out.println(" <Directory Id=\"DesktopFolder\" />"); |
|
971 |
} |
|
972 |
if (MENU_HINT.fetchFrom(params)) { |
|
973 |
out.println(" <Directory Id=\"ProgramMenuFolder\">"); |
|
974 |
out.println(" <Directory Id=\"ProgramMenuDir\" Name=\"" |
|
975 |
+ MENU_GROUP.fetchFrom(params) + "\">"); |
|
976 |
out.println(" <Component Id=\"comp" + (compId++) + "\"" |
|
977 |
+ " Guid=\"" + UUID.randomUUID().toString() + "\"" |
|
978 |
+ " Win64=\"yes\"" |
|
979 |
+ ">"); |
|
980 |
out.println(" <RemoveFolder Id=\"ProgramMenuDir\" " |
|
981 |
+ "On=\"uninstall\" />"); |
|
982 |
// This has to be under HKCU to make WiX happy. |
|
983 |
// There are numberous discussions on this amoung WiX users |
|
984 |
// (if user A installs and user B uninstalls key is left behind) |
|
985 |
// there are suggested workarounds but none are appealing. |
|
986 |
// Leave it for now |
|
987 |
out.println( |
|
988 |
" <RegistryValue Root=\"HKCU\" Key=\"Software\\" |
|
989 |
+ VENDOR.fetchFrom(params) + "\\" |
|
990 |
+ APP_NAME.fetchFrom(params) |
|
991 |
+ "\" Type=\"string\" Value=\"\" />"); |
|
992 |
out.println(" </Component>"); |
|
993 |
out.println(" </Directory>"); |
|
994 |
out.println(" </Directory>"); |
|
995 |
} |
|
996 |
||
997 |
out.println(" </Directory>"); |
|
998 |
||
999 |
out.println(" <Feature Id=\"DefaultFeature\" " |
|
1000 |
+ "Title=\"Main Feature\" Level=\"1\">"); |
|
1001 |
for (int j = 0; j < compId; j++) { |
|
1002 |
out.println(" <ComponentRef Id=\"comp" + j + "\" />"); |
|
1003 |
} |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1004 |
// component is defined in the main.wsx |
57038 | 1005 |
out.println( |
57390 | 1006 |
" <ComponentRef Id=\"CleanupMainApplicationFolder\" />"); |
1007 |
out.println(" </Feature>"); |
|
1008 |
out.println("</Include>"); |
|
57038 | 1009 |
|
1010 |
} |
|
1011 |
} |
|
1012 |
||
1013 |
private File getConfig_ProjectFile(Map<String, ? super Object> params) { |
|
1014 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
1015 |
APP_NAME.fetchFrom(params) + ".wxs"); |
|
1016 |
} |
|
1017 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1018 |
private Map<String, String> prepareWiXConfig( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1019 |
Map<String, ? super Object> params) throws IOException { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1020 |
prepareContentList(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1021 |
prepareIconsFile(params); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1022 |
return prepareMainProjectFile(params); |
57038 | 1023 |
} |
1024 |
||
1025 |
private final static String MSI_PROJECT_CONTENT_FILE = "bundle.wxi"; |
|
1026 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1027 |
private File buildMSI(Map<String, ? super Object> params, |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1028 |
Map<String, String> wixVars, File outdir) |
57038 | 1029 |
throws IOException { |
57256 | 1030 |
File tmpDir = new File(TEMP_ROOT.fetchFrom(params), "tmp"); |
57038 | 1031 |
File candleOut = new File( |
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1032 |
tmpDir, APP_NAME.fetchFrom(params) + ".wixobj"); |
57038 | 1033 |
File msiOut = new File( |
1034 |
outdir, INSTALLER_FILE_NAME.fetchFrom(params) + ".msi"); |
|
1035 |
||
1036 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
1037 |
"message.preparing-msi-config"), msiOut.getAbsolutePath())); |
|
1038 |
||
1039 |
msiOut.getParentFile().mkdirs(); |
|
1040 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1041 |
List<String> commandLine = new ArrayList<>(Arrays.asList( |
57038 | 1042 |
TOOL_CANDLE_EXECUTABLE.fetchFrom(params), |
1043 |
"-nologo", |
|
1044 |
getConfig_ProjectFile(params).getAbsolutePath(), |
|
1045 |
"-ext", "WixUtilExtension", |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1046 |
"-out", candleOut.getAbsolutePath())); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1047 |
for(Map.Entry<String, String> wixVar: wixVars.entrySet()) { |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1048 |
String v = "-d" + wixVar.getKey() + "=" + wixVar.getValue(); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1049 |
commandLine.add(v); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1050 |
} |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1051 |
ProcessBuilder pb = new ProcessBuilder(commandLine); |
57038 | 1052 |
pb = pb.directory(WIN_APP_IMAGE.fetchFrom(params)); |
57391 | 1053 |
IOUtils.exec(pb); |
57038 | 1054 |
|
1055 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
1056 |
"message.generating-msi"), msiOut.getAbsolutePath())); |
|
1057 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1058 |
boolean enableLicenseUI = (LICENSE_FILE.fetchFrom(params) != null); |
57038 | 1059 |
boolean enableInstalldirUI = INSTALLDIR_CHOOSER.fetchFrom(params); |
1060 |
||
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1061 |
commandLine = new ArrayList<>(); |
57038 | 1062 |
|
1063 |
commandLine.add(TOOL_LIGHT_EXECUTABLE.fetchFrom(params)); |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1064 |
|
57038 | 1065 |
commandLine.add("-nologo"); |
1066 |
commandLine.add("-spdb"); |
|
1067 |
commandLine.add("-sice:60"); |
|
1068 |
// ignore warnings due to "missing launcguage info" (ICE60) |
|
1069 |
commandLine.add(candleOut.getAbsolutePath()); |
|
1070 |
commandLine.add("-ext"); |
|
1071 |
commandLine.add("WixUtilExtension"); |
|
1072 |
if (enableLicenseUI || enableInstalldirUI) { |
|
1073 |
commandLine.add("-ext"); |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1074 |
commandLine.add("WixUIExtension"); |
57038 | 1075 |
} |
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1076 |
|
57404
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1077 |
commandLine.add("-loc"); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1078 |
commandLine.add(new File(CONFIG_ROOT.fetchFrom(params), I18N.getString( |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1079 |
"resource.wxl-file-name")).getAbsolutePath()); |
a477b26bf888
8223643: Provide better defined context for custom installer steps on Windows
herrick
parents:
57397
diff
changeset
|
1080 |
|
57254
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1081 |
// Only needed if we using CA dll, so Wix can find it |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1082 |
if (enableInstalldirUI) { |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1083 |
commandLine.add("-b"); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1084 |
commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()); |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1085 |
} |
c1b92a014e89
8214566: --win-dir-chooser does not prompt if destination folder is not empty
herrick
parents:
57219
diff
changeset
|
1086 |
|
57038 | 1087 |
commandLine.add("-out"); |
1088 |
commandLine.add(msiOut.getAbsolutePath()); |
|
1089 |
||
1090 |
// create .msi |
|
1091 |
pb = new ProcessBuilder(commandLine); |
|
1092 |
||
1093 |
pb = pb.directory(WIN_APP_IMAGE.fetchFrom(params)); |
|
57391 | 1094 |
IOUtils.exec(pb); |
57038 | 1095 |
|
1096 |
candleOut.delete(); |
|
1097 |
IOUtils.deleteRecursive(tmpDir); |
|
1098 |
||
1099 |
return msiOut; |
|
1100 |
} |
|
1101 |
||
1102 |
public static void ensureByMutationFileIsRTF(File f) { |
|
1103 |
if (f == null || !f.isFile()) return; |
|
1104 |
||
1105 |
try { |
|
1106 |
boolean existingLicenseIsRTF = false; |
|
1107 |
||
1108 |
try (FileInputStream fin = new FileInputStream(f)) { |
|
1109 |
byte[] firstBits = new byte[7]; |
|
1110 |
||
1111 |
if (fin.read(firstBits) == firstBits.length) { |
|
1112 |
String header = new String(firstBits); |
|
1113 |
existingLicenseIsRTF = "{\\rtf1\\".equals(header); |
|
1114 |
} |
|
1115 |
} |
|
1116 |
||
1117 |
if (!existingLicenseIsRTF) { |
|
1118 |
List<String> oldLicense = Files.readAllLines(f.toPath()); |
|
1119 |
try (Writer w = Files.newBufferedWriter( |
|
1120 |
f.toPath(), Charset.forName("Windows-1252"))) { |
|
1121 |
w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" |
|
1122 |
+ "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n" |
|
1123 |
+ "\\viewkind4\\uc1\\pard\\sa200\\sl276" |
|
1124 |
+ "\\slmult1\\lang9\\fs20 "); |
|
1125 |
oldLicense.forEach(l -> { |
|
1126 |
try { |
|
1127 |
for (char c : l.toCharArray()) { |
|
1128 |
// 0x00 <= ch < 0x20 Escaped (\'hh) |
|
1129 |
// 0x20 <= ch < 0x80 Raw(non - escaped) char |
|
1130 |
// 0x80 <= ch <= 0xFF Escaped(\ 'hh) |
|
1131 |
// 0x5C, 0x7B, 0x7D (special RTF characters |
|
1132 |
// \,{,})Escaped(\'hh) |
|
1133 |
// ch > 0xff Escaped (\\ud###?) |
|
1134 |
if (c < 0x10) { |
|
1135 |
w.write("\\'0"); |
|
1136 |
w.write(Integer.toHexString(c)); |
|
1137 |
} else if (c > 0xff) { |
|
1138 |
w.write("\\ud"); |
|
1139 |
w.write(Integer.toString(c)); |
|
1140 |
// \\uc1 is in the header and in effect |
|
1141 |
// so we trail with a replacement char if |
|
1142 |
// the font lacks that character - '?' |
|
1143 |
w.write("?"); |
|
1144 |
} else if ((c < 0x20) || (c >= 0x80) || |
|
1145 |
(c == 0x5C) || (c == 0x7B) || |
|
1146 |
(c == 0x7D)) { |
|
1147 |
w.write("\\'"); |
|
1148 |
w.write(Integer.toHexString(c)); |
|
1149 |
} else { |
|
1150 |
w.write(c); |
|
1151 |
} |
|
1152 |
} |
|
1153 |
// blank lines are interpreted as paragraph breaks |
|
1154 |
if (l.length() < 1) { |
|
1155 |
w.write("\\par"); |
|
1156 |
} else { |
|
1157 |
w.write(" "); |
|
1158 |
} |
|
1159 |
w.write("\r\n"); |
|
1160 |
} catch (IOException e) { |
|
1161 |
Log.verbose(e); |
|
1162 |
} |
|
1163 |
}); |
|
1164 |
w.write("}\r\n"); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
} catch (IOException e) { |
|
1168 |
Log.verbose(e); |
|
1169 |
} |
|
1170 |
||
1171 |
} |
|
1172 |
} |