author | herrick |
Mon, 17 Jun 2019 14:57:23 -0400 | |
branch | JDK-8200758-branch |
changeset 57411 | 4a80a72a891d |
parent 57407 | 2c14fbeff1dc |
child 57414 | 6eda749d3117 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57103
diff
changeset
|
2 |
* Copyright (c) 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 getDescription() { |
|
57059 | 72 |
return getString("exe.bundler.description"); |
57038 | 73 |
} |
74 |
||
75 |
@Override |
|
76 |
public String getID() { |
|
77 |
return "exe"; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
81 |
public String getBundleType() { |
|
82 |
return "INSTALLER"; |
|
83 |
} |
|
84 |
||
85 |
@Override |
|
86 |
public Collection<BundlerParamInfo<?>> getBundleParameters() { |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
87 |
return new WinMsiBundler().getBundleParameters(); |
57038 | 88 |
} |
89 |
||
90 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
91 |
public File execute(Map<String, ? super Object> params, |
57140 | 92 |
File outputParentDir) throws PackagerException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
93 |
return bundle(params, outputParentDir); |
57038 | 94 |
} |
95 |
||
96 |
@Override |
|
57150 | 97 |
public boolean supported(boolean platformInstaller) { |
57038 | 98 |
return (Platform.getPlatform() == Platform.WINDOWS); |
99 |
} |
|
100 |
||
101 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
102 |
public boolean validate(Map<String, ? super Object> params) |
57038 | 103 |
throws UnsupportedPlatformException, ConfigException { |
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
104 |
return new WinMsiBundler().validate(params); |
57038 | 105 |
} |
106 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
107 |
public File bundle(Map<String, ? super Object> params, File outdir) |
57140 | 108 |
throws PackagerException { |
57407 | 109 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
110 |
File exeImageDir = EXE_IMAGE_DIR.fetchFrom(params); |
57038 | 111 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
112 |
// Write msi to temporary directory. |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
113 |
File msi = new WinMsiBundler().bundle(params, exeImageDir); |
57038 | 114 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
115 |
try { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
116 |
return buildEXE(msi, outdir); |
57038 | 117 |
} catch (IOException ex) { |
57140 | 118 |
Log.verbose(ex); |
119 |
throw new PackagerException(ex); |
|
57038 | 120 |
} |
121 |
} |
|
122 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
123 |
private File buildEXE(File msi, File outdir) |
57038 | 124 |
throws IOException { |
125 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
126 |
Log.verbose(MessageFormat.format( |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
127 |
getString("message.outputting-to-location"), |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
128 |
outdir.getAbsolutePath())); |
57038 | 129 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
130 |
// 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
|
131 |
String exePath = msi.getAbsolutePath(); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
132 |
exePath = exePath.substring(0, exePath.lastIndexOf('.')) + ".exe"; |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
133 |
try (InputStream is = getResourceAsStream(EXE_WRAPPER_NAME)) { |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
134 |
Files.copy(is, Path.of(exePath)); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
135 |
} |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
136 |
// Embed msi in msi wrapper exe. |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
137 |
embedMSI(exePath, msi.getAbsolutePath()); |
57038 | 138 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
139 |
Path dstExePath = Paths.get(outdir.getAbsolutePath(), Path.of(exePath).getFileName().toString()); |
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
140 |
Files.deleteIfExists(dstExePath); |
57038 | 141 |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
142 |
Files.copy(Path.of(exePath), dstExePath); |
57038 | 143 |
|
144 |
Log.verbose(MessageFormat.format( |
|
145 |
getString("message.output-location"), |
|
146 |
outdir.getAbsolutePath())); |
|
147 |
||
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
148 |
return dstExePath.toFile(); |
57038 | 149 |
} |
150 |
||
151 |
private static String getString(String key) |
|
152 |
throws MissingResourceException { |
|
153 |
return I18N.getString(key); |
|
154 |
} |
|
57411
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
155 |
|
4a80a72a891d
8221333: Replace Inno Setup with custom MSI wrapper for .exe bundler
herrick
parents:
57407
diff
changeset
|
156 |
private static native int embedMSI(String exePath, String msiPath); |
57038 | 157 |
} |