1
1
/*
2
- * Copyright (c) 2012, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
67
67
import static jdk .jpackage .internal .StandardBundlerParam .TEMP_ROOT ;
68
68
import static jdk .jpackage .internal .StandardBundlerParam .VENDOR ;
69
69
import static jdk .jpackage .internal .StandardBundlerParam .VERSION ;
70
+ import jdk .jpackage .internal .WixToolset .WixToolsetType ;
70
71
import org .w3c .dom .Document ;
71
72
import org .w3c .dom .NodeList ;
72
73
import org .xml .sax .SAXException ;
@@ -253,7 +254,7 @@ public String getBundleType() {
253
254
public boolean supported (boolean platformInstaller ) {
254
255
try {
255
256
if (wixToolset == null ) {
256
- wixToolset = WixTool .toolset ();
257
+ wixToolset = WixTool .createToolset ();
257
258
}
258
259
return true ;
259
260
} catch (ConfigException ce ) {
@@ -300,7 +301,7 @@ public boolean validate(Map<String, ? super Object> params)
300
301
appImageBundler .validate (params );
301
302
302
303
if (wixToolset == null ) {
303
- wixToolset = WixTool .toolset ();
304
+ wixToolset = WixTool .createToolset ();
304
305
}
305
306
306
307
try {
@@ -309,16 +310,17 @@ public boolean validate(Map<String, ? super Object> params)
309
310
throw new ConfigException (ex );
310
311
}
311
312
312
- for (var toolInfo : wixToolset .values ()) {
313
+ for (var tool : wixToolset .getType (). getTools ()) {
313
314
Log .verbose (MessageFormat .format (I18N .getString (
314
- "message.tool-version" ), toolInfo . path . getFileName (),
315
- toolInfo . version ));
315
+ "message.tool-version" ), wixToolset . getToolPath ( tool ).
316
+ getFileName (), wixToolset . getVersion () ));
316
317
}
317
318
318
- wixFragments .forEach (wixFragment -> wixFragment .setWixVersion (
319
- wixToolset .get ( WixTool . Light ). version ));
319
+ wixFragments .forEach (wixFragment -> wixFragment .setWixVersion (wixToolset . getVersion (),
320
+ wixToolset .getType () ));
320
321
321
- wixFragments .get (0 ).logWixFeatures ();
322
+ wixFragments .stream ().map (WixFragmentBuilder ::getLoggableWixFeatures ).flatMap (
323
+ List ::stream ).distinct ().toList ().forEach (Log ::verbose );
322
324
323
325
/********* validate bundle parameters *************/
324
326
@@ -512,22 +514,6 @@ private Map<String, String> prepareMainProjectFile(
512
514
data .put ("JpIsSystemWide" , "yes" );
513
515
}
514
516
515
- // Copy standard l10n files.
516
- for (String loc : Arrays .asList ("de" , "en" , "ja" , "zh_CN" )) {
517
- String fname = "MsiInstallerStrings_" + loc + ".wxl" ;
518
- createResource (fname , params )
519
- .setCategory (I18N .getString ("resource.wxl-file" ))
520
- .saveToFile (configDir .resolve (fname ));
521
- }
522
-
523
- createResource ("main.wxs" , params )
524
- .setCategory (I18N .getString ("resource.main-wix-file" ))
525
- .saveToFile (configDir .resolve ("main.wxs" ));
526
-
527
- createResource ("overrides.wxi" , params )
528
- .setCategory (I18N .getString ("resource.overrides-wix-file" ))
529
- .saveToFile (configDir .resolve ("overrides.wxi" ));
530
-
531
517
return data ;
532
518
}
533
519
@@ -542,13 +528,11 @@ private Path buildMSI(Map<String, ? super Object> params,
542
528
.toString ()));
543
529
544
530
WixPipeline wixPipeline = new WixPipeline ()
545
- .setToolset (wixToolset .entrySet ().stream ().collect (
546
- Collectors .toMap (
547
- entry -> entry .getKey (),
548
- entry -> entry .getValue ().path )))
549
- .setWixObjDir (TEMP_ROOT .fetchFrom (params ).resolve ("wixobj" ))
550
- .setWorkDir (WIN_APP_IMAGE .fetchFrom (params ))
551
- .addSource (CONFIG_ROOT .fetchFrom (params ).resolve ("main.wxs" ), wixVars );
531
+ .setToolset (wixToolset )
532
+ .setWixObjDir (TEMP_ROOT .fetchFrom (params ).resolve ("wixobj" ))
533
+ .setWorkDir (WIN_APP_IMAGE .fetchFrom (params ))
534
+ .addSource (CONFIG_ROOT .fetchFrom (params ).resolve ("main.wxs" ),
535
+ wixVars );
552
536
553
537
for (var wixFragment : wixFragments ) {
554
538
wixFragment .configureWixPipeline (wixPipeline );
@@ -557,16 +541,46 @@ private Path buildMSI(Map<String, ? super Object> params,
557
541
Log .verbose (MessageFormat .format (I18N .getString (
558
542
"message.generating-msi" ), msiOut .toAbsolutePath ().toString ()));
559
543
560
- wixPipeline .addLightOptions ("-sice:ICE27" );
544
+ switch (wixToolset .getType ()) {
545
+ case Wix3 -> {
546
+ wixPipeline .addLightOptions ("-sice:ICE27" );
547
+
548
+ if (!MSI_SYSTEM_WIDE .fetchFrom (params )) {
549
+ wixPipeline .addLightOptions ("-sice:ICE91" );
550
+ }
551
+ }
552
+ case Wix4 -> {
553
+ }
554
+ default -> {
555
+ throw new IllegalArgumentException ();
556
+ }
557
+ }
558
+
559
+ final Path configDir = CONFIG_ROOT .fetchFrom (params );
560
+
561
+ var primaryWxlFiles = Stream .of ("de" , "en" , "ja" , "zh_CN" ).map (loc -> {
562
+ return configDir .resolve ("MsiInstallerStrings_" + loc + ".wxl" );
563
+ }).toList ();
564
+
565
+ var wixResources = new WixSourceConverter .ResourceGroup (wixToolset .getType ());
561
566
562
- if (!MSI_SYSTEM_WIDE .fetchFrom (params )) {
563
- wixPipeline .addLightOptions ("-sice:ICE91" );
567
+ // Copy standard l10n files.
568
+ for (var path : primaryWxlFiles ) {
569
+ var name = path .getFileName ().toString ();
570
+ wixResources .addResource (createResource (name , params ).setPublicName (name ).setCategory (
571
+ I18N .getString ("resource.wxl-file" )), path );
564
572
}
565
573
574
+ wixResources .addResource (createResource ("main.wxs" , params ).setPublicName ("main.wxs" ).
575
+ setCategory (I18N .getString ("resource.main-wix-file" )), configDir .resolve ("main.wxs" ));
576
+
577
+ wixResources .addResource (createResource ("overrides.wxi" , params ).setPublicName (
578
+ "overrides.wxi" ).setCategory (I18N .getString ("resource.overrides-wix-file" )),
579
+ configDir .resolve ("overrides.wxi" ));
580
+
566
581
// Filter out custom l10n files that were already used to
567
582
// override primary l10n files. Ignore case filename comparison,
568
583
// both lists are expected to be short.
569
- List <Path > primaryWxlFiles = getWxlFilesFromDir (params , CONFIG_ROOT );
570
584
List <Path > customWxlFiles = getWxlFilesFromDir (params , RESOURCE_DIR ).stream ()
571
585
.filter (custom -> primaryWxlFiles .stream ().noneMatch (primary ->
572
586
primary .getFileName ().toString ().equalsIgnoreCase (
@@ -577,6 +591,17 @@ private Path buildMSI(Map<String, ? super Object> params,
577
591
custom .getFileName ().toString ())))
578
592
.toList ();
579
593
594
+ // Copy custom l10n files.
595
+ for (var path : customWxlFiles ) {
596
+ var name = path .getFileName ().toString ();
597
+ wixResources .addResource (createResource (name , params ).setPublicName (name ).
598
+ setSourceOrder (OverridableResource .Source .ResourceDir ).setCategory (I18N .
599
+ getString ("resource.wxl-file" )), configDir .resolve (name ));
600
+ }
601
+
602
+ // Save all WiX resources into config dir.
603
+ wixResources .saveResources ();
604
+
580
605
// All l10n files are supplied to WiX with "-loc", but only
581
606
// Cultures from custom files and a single primary Culture are
582
607
// included into "-cultures" list
@@ -586,6 +611,7 @@ private Path buildMSI(Map<String, ? super Object> params,
586
611
587
612
List <String > cultures = new ArrayList <>();
588
613
for (var wxl : customWxlFiles ) {
614
+ wxl = configDir .resolve (wxl .getFileName ());
589
615
wixPipeline .addLightOptions ("-loc" , wxl .toAbsolutePath ().normalize ().toString ());
590
616
cultures .add (getCultureFromWxlFile (wxl ));
591
617
}
@@ -598,8 +624,20 @@ private Path buildMSI(Map<String, ? super Object> params,
598
624
// Build ordered list of unique cultures.
599
625
Set <String > uniqueCultures = new LinkedHashSet <>();
600
626
uniqueCultures .addAll (cultures );
601
- wixPipeline .addLightOptions (uniqueCultures .stream ().collect (
602
- Collectors .joining (";" , "-cultures:" , "" )));
627
+ switch (wixToolset .getType ()) {
628
+ case Wix3 -> {
629
+ wixPipeline .addLightOptions (uniqueCultures .stream ().collect (Collectors .joining (";" ,
630
+ "-cultures:" , "" )));
631
+ }
632
+ case Wix4 -> {
633
+ uniqueCultures .forEach (culture -> {
634
+ wixPipeline .addLightOptions ("-culture" , culture );
635
+ });
636
+ }
637
+ default -> {
638
+ throw new IllegalArgumentException ();
639
+ }
640
+ }
603
641
604
642
wixPipeline .buildMsi (msiOut .toAbsolutePath ());
605
643
@@ -751,7 +789,7 @@ private static OverridableResource initServiceInstallerResource(
751
789
}
752
790
753
791
private Path installerIcon ;
754
- private Map < WixTool , WixTool . ToolInfo > wixToolset ;
792
+ private WixToolset wixToolset ;
755
793
private AppImageBundler appImageBundler ;
756
794
private final List <WixFragmentBuilder > wixFragments ;
757
795
}
0 commit comments