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