11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
6767import static jdk .jpackage .internal .StandardBundlerParam .TEMP_ROOT ;
6868import static jdk .jpackage .internal .StandardBundlerParam .VENDOR ;
6969import static jdk .jpackage .internal .StandardBundlerParam .VERSION ;
70+ import jdk .jpackage .internal .WixToolset .WixToolsetType ;
7071import org .w3c .dom .Document ;
7172import org .w3c .dom .NodeList ;
7273import org .xml .sax .SAXException ;
@@ -253,7 +254,7 @@ public String getBundleType() {
253254 public boolean supported (boolean platformInstaller ) {
254255 try {
255256 if (wixToolset == null ) {
256- wixToolset = WixTool .toolset ();
257+ wixToolset = WixTool .createToolset ();
257258 }
258259 return true ;
259260 } catch (ConfigException ce ) {
@@ -300,7 +301,7 @@ public boolean validate(Map<String, ? super Object> params)
300301 appImageBundler .validate (params );
301302
302303 if (wixToolset == null ) {
303- wixToolset = WixTool .toolset ();
304+ wixToolset = WixTool .createToolset ();
304305 }
305306
306307 try {
@@ -309,16 +310,17 @@ public boolean validate(Map<String, ? super Object> params)
309310 throw new ConfigException (ex );
310311 }
311312
312- for (var toolInfo : wixToolset .values ()) {
313+ for (var tool : wixToolset .getType (). getTools ()) {
313314 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 () ));
316317 }
317318
318- wixFragments .forEach (wixFragment -> wixFragment .setWixVersion (
319- wixToolset .get ( WixTool . Light ). version ));
319+ wixFragments .forEach (wixFragment -> wixFragment .setWixVersion (wixToolset . getVersion (),
320+ wixToolset .getType () ));
320321
321- wixFragments .get (0 ).logWixFeatures ();
322+ wixFragments .stream ().map (WixFragmentBuilder ::getLoggableWixFeatures ).flatMap (
323+ List ::stream ).distinct ().toList ().forEach (Log ::verbose );
322324
323325 /********* validate bundle parameters *************/
324326
@@ -512,22 +514,6 @@ private Map<String, String> prepareMainProjectFile(
512514 data .put ("JpIsSystemWide" , "yes" );
513515 }
514516
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-
531517 return data ;
532518 }
533519
@@ -542,13 +528,11 @@ private Path buildMSI(Map<String, ? super Object> params,
542528 .toString ()));
543529
544530 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 );
552536
553537 for (var wixFragment : wixFragments ) {
554538 wixFragment .configureWixPipeline (wixPipeline );
@@ -557,16 +541,46 @@ private Path buildMSI(Map<String, ? super Object> params,
557541 Log .verbose (MessageFormat .format (I18N .getString (
558542 "message.generating-msi" ), msiOut .toAbsolutePath ().toString ()));
559543
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 ());
561566
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 );
564572 }
565573
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+
566581 // Filter out custom l10n files that were already used to
567582 // override primary l10n files. Ignore case filename comparison,
568583 // both lists are expected to be short.
569- List <Path > primaryWxlFiles = getWxlFilesFromDir (params , CONFIG_ROOT );
570584 List <Path > customWxlFiles = getWxlFilesFromDir (params , RESOURCE_DIR ).stream ()
571585 .filter (custom -> primaryWxlFiles .stream ().noneMatch (primary ->
572586 primary .getFileName ().toString ().equalsIgnoreCase (
@@ -577,6 +591,17 @@ private Path buildMSI(Map<String, ? super Object> params,
577591 custom .getFileName ().toString ())))
578592 .toList ();
579593
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+
580605 // All l10n files are supplied to WiX with "-loc", but only
581606 // Cultures from custom files and a single primary Culture are
582607 // included into "-cultures" list
@@ -586,6 +611,7 @@ private Path buildMSI(Map<String, ? super Object> params,
586611
587612 List <String > cultures = new ArrayList <>();
588613 for (var wxl : customWxlFiles ) {
614+ wxl = configDir .resolve (wxl .getFileName ());
589615 wixPipeline .addLightOptions ("-loc" , wxl .toAbsolutePath ().normalize ().toString ());
590616 cultures .add (getCultureFromWxlFile (wxl ));
591617 }
@@ -598,8 +624,20 @@ private Path buildMSI(Map<String, ? super Object> params,
598624 // Build ordered list of unique cultures.
599625 Set <String > uniqueCultures = new LinkedHashSet <>();
600626 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+ }
603641
604642 wixPipeline .buildMsi (msiOut .toAbsolutePath ());
605643
@@ -751,7 +789,7 @@ private static OverridableResource initServiceInstallerResource(
751789 }
752790
753791 private Path installerIcon ;
754- private Map < WixTool , WixTool . ToolInfo > wixToolset ;
792+ private WixToolset wixToolset ;
755793 private AppImageBundler appImageBundler ;
756794 private final List <WixFragmentBuilder > wixFragments ;
757795}
0 commit comments