Skip to content

Commit 235d2ed

Browse files
Merge with JDK-8355651 fix
1 parent 48d88e4 commit 235d2ed

File tree

1 file changed

+81
-82
lines changed

1 file changed

+81
-82
lines changed

src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ public Path execute(Map<String, ? super Object> params,
249249

250250
WinPackagingPipeline.build()
251251
.excludeDirFromCopying(outputParentDir)
252+
.task(PackagingPipeline.PackageTaskID.CREATE_CONFIG_FILES)
253+
.packageAction(this::prepareConfigFiles)
254+
.add()
252255
.task(PackagingPipeline.PackageTaskID.CREATE_PACKAGE_FILE)
253256
.packageAction(this::buildPackage)
254257
.add()
@@ -257,93 +260,38 @@ public Path execute(Map<String, ? super Object> params,
257260
return outputParentDir.resolve(pkg.packageFileNameWithSuffix()).toAbsolutePath();
258261
}
259262

260-
private void buildPackage(PackageBuildEnv<WinMsiPackage, AppImageLayout> env) throws PackagerException, IOException {
263+
private void prepareConfigFiles(PackageBuildEnv<WinMsiPackage, AppImageLayout> env) throws PackagerException, IOException {
261264
prepareProto(env.pkg(), env.env(), env.resolvedLayout());
262265
for (var wixFragment : wixFragments) {
263266
wixFragment.initFromParams(env.env(), env.pkg());
264267
wixFragment.addFilesToConfigRoot();
265268
}
266269

267-
Map<String, String> wixVars = prepareMainProjectFile(env);
268-
269-
buildMSI(env.env(), env.pkg(), wixVars, env.outputDir());
270-
}
271-
272-
private Map<String, String> prepareMainProjectFile(PackageBuildEnv<WinMsiPackage, AppImageLayout> env) throws IOException {
273-
Map<String, String> data = new HashMap<>();
274-
275-
final var pkg = env.pkg();
276-
277-
data.put("JpProductCode", pkg.productCode().toString());
278-
data.put("JpProductUpgradeCode", pkg.upgradeCode().toString());
279-
280-
Log.verbose(I18N.format("message.product-code", pkg.productCode()));
281-
Log.verbose(I18N.format("message.upgrade-code", pkg.upgradeCode()));
282-
283-
data.put("JpAllowUpgrades", "yes");
284-
if (!pkg.isRuntimeInstaller()) {
285-
data.put("JpAllowDowngrades", "yes");
286-
}
287-
288-
data.put("JpAppName", pkg.packageName());
289-
data.put("JpAppDescription", pkg.description());
290-
data.put("JpAppVendor", pkg.app().vendor());
291-
data.put("JpAppVersion", pkg.version());
292-
if (Files.exists(installerIcon)) {
293-
data.put("JpIcon", installerIcon.toString());
294-
}
270+
final var msiOut = env.outputDir().resolve(env.pkg().packageFileNameWithSuffix());
295271

296-
pkg.helpURL().ifPresent(value -> {
297-
data.put("JpHelpURL", value);
298-
});
299-
300-
pkg.updateURL().ifPresent(value -> {
301-
data.put("JpUpdateURL", value);
302-
});
303-
304-
pkg.aboutURL().ifPresent(value -> {
305-
data.put("JpAboutURL", value);
306-
});
307-
308-
data.put("JpAppSizeKb", Long.toString(AppImageLayout.toPathGroup(
309-
env.resolvedLayout()).sizeInBytes() >> 10));
310-
311-
data.put("JpConfigDir", env.env().configDir().toAbsolutePath().toString());
312-
313-
if (pkg.isSystemWideInstall()) {
314-
data.put("JpIsSystemWide", "yes");
315-
}
316-
317-
return data;
318-
}
319-
320-
private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
321-
Map<String, String> wixVars, Path outdir)
322-
throws IOException {
272+
Log.verbose(I18N.format("message.preparing-msi-config", msiOut.toAbsolutePath()));
323273

324-
Path msiOut = outdir.resolve(pkg.packageFileNameWithSuffix());
274+
final var wixVars = createWixVars(env);
325275

326-
Log.verbose(I18N.format("message.preparing-msi-config", msiOut.toAbsolutePath()));
276+
final var wixObjDir = env.env().buildRoot().resolve("wixobj");
327277

328-
final var wixObjDir = env.buildRoot().resolve("wixobj");
278+
final var configDir = env.env().configDir();
329279

330-
final var wixPipeline = WixPipeline.build()
280+
final var wixPipelineBuilder = WixPipeline.build()
331281
.setWixObjDir(wixObjDir)
332-
.setWorkDir(env.appImageDir())
333-
.addSource(env.configDir().resolve("main.wxs"), wixVars);
282+
.setWorkDir(env.env().appImageDir())
283+
.addSource(configDir.resolve("main.wxs"), wixVars);
334284

335285
for (var wixFragment : wixFragments) {
336-
wixFragment.configureWixPipeline(wixPipeline);
286+
wixFragment.configureWixPipeline(wixPipelineBuilder);
337287
}
338288

339-
Log.verbose(I18N.format("message.generating-msi", msiOut.toAbsolutePath()));
340-
341289
switch (wixToolset.getType()) {
342290
case Wix3 -> {
343-
wixPipeline.addLightOptions("-sice:ICE27");
291+
wixPipelineBuilder.addLightOptions("-sice:ICE27");
344292

345-
if (!pkg.isSystemWideInstall()) {
346-
wixPipeline.addLightOptions("-sice:ICE91");
293+
if (!env.pkg().isSystemWideInstall()) {
294+
wixPipelineBuilder.addLightOptions("-sice:ICE91");
347295
}
348296
}
349297
case Wix4 -> {
@@ -353,8 +301,6 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
353301
}
354302
}
355303

356-
final Path configDir = env.configDir();
357-
358304
var primaryWxlFiles = Stream.of("de", "en", "ja", "zh_CN").map(loc -> {
359305
return configDir.resolve("MsiInstallerStrings_" + loc + ".wxl");
360306
}).toList();
@@ -364,21 +310,21 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
364310
// Copy standard l10n files.
365311
for (var path : primaryWxlFiles) {
366312
var name = path.getFileName().toString();
367-
wixResources.addResource(env.createResource(name).setPublicName(name).setCategory(
313+
wixResources.addResource(env.env().createResource(name).setPublicName(name).setCategory(
368314
I18N.getString("resource.wxl-file")), path);
369315
}
370316

371-
wixResources.addResource(env.createResource("main.wxs").setPublicName("main.wxs").
317+
wixResources.addResource(env.env().createResource("main.wxs").setPublicName("main.wxs").
372318
setCategory(I18N.getString("resource.main-wix-file")), configDir.resolve("main.wxs"));
373319

374-
wixResources.addResource(env.createResource("overrides.wxi").setPublicName(
320+
wixResources.addResource(env.env().createResource("overrides.wxi").setPublicName(
375321
"overrides.wxi").setCategory(I18N.getString("resource.overrides-wix-file")),
376322
configDir.resolve("overrides.wxi"));
377323

378324
// Filter out custom l10n files that were already used to
379325
// override primary l10n files. Ignore case filename comparison,
380326
// both lists are expected to be short.
381-
List<Path> customWxlFiles = env.resourceDir()
327+
List<Path> customWxlFiles = env.env().resourceDir()
382328
.map(WinMsiBundler::getWxlFilesFromDir)
383329
.orElseGet(Collections::emptyList)
384330
.stream()
@@ -393,7 +339,7 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
393339
// Copy custom l10n files.
394340
for (var path : customWxlFiles) {
395341
var name = path.getFileName().toString();
396-
wixResources.addResource(env.createResource(name).setPublicName(name).
342+
wixResources.addResource(env.env().createResource(name).setPublicName(name).
397343
setSourceOrder(OverridableResource.Source.ResourceDir).setCategory(I18N.
398344
getString("resource.wxl-file")), configDir.resolve(name));
399345
}
@@ -405,18 +351,18 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
405351
// Cultures from custom files and a single primary Culture are
406352
// included into "-cultures" list
407353
for (var wxl : primaryWxlFiles) {
408-
wixPipeline.addLightOptions("-loc", wxl.toString());
354+
wixPipelineBuilder.addLightOptions("-loc", wxl.toString());
409355
}
410356

411357
List<String> cultures = new ArrayList<>();
412358
for (var wxl : customWxlFiles) {
413359
wxl = configDir.resolve(wxl.getFileName());
414-
wixPipeline.addLightOptions("-loc", wxl.toString());
360+
wixPipelineBuilder.addLightOptions("-loc", wxl.toString());
415361
cultures.add(getCultureFromWxlFile(wxl));
416362
}
417363

418364
// Append a primary culture bases on runtime locale.
419-
final Path primaryWxlFile = env.configDir().resolve(
365+
final Path primaryWxlFile = configDir.resolve(
420366
I18N.getString("resource.wxl-file-name"));
421367
cultures.add(getCultureFromWxlFile(primaryWxlFile));
422368

@@ -425,12 +371,12 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
425371
uniqueCultures.addAll(cultures);
426372
switch (wixToolset.getType()) {
427373
case Wix3 -> {
428-
wixPipeline.addLightOptions(uniqueCultures.stream().collect(Collectors.joining(";",
374+
wixPipelineBuilder.addLightOptions(uniqueCultures.stream().collect(Collectors.joining(";",
429375
"-cultures:", "")));
430376
}
431377
case Wix4 -> {
432378
uniqueCultures.forEach(culture -> {
433-
wixPipeline.addLightOptions("-culture", culture);
379+
wixPipelineBuilder.addLightOptions("-culture", culture);
434380
});
435381
}
436382
default -> {
@@ -439,9 +385,61 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
439385
}
440386

441387
Files.createDirectories(wixObjDir);
442-
wixPipeline.create(wixToolset).buildMsi(msiOut.toAbsolutePath());
388+
wixPipeline = wixPipelineBuilder.create(wixToolset);
389+
}
390+
391+
private void buildPackage(PackageBuildEnv<WinMsiPackage, AppImageLayout> env) throws PackagerException, IOException {
392+
final var msiOut = env.outputDir().resolve(env.pkg().packageFileNameWithSuffix());
393+
Log.verbose(I18N.format("message.generating-msi", msiOut.toAbsolutePath()));
394+
wixPipeline.buildMsi(msiOut.toAbsolutePath());
395+
}
396+
397+
private Map<String, String> createWixVars(PackageBuildEnv<WinMsiPackage, AppImageLayout> env) throws IOException {
398+
Map<String, String> data = new HashMap<>();
443399

444-
return msiOut;
400+
final var pkg = env.pkg();
401+
402+
data.put("JpProductCode", pkg.productCode().toString());
403+
data.put("JpProductUpgradeCode", pkg.upgradeCode().toString());
404+
405+
Log.verbose(I18N.format("message.product-code", pkg.productCode()));
406+
Log.verbose(I18N.format("message.upgrade-code", pkg.upgradeCode()));
407+
408+
data.put("JpAllowUpgrades", "yes");
409+
if (!pkg.isRuntimeInstaller()) {
410+
data.put("JpAllowDowngrades", "yes");
411+
}
412+
413+
data.put("JpAppName", pkg.packageName());
414+
data.put("JpAppDescription", pkg.description());
415+
data.put("JpAppVendor", pkg.app().vendor());
416+
data.put("JpAppVersion", pkg.version());
417+
if (Files.exists(installerIcon)) {
418+
data.put("JpIcon", installerIcon.toString());
419+
}
420+
421+
pkg.helpURL().ifPresent(value -> {
422+
data.put("JpHelpURL", value);
423+
});
424+
425+
pkg.updateURL().ifPresent(value -> {
426+
data.put("JpUpdateURL", value);
427+
});
428+
429+
pkg.aboutURL().ifPresent(value -> {
430+
data.put("JpAboutURL", value);
431+
});
432+
433+
data.put("JpAppSizeKb", Long.toString(AppImageLayout.toPathGroup(
434+
env.resolvedLayout()).sizeInBytes() >> 10));
435+
436+
data.put("JpConfigDir", env.env().configDir().toAbsolutePath().toString());
437+
438+
if (pkg.isSystemWideInstall()) {
439+
data.put("JpIsSystemWide", "yes");
440+
}
441+
442+
return data;
445443
}
446444

447445
private static List<Path> getWxlFilesFromDir(Path dir) {
@@ -557,5 +555,6 @@ private static void ensureByMutationFileIsRTF(Path f) {
557555

558556
private Path installerIcon;
559557
private WixToolset wixToolset;
558+
private WixPipeline wixPipeline;
560559
private final List<WixFragmentBuilder> wixFragments;
561560
}

0 commit comments

Comments
 (0)