author | herrick |
Wed, 23 Oct 2019 10:37:54 -0400 | |
branch | JDK-8200758-branch |
changeset 58762 | 0fe62353385b |
parent 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) 2017, 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 |
*/ |
|
57039 | 25 |
package jdk.jpackage.internal; |
57038 | 26 |
|
27 |
import java.io.*; |
|
28 |
import java.nio.file.Files; |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
29 |
import java.nio.file.Path; |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
30 |
import java.nio.file.Paths; |
57038 | 31 |
import java.text.MessageFormat; |
32 |
import java.util.*; |
|
33 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
34 |
public class WinExeBundler extends AbstractBundler { |
57038 | 35 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
36 |
static { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
37 |
System.loadLibrary("jpackage"); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
38 |
} |
57038 | 39 |
|
40 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 41 |
"jdk.jpackage.internal.resources.WinResources"); |
57038 | 42 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
43 |
public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
44 |
= new WindowsBundlerParam<>( |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
45 |
"win.app.bundler", |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
46 |
WinAppBundler.class, |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
47 |
params -> new WinAppBundler(), |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
48 |
null); |
57038 | 49 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
50 |
public static final BundlerParamInfo<File> EXE_IMAGE_DIR |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
51 |
= new WindowsBundlerParam<>( |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
52 |
"win.exe.imageDir", |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
53 |
File.class, |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
54 |
params -> { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
55 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
56 |
if (!imagesRoot.exists()) { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
57 |
imagesRoot.mkdirs(); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
58 |
} |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
59 |
return new File(imagesRoot, "win-exe.image"); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
60 |
}, |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
61 |
(s, p) -> null); |
57038 | 62 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
63 |
private final static String EXE_WRAPPER_NAME = "msiwrapper.exe"; |
57038 | 64 |
|
65 |
@Override |
|
66 |
public String getName() { |
|
57059 | 67 |
return getString("exe.bundler.name"); |
57038 | 68 |
} |
69 |
||
70 |
@Override |
|
71 |
public String getID() { |
|
72 |
return "exe"; |
|
73 |
} |
|
74 |
||
75 |
@Override |
|
76 |
public String getBundleType() { |
|
77 |
return "INSTALLER"; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
81 |
public File execute(Map<String, ? super Object> params, |
57140 | 82 |
File outputParentDir) throws PackagerException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
83 |
return bundle(params, outputParentDir); |
57038 | 84 |
} |
85 |
||
86 |
@Override |
|
57150 | 87 |
public boolean supported(boolean platformInstaller) { |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58647
diff
changeset
|
88 |
return msiBundler.supported(platformInstaller); |
57038 | 89 |
} |
90 |
||
91 |
@Override |
|
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
92 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
93 |
return true; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
94 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
95 |
|
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
96 |
@Override |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
97 |
public boolean validate(Map<String, ? super Object> params) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
98 |
throws ConfigException { |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58647
diff
changeset
|
99 |
return msiBundler.validate(params); |
57038 | 100 |
} |
101 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
102 |
public File bundle(Map<String, ? super Object> params, File outdir) |
57140 | 103 |
throws PackagerException { |
57407 | 104 |
|
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57411
diff
changeset
|
105 |
IOUtils.writableOutputDir(outdir.toPath()); |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57411
diff
changeset
|
106 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
107 |
File exeImageDir = EXE_IMAGE_DIR.fetchFrom(params); |
57038 | 108 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
109 |
// Write msi to temporary directory. |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58647
diff
changeset
|
110 |
File msi = msiBundler.bundle(params, exeImageDir); |
57038 | 111 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
112 |
try { |
58762
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
113 |
new ScriptRunner() |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
114 |
.setDirectory(msi.toPath().getParent()) |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
115 |
.setResourceCategoryId("resource.post-msi-script") |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
116 |
.setScriptNameSuffix("post-msi") |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
117 |
.setEnvironmentVariable("JpMsiFile", msi.getAbsolutePath().toString()) |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
118 |
.run(params); |
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58696
diff
changeset
|
119 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
120 |
return buildEXE(msi, outdir); |
57038 | 121 |
} catch (IOException ex) { |
57140 | 122 |
Log.verbose(ex); |
123 |
throw new PackagerException(ex); |
|
57038 | 124 |
} |
125 |
} |
|
126 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
127 |
private File buildEXE(File msi, File outdir) |
57038 | 128 |
throws IOException { |
129 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
130 |
Log.verbose(MessageFormat.format( |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
131 |
getString("message.outputting-to-location"), |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
132 |
outdir.getAbsolutePath())); |
57038 | 133 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
134 |
// Copy template msi wrapper next to msi file |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
135 |
String exePath = msi.getAbsolutePath(); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
136 |
exePath = exePath.substring(0, exePath.lastIndexOf('.')) + ".exe"; |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
137 |
try (InputStream is = OverridableResource.readDefault(EXE_WRAPPER_NAME)) { |
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
138 |
Files.copy(is, Path.of(exePath)); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
139 |
} |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
140 |
// Embed msi in msi wrapper exe. |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
141 |
embedMSI(exePath, msi.getAbsolutePath()); |
57038 | 142 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
143 |
Path dstExePath = Paths.get(outdir.getAbsolutePath(), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
144 |
Path.of(exePath).getFileName().toString()); |
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
145 |
Files.deleteIfExists(dstExePath); |
57038 | 146 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
147 |
Files.copy(Path.of(exePath), dstExePath); |
57038 | 148 |
|
149 |
Log.verbose(MessageFormat.format( |
|
150 |
getString("message.output-location"), |
|
151 |
outdir.getAbsolutePath())); |
|
152 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
153 |
return dstExePath.toFile(); |
57038 | 154 |
} |
155 |
||
156 |
private static String getString(String key) |
|
157 |
throws MissingResourceException { |
|
158 |
return I18N.getString(key); |
|
159 |
} |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
160 |
|
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58647
diff
changeset
|
161 |
private final WinMsiBundler msiBundler = new WinMsiBundler(); |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58647
diff
changeset
|
162 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
163 |
private static native int embedMSI(String exePath, String msiPath); |
57038 | 164 |
} |