author | herrick |
Wed, 27 Mar 2019 07:45:21 -0400 | |
branch | JDK-8200758-branch |
changeset 57287 | 90fa9a095959 |
parent 57259 | a84c657c713d |
child 57396 | 3944e4c2f779 |
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) 2015, 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.File; |
|
29 |
import java.io.FileOutputStream; |
|
30 |
import java.io.IOException; |
|
31 |
import java.io.InputStream; |
|
32 |
import java.io.OutputStream; |
|
33 |
import java.io.OutputStreamWriter; |
|
34 |
import java.io.UncheckedIOException; |
|
35 |
import java.io.Writer; |
|
36 |
import java.io.BufferedWriter; |
|
37 |
import java.io.FileWriter; |
|
57287
90fa9a095959
JDK-8221525: jpackage fails with non-ASCII characters in --copyright
herrick
parents:
57259
diff
changeset
|
38 |
import java.nio.charset.StandardCharsets; |
57038 | 39 |
import java.nio.file.Files; |
40 |
import java.nio.file.Path; |
|
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
41 |
import java.nio.file.StandardCopyOption; |
57038 | 42 |
import java.nio.file.attribute.PosixFilePermission; |
43 |
import java.text.MessageFormat; |
|
44 |
import java.util.HashMap; |
|
45 |
import java.util.List; |
|
46 |
import java.util.Map; |
|
47 |
import java.util.Objects; |
|
48 |
import java.util.ResourceBundle; |
|
49 |
import java.util.Set; |
|
50 |
import java.util.concurrent.atomic.AtomicReference; |
|
51 |
import java.util.regex.Pattern; |
|
52 |
import java.util.stream.Stream; |
|
53 |
||
57039 | 54 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57038 | 55 |
|
56 |
public class WindowsAppImageBuilder extends AbstractAppImageBuilder { |
|
57 |
||
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
58 |
static { |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
59 |
System.loadLibrary("jpackage"); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
60 |
} |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
61 |
|
57059 | 62 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
63 |
"jdk.jpackage.internal.resources.WinResources"); |
|
57038 | 64 |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
65 |
private final static String LIBRARY_NAME = "applauncher.dll"; |
57038 | 66 |
private final static String REDIST_MSVCR = "vcruntimeVS_VER.dll"; |
67 |
private final static String REDIST_MSVCP = "msvcpVS_VER.dll"; |
|
68 |
||
69 |
private final static String TEMPLATE_APP_ICON ="javalogo_white_48.ico"; |
|
70 |
||
71 |
private static final String EXECUTABLE_PROPERTIES_TEMPLATE = |
|
57059 | 72 |
"WinLauncher.template"; |
57038 | 73 |
|
74 |
private final Path root; |
|
75 |
private final Path appDir; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
76 |
private final Path appModsDir; |
57038 | 77 |
private final Path runtimeDir; |
78 |
private final Path mdir; |
|
79 |
||
80 |
private final Map<String, ? super Object> params; |
|
81 |
||
82 |
public static final BundlerParamInfo<Boolean> REBRAND_EXECUTABLE = |
|
83 |
new WindowsBundlerParam<>( |
|
84 |
"win.launcher.rebrand", |
|
85 |
Boolean.class, |
|
86 |
params -> Boolean.TRUE, |
|
87 |
(s, p) -> Boolean.valueOf(s)); |
|
88 |
||
89 |
public static final BundlerParamInfo<File> ICON_ICO = |
|
90 |
new StandardBundlerParam<>( |
|
91 |
"icon.ico", |
|
92 |
File.class, |
|
93 |
params -> { |
|
94 |
File f = ICON.fetchFrom(params); |
|
95 |
if (f != null && !f.getName().toLowerCase().endsWith(".ico")) { |
|
96 |
Log.error(MessageFormat.format( |
|
97 |
I18N.getString("message.icon-not-ico"), f)); |
|
98 |
return null; |
|
99 |
} |
|
100 |
return f; |
|
101 |
}, |
|
102 |
(s, p) -> new File(s)); |
|
103 |
||
104 |
public static final StandardBundlerParam<Boolean> CONSOLE_HINT = |
|
105 |
new WindowsBundlerParam<>( |
|
106 |
Arguments.CLIOptions.WIN_CONSOLE_HINT.getId(), |
|
107 |
Boolean.class, |
|
108 |
params -> false, |
|
109 |
// valueOf(null) is false, |
|
110 |
// and we actually do want null in some cases |
|
111 |
(s, p) -> (s == null |
|
112 |
|| "null".equalsIgnoreCase(s)) ? true : Boolean.valueOf(s)); |
|
113 |
||
114 |
public WindowsAppImageBuilder(Map<String, Object> config, Path imageOutDir) |
|
115 |
throws IOException { |
|
116 |
super(config, |
|
117 |
imageOutDir.resolve(APP_NAME.fetchFrom(config) + "/runtime")); |
|
118 |
||
119 |
Objects.requireNonNull(imageOutDir); |
|
120 |
||
121 |
this.params = config; |
|
122 |
||
123 |
this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params)); |
|
124 |
this.appDir = root.resolve("app"); |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
125 |
this.appModsDir = appDir.resolve("mods"); |
57038 | 126 |
this.runtimeDir = root.resolve("runtime"); |
127 |
this.mdir = runtimeDir.resolve("lib"); |
|
128 |
Files.createDirectories(appDir); |
|
129 |
Files.createDirectories(runtimeDir); |
|
130 |
} |
|
131 |
||
132 |
public WindowsAppImageBuilder(String jreName, Path imageOutDir) |
|
133 |
throws IOException { |
|
134 |
super(null, imageOutDir.resolve(jreName)); |
|
135 |
||
136 |
Objects.requireNonNull(imageOutDir); |
|
137 |
||
138 |
this.params = null; |
|
139 |
this.root = imageOutDir.resolve(jreName); |
|
140 |
this.appDir = null; |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
141 |
this.appModsDir = null; |
57038 | 142 |
this.runtimeDir = root; |
143 |
this.mdir = runtimeDir.resolve("lib"); |
|
144 |
Files.createDirectories(runtimeDir); |
|
145 |
} |
|
146 |
||
147 |
private Path destFile(String dir, String filename) { |
|
148 |
return runtimeDir.resolve(dir).resolve(filename); |
|
149 |
} |
|
150 |
||
151 |
private void writeEntry(InputStream in, Path dstFile) throws IOException { |
|
152 |
Files.createDirectories(dstFile.getParent()); |
|
153 |
Files.copy(in, dstFile); |
|
154 |
} |
|
155 |
||
156 |
private void writeSymEntry(Path dstFile, Path target) throws IOException { |
|
157 |
Files.createDirectories(dstFile.getParent()); |
|
158 |
Files.createLink(dstFile, target); |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* chmod ugo+x file |
|
163 |
*/ |
|
164 |
private void setExecutable(Path file) { |
|
165 |
try { |
|
166 |
Set<PosixFilePermission> perms = |
|
167 |
Files.getPosixFilePermissions(file); |
|
168 |
perms.add(PosixFilePermission.OWNER_EXECUTE); |
|
169 |
perms.add(PosixFilePermission.GROUP_EXECUTE); |
|
170 |
perms.add(PosixFilePermission.OTHERS_EXECUTE); |
|
171 |
Files.setPosixFilePermissions(file, perms); |
|
172 |
} catch (IOException ioe) { |
|
173 |
throw new UncheckedIOException(ioe); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
private static void createUtf8File(File file, String content) |
|
178 |
throws IOException { |
|
179 |
try (OutputStream fout = new FileOutputStream(file); |
|
180 |
Writer output = new OutputStreamWriter(fout, "UTF-8")) { |
|
181 |
output.write(content); |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
public static String getLauncherName(Map<String, ? super Object> p) { |
|
57119 | 186 |
return APP_NAME.fetchFrom(p) + ".exe"; |
57038 | 187 |
} |
188 |
||
189 |
// Returns launcher resource name for launcher we need to use. |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
190 |
public static String getLauncherResourceName( |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
191 |
Map<String, ? super Object> p) { |
57038 | 192 |
if (CONSOLE_HINT.fetchFrom(p)) { |
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
193 |
return "jpackageapplauncher.exe"; |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
194 |
} else { |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
195 |
return "jpackageapplauncherw.exe"; |
57038 | 196 |
} |
197 |
} |
|
198 |
||
199 |
public static String getLauncherCfgName(Map<String, ? super Object> p) { |
|
57119 | 200 |
return "app/" + APP_NAME.fetchFrom(p) +".cfg"; |
57038 | 201 |
} |
202 |
||
203 |
private File getConfig_AppIcon(Map<String, ? super Object> params) { |
|
204 |
return new File(getConfigRoot(params), |
|
57119 | 205 |
APP_NAME.fetchFrom(params) + ".ico"); |
57038 | 206 |
} |
207 |
||
208 |
private File getConfig_ExecutableProperties( |
|
209 |
Map<String, ? super Object> params) { |
|
210 |
return new File(getConfigRoot(params), |
|
57119 | 211 |
APP_NAME.fetchFrom(params) + ".properties"); |
57038 | 212 |
} |
213 |
||
214 |
File getConfigRoot(Map<String, ? super Object> params) { |
|
215 |
return CONFIG_ROOT.fetchFrom(params); |
|
216 |
} |
|
217 |
||
218 |
@Override |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
219 |
public Path getAppDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
220 |
return appDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
221 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
222 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
223 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
224 |
public Path getAppModsDir() { |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
225 |
return appModsDir; |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
226 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
227 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
228 |
@Override |
57038 | 229 |
public void prepareApplicationFiles() throws IOException { |
230 |
Map<String, ? super Object> originalParams = new HashMap<>(params); |
|
231 |
File rootFile = root.toFile(); |
|
232 |
if (!rootFile.isDirectory() && !rootFile.mkdirs()) { |
|
233 |
throw new RuntimeException(MessageFormat.format(I18N.getString( |
|
234 |
"error.cannot-create-output-dir"), rootFile.getAbsolutePath())); |
|
235 |
} |
|
236 |
if (!rootFile.canWrite()) { |
|
237 |
throw new RuntimeException(MessageFormat.format( |
|
238 |
I18N.getString("error.cannot-write-to-output-dir"), |
|
239 |
rootFile.getAbsolutePath())); |
|
240 |
} |
|
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
241 |
// create the .exe launchers |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
242 |
createLauncherForEntryPoint(params); |
57038 | 243 |
|
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
244 |
// copy the jars |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
245 |
copyApplication(params); |
57038 | 246 |
|
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
247 |
// copy in the needed libraries |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
248 |
try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
249 |
Files.copy(is_lib, root.resolve(LIBRARY_NAME)); |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
250 |
} |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
251 |
|
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
252 |
copyMSVCDLLs(); |
57038 | 253 |
|
57256 | 254 |
// create the additional launcher(s), if any |
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
255 |
List<Map<String, ? super Object>> entryPoints = |
57256 | 256 |
StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params); |
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
257 |
for (Map<String, ? super Object> entryPoint : entryPoints) { |
57259
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
258 |
createLauncherForEntryPoint( |
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
259 |
AddLauncherArguments.merge(originalParams, entryPoint)); |
57038 | 260 |
} |
261 |
} |
|
262 |
||
263 |
@Override |
|
57070 | 264 |
public void prepareJreFiles() throws IOException {} |
57038 | 265 |
|
266 |
private void copyMSVCDLLs() throws IOException { |
|
267 |
AtomicReference<IOException> ioe = new AtomicReference<>(); |
|
268 |
try (Stream<Path> files = Files.list(runtimeDir.resolve("bin"))) { |
|
269 |
files.filter(p -> Pattern.matches( |
|
270 |
"^(vcruntime|msvcp|msvcr|ucrtbase|api-ms-win-).*\\.dll$", |
|
271 |
p.toFile().getName().toLowerCase())) |
|
272 |
.forEach(p -> { |
|
273 |
try { |
|
274 |
Files.copy(p, root.resolve((p.toFile().getName()))); |
|
275 |
} catch (IOException e) { |
|
276 |
ioe.set(e); |
|
277 |
} |
|
278 |
}); |
|
279 |
} |
|
280 |
||
281 |
IOException e = ioe.get(); |
|
282 |
if (e != null) { |
|
283 |
throw e; |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
// TODO: do we still need this? |
|
288 |
private boolean copyMSVCDLLs(String VS_VER) throws IOException { |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57078
diff
changeset
|
289 |
final InputStream REDIST_MSVCR_URL = getResourceAsStream( |
57038 | 290 |
REDIST_MSVCR.replaceAll("VS_VER", VS_VER)); |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57078
diff
changeset
|
291 |
final InputStream REDIST_MSVCP_URL = getResourceAsStream( |
57038 | 292 |
REDIST_MSVCP.replaceAll("VS_VER", VS_VER)); |
293 |
||
294 |
if (REDIST_MSVCR_URL != null && REDIST_MSVCP_URL != null) { |
|
295 |
Files.copy( |
|
296 |
REDIST_MSVCR_URL, |
|
297 |
root.resolve(REDIST_MSVCR.replaceAll("VS_VER", VS_VER))); |
|
298 |
Files.copy( |
|
299 |
REDIST_MSVCP_URL, |
|
300 |
root.resolve(REDIST_MSVCP.replaceAll("VS_VER", VS_VER))); |
|
301 |
return true; |
|
302 |
} |
|
303 |
||
304 |
return false; |
|
305 |
} |
|
306 |
||
307 |
private void validateValueAndPut( |
|
308 |
Map<String, String> data, String key, |
|
309 |
BundlerParamInfo<String> param, |
|
310 |
Map<String, ? super Object> params) { |
|
311 |
String value = param.fetchFrom(params); |
|
312 |
if (value.contains("\r") || value.contains("\n")) { |
|
313 |
Log.error("Configuration Parameter " + param.getID() |
|
314 |
+ " contains multiple lines of text, ignore it"); |
|
315 |
data.put(key, ""); |
|
316 |
return; |
|
317 |
} |
|
318 |
data.put(key, value); |
|
319 |
} |
|
320 |
||
321 |
protected void prepareExecutableProperties( |
|
322 |
Map<String, ? super Object> params) throws IOException { |
|
323 |
Map<String, String> data = new HashMap<>(); |
|
324 |
||
325 |
// mapping Java parameters in strings for version resource |
|
326 |
validateValueAndPut(data, "COMPANY_NAME", VENDOR, params); |
|
327 |
validateValueAndPut(data, "FILE_DESCRIPTION", DESCRIPTION, params); |
|
328 |
validateValueAndPut(data, "FILE_VERSION", VERSION, params); |
|
329 |
data.put("INTERNAL_NAME", getLauncherName(params)); |
|
330 |
validateValueAndPut(data, "LEGAL_COPYRIGHT", COPYRIGHT, params); |
|
331 |
data.put("ORIGINAL_FILENAME", getLauncherName(params)); |
|
332 |
validateValueAndPut(data, "PRODUCT_NAME", APP_NAME, params); |
|
333 |
validateValueAndPut(data, "PRODUCT_VERSION", VERSION, params); |
|
334 |
||
57287
90fa9a095959
JDK-8221525: jpackage fails with non-ASCII characters in --copyright
herrick
parents:
57259
diff
changeset
|
335 |
try (Writer w = Files.newBufferedWriter( |
90fa9a095959
JDK-8221525: jpackage fails with non-ASCII characters in --copyright
herrick
parents:
57259
diff
changeset
|
336 |
getConfig_ExecutableProperties(params).toPath(), |
90fa9a095959
JDK-8221525: jpackage fails with non-ASCII characters in --copyright
herrick
parents:
57259
diff
changeset
|
337 |
StandardCharsets.UTF_8)) { |
57215
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
338 |
String content = preprocessTextResource( |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
339 |
getConfig_ExecutableProperties(params).getName(), |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
340 |
I18N.getString("resource.executable-properties-template"), |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
341 |
EXECUTABLE_PROPERTIES_TEMPLATE, data, |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
342 |
VERBOSE.fetchFrom(params), |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
343 |
RESOURCE_DIR.fetchFrom(params)); |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
344 |
w.write(content); |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
345 |
} |
57038 | 346 |
} |
347 |
||
348 |
private void createLauncherForEntryPoint( |
|
349 |
Map<String, ? super Object> p) throws IOException { |
|
350 |
||
351 |
File launcherIcon = ICON_ICO.fetchFrom(p); |
|
352 |
File icon = launcherIcon != null ? |
|
353 |
launcherIcon : ICON_ICO.fetchFrom(params); |
|
354 |
File iconTarget = getConfig_AppIcon(p); |
|
355 |
||
356 |
InputStream in = locateResource( |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57078
diff
changeset
|
357 |
APP_NAME.fetchFrom(params) + ".ico", |
57038 | 358 |
"icon", |
359 |
TEMPLATE_APP_ICON, |
|
360 |
icon, |
|
361 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57078
diff
changeset
|
362 |
RESOURCE_DIR.fetchFrom(params)); |
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
363 |
|
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
364 |
Files.copy(in, iconTarget.toPath(), |
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
365 |
StandardCopyOption.REPLACE_EXISTING); |
57038 | 366 |
|
367 |
writeCfgFile(p, root.resolve( |
|
368 |
getLauncherCfgName(p)).toFile(), "$APPDIR\\runtime"); |
|
369 |
||
370 |
prepareExecutableProperties(p); |
|
371 |
||
372 |
// Copy executable root folder |
|
373 |
Path executableFile = root.resolve(getLauncherName(p)); |
|
374 |
try (InputStream is_launcher = |
|
375 |
getResourceAsStream(getLauncherResourceName(p))) { |
|
376 |
writeEntry(is_launcher, executableFile); |
|
377 |
} |
|
378 |
||
379 |
File launcher = executableFile.toFile(); |
|
380 |
launcher.setWritable(true, true); |
|
381 |
||
382 |
// Update branding of EXE file |
|
383 |
if (REBRAND_EXECUTABLE.fetchFrom(p)) { |
|
384 |
try { |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
385 |
String tempDirectory = WindowsDefender.getUserTempDirectory(); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
386 |
if (Arguments.CLIOptions.context().userProvidedBuildRoot) { |
57256 | 387 |
tempDirectory = TEMP_ROOT.fetchFrom(p).getAbsolutePath(); |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
388 |
} |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
389 |
if (WindowsDefender.isThereAPotentialWindowsDefenderIssue( |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
390 |
tempDirectory)) { |
57038 | 391 |
Log.error(MessageFormat.format(I18N.getString( |
392 |
"message.potential.windows.defender.issue"), |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
393 |
tempDirectory)); |
57038 | 394 |
} |
395 |
||
396 |
launcher.setWritable(true); |
|
397 |
||
398 |
if (iconTarget.exists()) { |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
399 |
iconSwap(iconTarget.getAbsolutePath(), |
57038 | 400 |
launcher.getAbsolutePath()); |
401 |
} |
|
402 |
||
403 |
File executableProperties = getConfig_ExecutableProperties(p); |
|
404 |
||
405 |
if (executableProperties.exists()) { |
|
57215
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
406 |
if (versionSwap(executableProperties.getAbsolutePath(), |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
407 |
launcher.getAbsolutePath()) != 0) { |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
408 |
throw new RuntimeException(MessageFormat.format( |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
409 |
I18N.getString("error.version-swap"), |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
410 |
executableProperties.getAbsolutePath())); |
62db1c695d13
8218681: Windows exe's generated by jpackage have wrong info
herrick
parents:
57151
diff
changeset
|
411 |
} |
57038 | 412 |
} |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
413 |
} finally { |
57038 | 414 |
executableFile.toFile().setReadOnly(); |
415 |
} |
|
416 |
} |
|
417 |
||
418 |
Files.copy(iconTarget.toPath(), |
|
419 |
root.resolve(APP_NAME.fetchFrom(p) + ".ico")); |
|
420 |
} |
|
421 |
||
422 |
private void copyApplication(Map<String, ? super Object> params) |
|
423 |
throws IOException { |
|
424 |
List<RelativeFileSet> appResourcesList = |
|
425 |
APP_RESOURCES_LIST.fetchFrom(params); |
|
426 |
if (appResourcesList == null) { |
|
427 |
throw new RuntimeException("Null app resources?"); |
|
428 |
} |
|
429 |
for (RelativeFileSet appResources : appResourcesList) { |
|
430 |
if (appResources == null) { |
|
431 |
throw new RuntimeException("Null app resources?"); |
|
432 |
} |
|
433 |
File srcdir = appResources.getBaseDirectory(); |
|
434 |
for (String fname : appResources.getIncludedFiles()) { |
|
435 |
copyEntry(appDir, srcdir, fname); |
|
436 |
} |
|
437 |
} |
|
438 |
} |
|
439 |
||
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
440 |
private static native int iconSwap(String iconTarget, String launcher); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
441 |
|
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
442 |
private static native int versionSwap(String executableProperties, String launcher); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57119
diff
changeset
|
443 |
|
57038 | 444 |
} |