Skip to content

Commit a873fe5

Browse files
authored
Support Wix v4+ (#478)
* Upgrade gradle * Add support for wix v4 and newer
1 parent d3823a8 commit a873fe5

9 files changed

Lines changed: 102 additions & 40 deletions

File tree

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repositories {
1313
mavenLocal()
1414
mavenCentral()
1515
maven {
16-
url 'https://plugins.gradle.org/m2/'
16+
url = uri('https://plugins.gradle.org/m2/')
1717
}
1818
}
1919

@@ -67,8 +67,10 @@ group = 'io.github.fvarrui'
6767
version = '1.7.7-SNAPSHOT'
6868
description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them'
6969

70-
sourceCompatibility = JavaVersion.VERSION_1_8
71-
targetCompatibility = JavaVersion.VERSION_1_8
70+
java {
71+
sourceCompatibility = JavaVersion.VERSION_1_8
72+
targetCompatibility = JavaVersion.VERSION_1_8
73+
}
7274

7375
compileJava.options.encoding = 'UTF-8'
7476

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/io/github/fvarrui/javapackager/gradle/PackagePluginExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public PackagePluginExtension(Project project) {
5151
this.organizationEmail = "";
5252
this.useResourcesAsWorkingDir = true;
5353
this.vmArgs = new ArrayList<>();
54+
this.appArgs = new ArrayList<>();
5455
this.winConfig = new WindowsConfig();
5556
this.outputDirectory = project.getBuildDir();
5657
this.scripts = new Scripts();

src/main/java/io/github/fvarrui/javapackager/packagers/GenerateMsi.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.File;
66

77
import io.github.fvarrui.javapackager.model.Platform;
8+
import io.github.fvarrui.javapackager.utils.CommandUtils;
89
import io.github.fvarrui.javapackager.utils.Logger;
910
import io.github.fvarrui.javapackager.utils.VelocityUtils;
1011
import io.github.fvarrui.javapackager.utils.XMLUtils;
@@ -32,7 +33,7 @@ public boolean skip(WindowsPackager packager) {
3233
return true;
3334
}
3435

35-
return false;
36+
return false;
3637
}
3738

3839
@Override
@@ -53,17 +54,23 @@ protected File doApply(WindowsPackager packager) throws Exception {
5354

5455
// prettify wxs
5556
XMLUtils.prettify(wxsFile);
56-
57-
// candle wxs file
58-
Logger.info("Compiling file " + wxsFile);
59-
File wixobjFile = new File(assetsFolder, name + ".wixobj");
60-
execute("candle", "-out", wixobjFile, wxsFile);
61-
Logger.info("WIXOBJ file generated in " + wixobjFile + "!");
6257

63-
// lighting wxs file
64-
Logger.info("Linking file " + wixobjFile);
6558
File msiFile = new File(outputDirectory, name + "_" + version + ".msi");
66-
execute("light", "-sw1076", "-spdb", "-out", msiFile, wixobjFile);
59+
// We can rely on the MSM generation to populate this
60+
if(packager.getWixMajorVersion() == 3) {
61+
// candle wxs file
62+
Logger.info("Compiling file " + wxsFile);
63+
File wixobjFile = new File(assetsFolder, name + ".wixobj");
64+
execute("candle", "-arch", "x64", "-out", wixobjFile, wxsFile);
65+
Logger.info("WIXOBJ file generated in " + wixobjFile + "!");
66+
67+
// lighting wxs file
68+
Logger.info("Linking file " + wixobjFile);
69+
execute("light", "-sw1076", "-spdb", "-out", msiFile, wixobjFile);
70+
} else {
71+
Logger.info("Building file " + wxsFile);
72+
CommandUtils.execute("wix", "build", "-pdbtype", "none", "-arch", "x64", "-out", msiFile, wxsFile);
73+
}
6774

6875
// setup file
6976
if (!msiFile.exists()) {

src/main/java/io/github/fvarrui/javapackager/packagers/GenerateMsm.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.github.fvarrui.javapackager.utils.Logger;
88
import io.github.fvarrui.javapackager.utils.VelocityUtils;
99
import io.github.fvarrui.javapackager.utils.XMLUtils;
10+
import org.codehaus.plexus.util.cli.CommandLineException;
1011

1112
/**
1213
* Creates an MSI file including all app folder's content only for Windows so app
@@ -40,6 +41,19 @@ protected File doApply(WindowsPackager packager) throws Exception {
4041
return packager.getMsmFile();
4142
}
4243

44+
try {
45+
String version = CommandUtils.execute("wix", "-version");
46+
packager.setWixMajorVersion(Integer.parseInt(version.split("\\.")[0]));
47+
} catch(CommandLineException ex) {
48+
try {
49+
CommandUtils.execute("candle", "-?");
50+
CommandUtils.execute("light", "-?");
51+
packager.setWixMajorVersion(3);
52+
} catch(CommandLineException ex2) {
53+
throw new Exception("Either 'wix' or 'candle' and 'light' must be on PATH");
54+
}
55+
}
56+
4357
File assetsFolder = packager.getAssetsFolder();
4458
String name = packager.getName();
4559
File outputDirectory = packager.getOutputDirectory();
@@ -53,16 +67,21 @@ protected File doApply(WindowsPackager packager) throws Exception {
5367
// prettify wxs
5468
XMLUtils.prettify(wxsFile);
5569

56-
// candle wxs file
57-
Logger.info("Compiling file " + wxsFile);
58-
File wixobjFile = new File(assetsFolder, name + ".msm.wixobj");
59-
CommandUtils.execute("candle", "-out", wixobjFile, wxsFile);
60-
Logger.info("WIXOBJ file generated in " + wixobjFile + "!");
61-
62-
// lighting wxs file
63-
Logger.info("Linking file " + wixobjFile);
6470
File msmFile = new File(outputDirectory, name + "_" + version + ".msm");
65-
CommandUtils.execute("light", "-sw1076", "-spdb", "-out", msmFile, wixobjFile);
71+
if(packager.getWixMajorVersion() == 3) {
72+
// candle wxs file
73+
Logger.info("Compiling file " + wxsFile);
74+
File wixobjFile = new File(assetsFolder, name + ".msm.wixobj");
75+
CommandUtils.execute("candle", "-arch", "x64", "-out", wixobjFile, wxsFile);
76+
Logger.info("WIXOBJ file generated in " + wixobjFile + "!");
77+
78+
// lighting wxs file
79+
Logger.info("Linking file " + wixobjFile);
80+
CommandUtils.execute("light", "-sw1076", "-spdb", "-out", msmFile, wixobjFile);
81+
} else {
82+
Logger.info("Building file " + wxsFile);
83+
CommandUtils.execute("wix", "build", "-pdbtype", "none", "-arch", "x64", "-out", msmFile, wxsFile);
84+
}
6685

6786
// setup file
6887
if (!msmFile.exists()) {

src/main/java/io/github/fvarrui/javapackager/packagers/PackagerSettings.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,12 @@ public String toString() {
937937
+ ", customizedJre=" + customizedJre + ", jrePath=" + jrePath + ", jdkPath=" + jdkPath
938938
+ ", additionalResources=" + additionalResources + ", modules=" + modules + ", additionalModules="
939939
+ additionalModules + ", platform=" + platform + ", envPath=" + envPath + ", vmArgs=" + vmArgs
940-
+ ", runnableJar=" + runnableJar + ", copyDependencies=" + copyDependencies + ", jreDirectoryName="
941-
+ jreDirectoryName + ", winConfig=" + winConfig + ", linuxConfig=" + linuxConfig + ", macConfig="
942-
+ macConfig + ", createTarball=" + createTarball + ", tarballName=" + tarballName + ", createZipball="
943-
+ createZipball + ", zipballName=" + zipballName + ", extra=" + extra + ", useResourcesAsWorkingDir="
944-
+ useResourcesAsWorkingDir + ", assetsDir=" + assetsDir + ", classpath=" + classpath
945-
+ ", jreMinVersion=" + jreMinVersion + ", manifest=" + manifest + ", additionalModulePaths="
940+
+ ", appArgs=" + appArgs + ",runnableJar=" + runnableJar + ", copyDependencies=" + copyDependencies
941+
+ ", jreDirectoryName=" + jreDirectoryName + ", winConfig=" + winConfig + ", linuxConfig=" + linuxConfig
942+
+ ", macConfig=" + macConfig + ", createTarball=" + createTarball + ", tarballName=" + tarballName
943+
+ ", createZipball=" + createZipball + ", zipballName=" + zipballName + ", extra=" + extra
944+
+ ", useResourcesAsWorkingDir=" + useResourcesAsWorkingDir + ", assetsDir=" + assetsDir+ ", classpath="
945+
+ classpath + ", jreMinVersion=" + jreMinVersion + ", manifest=" + manifest + ", additionalModulePaths="
946946
+ additionalModulePaths + ", fileAssociations=" + fileAssociations + ", packagingJdk=" + packagingJdk
947947
+ ", scripts=" + scripts + ", arch=" + arch + ", templates=" + templates + "]";
948948
}

src/main/java/io/github/fvarrui/javapackager/packagers/WindowsPackager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class WindowsPackager extends Packager {
1919

2020
private File manifestFile;
2121
private File msmFile;
22+
private int wixMajorVersion;
2223

2324
public File getManifestFile() {
2425
return manifestFile;
@@ -28,9 +29,17 @@ public File getMsmFile() {
2829
return msmFile;
2930
}
3031

32+
public int getWixMajorVersion() {
33+
return wixMajorVersion;
34+
}
35+
3136
public void setMsmFile(File msmFile) {
3237
this.msmFile = msmFile;
3338
}
39+
40+
public void setWixMajorVersion(int wixMajorVersion) {
41+
this.wixMajorVersion = wixMajorVersion;
42+
}
3443

3544
public WindowsPackager() {
3645
super();

src/main/resources/windows/msm.wxs.vtl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#end
2020
</Directory>
2121
#else
22-
<Component Id="_${id}" Guid="${guid}" Win64="yes">
22+
<Component Id="_${id}" Guid="${guid}">
2323
#if($file.equals(${info.executable}))
2424
<File Id="EXEFILE" Name="${file.name}" KeyPath="yes" Source="${file}">
2525
<Shortcut Id="ApplicationStartMenuShortcut" Name="${info.winConfig.shortcutName}" Description="${info.description}" Directory="ProgramMenuFolder" />
@@ -32,15 +32,26 @@
3232
</Component>
3333
#end
3434
#end
35+
#if($info.wixMajorVersion == 3)
3536
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
36-
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
37-
<Module Id="${name}_Module" Codepage="1252" Language="1033" Version="${info.winConfig.productVersion}">
37+
#end
38+
<Wix xmlns="#if($info.wixMajorVersion > 3)http://wixtoolset.org/schemas/v4/wxs#{else}http://schemas.microsoft.com/wix/2006/wi#end">
39+
<Module Id="${name}_Module" Codepage="1252" Language="1033" Version="${info.winConfig.productVersion}"
40+
#if($info.wixMajorVersion > 3)
41+
Guid="${GUID.randomUUID()}" InstallerVersion="${installedVersion}"
42+
#end
43+
>
44+
#if($info.wixMajorVersion == 3)
3845
<Package Id="${GUID.randomUUID()}" Manufacturer="${info.organizationName}" InstallerVersion="${installedVersion}" Languages="1033" Platform="${info.arch.toMsiArchitecture()}" SummaryCodepage="1252" Description="${info.description}"/>
46+
#end
47+
48+
#if($info.wixMajorVersion == 3)
3949
<Directory Id="TARGETDIR" Name="SourceDir">
50+
#end
4051
#list(${info.appFolder})
41-
<Directory Id="ProgramMenuFolder" />
52+
#if($info.wixMajorVersion == 3)<Directory Id="ProgramMenuFolder" />#end
4253
#if ($info.winConfig.registry)
43-
<Component Id="RegistryEntries" Guid="${GUID.randomUUID()}">
54+
<Component Id="RegistryEntries" Guid="${GUID.randomUUID()}" #if($info.wixMajorVersion > 3)Directory="TARGETDIR"#end>
4455
#foreach ($entry in $info.winConfig.registry.entries)
4556
<RegistryKey Root="${entry.root}" Key="${entry.subkey}" ForceDeleteOnUninstall="yes">
4657
<RegistryValue
@@ -56,6 +67,8 @@
5667
#end
5768
</Component>
5869
#end
70+
#if($info.wixMajorVersion == 3)
5971
</Directory>
72+
#end
6073
</Module>
6174
</Wix>

src/main/resources/windows/wxs.vtl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
#set($moduleName = $info.name.replaceAll("[^A-Za-z0-9_.]", "_") + "_Module")
2+
#if($info.wixMajorVersion == 3)
23
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3-
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
4+
#end
5+
<Wix xmlns="#if($info.wixMajorVersion == 3)http://schemas.microsoft.com/wix/2006/wi#{else}http://wixtoolset.org/schemas/v4/wxs#end">
6+
#if($info.wixMajorVersion > 3)
7+
<Package Codepage="1252" Language="1033" Manufacturer="${info.organizationName}" Name="${info.name}" UpgradeCode="${info.winConfig.msiUpgradeCode}" Version="${info.winConfig.productVersion}" InstallerVersion="200">
8+
<SummaryInformation Description="${info.description}" />
9+
#else
410
<Product Id="*" Codepage="1252" Language="1033" Manufacturer="${info.organizationName}" Name="${info.name}" UpgradeCode="${info.winConfig.msiUpgradeCode}" Version="${info.winConfig.productVersion}">
5-
<Package Compressed="yes" InstallScope="perMachine" InstallerVersion="200" Languages="1033" Platform="x64" SummaryCodepage="1252" Description="${info.description}"/>
11+
<Package Compressed="yes" InstallScope="perMachine" InstallerVersion="200" Languages="1033" Platform="x64" SummaryCodepage="1252" Description="${info.description}"/>
12+
#end
613
<Media Id="1" Cabinet="Application.cab" EmbedCab="yes"/>
14+
#if($info.wixMajorVersion == 3)
715
<Directory Id="TARGETDIR" Name="SourceDir">
8-
<Directory Id="ProgramFiles64Folder">
16+
#end
17+
<#if($info.wixMajorVersion > 3)StandardDirectory#{else}Directory#end Id="ProgramFiles64Folder">
918
<Merge Id="${moduleName}" Language="1033" SourceFile="${info.msmFile}" DiskId="1" />
10-
</Directory>
19+
</#if($info.wixMajorVersion > 3)StandardDirectory#{else}Directory#end>
20+
#if($info.wixMajorVersion == 3)
1121
</Directory>
12-
<Feature Id="_${GUID.randomUUID().toString().replaceAll('-','_')}" Absent="disallow" AllowAdvertise="no" ConfigurableDirectory="TARGETDIR" Description="${info.description}" Level="1" Title="${info.displayName}">
22+
#end
23+
<Feature Id="_${GUID.randomUUID().toString().replaceAll('-','_')}" #if($info.wixMajorVersion > 3)AllowAbsent="no"#{else}Absent="disallow"#end AllowAdvertise="no" ConfigurableDirectory="TARGETDIR" Description="${info.description}" Level="1" Title="${info.displayName}">
1324
<MergeRef Id="${moduleName}"/>
1425
</Feature>
1526
<Icon Id="ICONFILE" SourceFile="${info.iconFile.getAbsolutePath()}"/>
@@ -18,5 +29,5 @@
1829
<WixVariable Id="WixUILicenseRtf" Value="LICENSE"/>
1930
#end
2031
<MajorUpgrade AllowDowngrades="no" AllowSameVersionUpgrades="no" DowngradeErrorMessage="A later version of ${info.winConfig.productName} is already installed. Setup will now exit." IgnoreRemoveFailure="no"/>
21-
</Product>
32+
</#if($info.wixMajorVersion > 3)Package#{else}Product#end>
2233
</Wix>

0 commit comments

Comments
 (0)