@@ -249,6 +249,9 @@ public Path execute(Map<String, ? super Object> params,
249
249
250
250
WinPackagingPipeline .build ()
251
251
.excludeDirFromCopying (outputParentDir )
252
+ .task (PackagingPipeline .PackageTaskID .CREATE_CONFIG_FILES )
253
+ .packageAction (this ::prepareConfigFiles )
254
+ .add ()
252
255
.task (PackagingPipeline .PackageTaskID .CREATE_PACKAGE_FILE )
253
256
.packageAction (this ::buildPackage )
254
257
.add ()
@@ -257,93 +260,38 @@ public Path execute(Map<String, ? super Object> params,
257
260
return outputParentDir .resolve (pkg .packageFileNameWithSuffix ()).toAbsolutePath ();
258
261
}
259
262
260
- private void buildPackage (PackageBuildEnv <WinMsiPackage , AppImageLayout > env ) throws PackagerException , IOException {
263
+ private void prepareConfigFiles (PackageBuildEnv <WinMsiPackage , AppImageLayout > env ) throws PackagerException , IOException {
261
264
prepareProto (env .pkg (), env .env (), env .resolvedLayout ());
262
265
for (var wixFragment : wixFragments ) {
263
266
wixFragment .initFromParams (env .env (), env .pkg ());
264
267
wixFragment .addFilesToConfigRoot ();
265
268
}
266
269
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 ());
295
271
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 ()));
323
273
324
- Path msiOut = outdir . resolve ( pkg . packageFileNameWithSuffix () );
274
+ final var wixVars = createWixVars ( env );
325
275
326
- Log . verbose ( I18N . format ( "message.preparing-msi-config" , msiOut . toAbsolutePath ()) );
276
+ final var wixObjDir = env . env (). buildRoot (). resolve ( "wixobj" );
327
277
328
- final var wixObjDir = env .buildRoot ().resolve ( "wixobj" );
278
+ final var configDir = env .env ().configDir ( );
329
279
330
- final var wixPipeline = WixPipeline .build ()
280
+ final var wixPipelineBuilder = WixPipeline .build ()
331
281
.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 );
334
284
335
285
for (var wixFragment : wixFragments ) {
336
- wixFragment .configureWixPipeline (wixPipeline );
286
+ wixFragment .configureWixPipeline (wixPipelineBuilder );
337
287
}
338
288
339
- Log .verbose (I18N .format ("message.generating-msi" , msiOut .toAbsolutePath ()));
340
-
341
289
switch (wixToolset .getType ()) {
342
290
case Wix3 -> {
343
- wixPipeline .addLightOptions ("-sice:ICE27" );
291
+ wixPipelineBuilder .addLightOptions ("-sice:ICE27" );
344
292
345
- if (!pkg .isSystemWideInstall ()) {
346
- wixPipeline .addLightOptions ("-sice:ICE91" );
293
+ if (!env . pkg () .isSystemWideInstall ()) {
294
+ wixPipelineBuilder .addLightOptions ("-sice:ICE91" );
347
295
}
348
296
}
349
297
case Wix4 -> {
@@ -353,8 +301,6 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
353
301
}
354
302
}
355
303
356
- final Path configDir = env .configDir ();
357
-
358
304
var primaryWxlFiles = Stream .of ("de" , "en" , "ja" , "zh_CN" ).map (loc -> {
359
305
return configDir .resolve ("MsiInstallerStrings_" + loc + ".wxl" );
360
306
}).toList ();
@@ -364,21 +310,21 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
364
310
// Copy standard l10n files.
365
311
for (var path : primaryWxlFiles ) {
366
312
var name = path .getFileName ().toString ();
367
- wixResources .addResource (env .createResource (name ).setPublicName (name ).setCategory (
313
+ wixResources .addResource (env .env (). createResource (name ).setPublicName (name ).setCategory (
368
314
I18N .getString ("resource.wxl-file" )), path );
369
315
}
370
316
371
- wixResources .addResource (env .createResource ("main.wxs" ).setPublicName ("main.wxs" ).
317
+ wixResources .addResource (env .env (). createResource ("main.wxs" ).setPublicName ("main.wxs" ).
372
318
setCategory (I18N .getString ("resource.main-wix-file" )), configDir .resolve ("main.wxs" ));
373
319
374
- wixResources .addResource (env .createResource ("overrides.wxi" ).setPublicName (
320
+ wixResources .addResource (env .env (). createResource ("overrides.wxi" ).setPublicName (
375
321
"overrides.wxi" ).setCategory (I18N .getString ("resource.overrides-wix-file" )),
376
322
configDir .resolve ("overrides.wxi" ));
377
323
378
324
// Filter out custom l10n files that were already used to
379
325
// override primary l10n files. Ignore case filename comparison,
380
326
// both lists are expected to be short.
381
- List <Path > customWxlFiles = env .resourceDir ()
327
+ List <Path > customWxlFiles = env .env (). resourceDir ()
382
328
.map (WinMsiBundler ::getWxlFilesFromDir )
383
329
.orElseGet (Collections ::emptyList )
384
330
.stream ()
@@ -393,7 +339,7 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
393
339
// Copy custom l10n files.
394
340
for (var path : customWxlFiles ) {
395
341
var name = path .getFileName ().toString ();
396
- wixResources .addResource (env .createResource (name ).setPublicName (name ).
342
+ wixResources .addResource (env .env (). createResource (name ).setPublicName (name ).
397
343
setSourceOrder (OverridableResource .Source .ResourceDir ).setCategory (I18N .
398
344
getString ("resource.wxl-file" )), configDir .resolve (name ));
399
345
}
@@ -405,18 +351,18 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
405
351
// Cultures from custom files and a single primary Culture are
406
352
// included into "-cultures" list
407
353
for (var wxl : primaryWxlFiles ) {
408
- wixPipeline .addLightOptions ("-loc" , wxl .toString ());
354
+ wixPipelineBuilder .addLightOptions ("-loc" , wxl .toString ());
409
355
}
410
356
411
357
List <String > cultures = new ArrayList <>();
412
358
for (var wxl : customWxlFiles ) {
413
359
wxl = configDir .resolve (wxl .getFileName ());
414
- wixPipeline .addLightOptions ("-loc" , wxl .toString ());
360
+ wixPipelineBuilder .addLightOptions ("-loc" , wxl .toString ());
415
361
cultures .add (getCultureFromWxlFile (wxl ));
416
362
}
417
363
418
364
// Append a primary culture bases on runtime locale.
419
- final Path primaryWxlFile = env . configDir () .resolve (
365
+ final Path primaryWxlFile = configDir .resolve (
420
366
I18N .getString ("resource.wxl-file-name" ));
421
367
cultures .add (getCultureFromWxlFile (primaryWxlFile ));
422
368
@@ -425,12 +371,12 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
425
371
uniqueCultures .addAll (cultures );
426
372
switch (wixToolset .getType ()) {
427
373
case Wix3 -> {
428
- wixPipeline .addLightOptions (uniqueCultures .stream ().collect (Collectors .joining (";" ,
374
+ wixPipelineBuilder .addLightOptions (uniqueCultures .stream ().collect (Collectors .joining (";" ,
429
375
"-cultures:" , "" )));
430
376
}
431
377
case Wix4 -> {
432
378
uniqueCultures .forEach (culture -> {
433
- wixPipeline .addLightOptions ("-culture" , culture );
379
+ wixPipelineBuilder .addLightOptions ("-culture" , culture );
434
380
});
435
381
}
436
382
default -> {
@@ -439,9 +385,61 @@ private Path buildMSI(BuildEnv env, WinMsiPackage pkg,
439
385
}
440
386
441
387
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 <>();
443
399
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 ;
445
443
}
446
444
447
445
private static List <Path > getWxlFilesFromDir (Path dir ) {
@@ -557,5 +555,6 @@ private static void ensureByMutationFileIsRTF(Path f) {
557
555
558
556
private Path installerIcon ;
559
557
private WixToolset wixToolset ;
558
+ private WixPipeline wixPipeline ;
560
559
private final List <WixFragmentBuilder > wixFragments ;
561
560
}
0 commit comments