author | herrick |
Wed, 16 Oct 2019 09:57:23 -0400 | |
branch | JDK-8200758-branch |
changeset 58647 | 2c43b89b1679 |
parent 58114 | 42df7de58e39 |
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) 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) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
88 |
return WinMsiBundler.isSupported(); |
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 { |
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
99 |
return new WinMsiBundler().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. |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
110 |
File msi = new WinMsiBundler().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 { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
113 |
return buildEXE(msi, outdir); |
57038 | 114 |
} catch (IOException ex) { |
57140 | 115 |
Log.verbose(ex); |
116 |
throw new PackagerException(ex); |
|
57038 | 117 |
} |
118 |
} |
|
119 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
120 |
private File buildEXE(File msi, File outdir) |
57038 | 121 |
throws IOException { |
122 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
123 |
Log.verbose(MessageFormat.format( |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
124 |
getString("message.outputting-to-location"), |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
125 |
outdir.getAbsolutePath())); |
57038 | 126 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
127 |
// 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
|
128 |
String exePath = msi.getAbsolutePath(); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
129 |
exePath = exePath.substring(0, exePath.lastIndexOf('.')) + ".exe"; |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58114
diff
changeset
|
130 |
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
|
131 |
Files.copy(is, Path.of(exePath)); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
132 |
} |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
133 |
// Embed msi in msi wrapper exe. |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
134 |
embedMSI(exePath, msi.getAbsolutePath()); |
57038 | 135 |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
136 |
Path dstExePath = Paths.get(outdir.getAbsolutePath(), |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
137 |
Path.of(exePath).getFileName().toString()); |
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
138 |
Files.deleteIfExists(dstExePath); |
57038 | 139 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
140 |
Files.copy(Path.of(exePath), dstExePath); |
57038 | 141 |
|
142 |
Log.verbose(MessageFormat.format( |
|
143 |
getString("message.output-location"), |
|
144 |
outdir.getAbsolutePath())); |
|
145 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
146 |
return dstExePath.toFile(); |
57038 | 147 |
} |
148 |
||
149 |
private static String getString(String key) |
|
150 |
throws MissingResourceException { |
|
151 |
return I18N.getString(key); |
|
152 |
} |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
153 |
|
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
154 |
private static native int embedMSI(String exePath, String msiPath); |
57038 | 155 |
} |