Skip to content

Commit

Permalink
Allow custom package comments
Browse files Browse the repository at this point in the history
Fixes #7369
  • Loading branch information
mosBrkr authored and robmen committed Jul 19, 2023
1 parent d20b6d4 commit 95bf601
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/wix/WixToolset.Core/Compiler_Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private void ParseModuleElement(XElement node)
string moduleId = null;
string version = null;
var setCodepage = false;
var setComments = false;
var setPackageName = false;
var setKeywords = false;
var ignoredForMergeModules = false;
Expand Down Expand Up @@ -206,7 +207,7 @@ private void ParseModuleElement(XElement node)
this.ParseSubstitutionElement(child);
break;
case "SummaryInformation":
this.ParseSummaryInformationElement(child, ref setCodepage, ref setPackageName, ref setKeywords, ref ignoredForMergeModules);
this.ParseSummaryInformationElement(child, ref setCodepage, ref setComments, ref setPackageName, ref setKeywords, ref ignoredForMergeModules);
break;
case "UI":
this.ParseUIElement(child);
Expand Down Expand Up @@ -274,11 +275,14 @@ private void ParseModuleElement(XElement node)
Value = "0"
});

this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
if (!setComments)
{
PropertyId = SummaryInformationType.Comments,
Value = String.Format(CultureInfo.InvariantCulture, "This merge module contains the logic and data required to install {0}.", this.activeName)
});
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
{
PropertyId = SummaryInformationType.Comments,
Value = String.Format(CultureInfo.InvariantCulture, "This merge module contains the logic and data required to install {0}.", this.activeName)
});
}

this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, this.activeLanguage);
}
Expand Down
35 changes: 27 additions & 8 deletions src/wix/WixToolset.Core/Compiler_Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void ParsePackageElement(XElement node)
string version = null;
string symbols = null;
var isCodepageSet = false;
var isCommentsSet = false;
var isPackageNameSet = false;
var isKeywordsSet = false;
var isPackageAuthorSet = false;
Expand Down Expand Up @@ -190,12 +191,6 @@ private void ParsePackageElement(XElement node)
Value = "Installation Database"
});

this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
{
PropertyId = SummaryInformationType.Comments,
Value = String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
});

this.ValidateAndAddCommonSummaryInformationSymbols(sourceLineNumbers, msiVersion, platform, productLanguage);

this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
Expand Down Expand Up @@ -334,7 +329,7 @@ private void ParsePackageElement(XElement node)
this.ParseStandardDirectoryElement(child);
break;
case "SummaryInformation":
this.ParseSummaryInformationElement(child, ref isCodepageSet, ref isPackageNameSet, ref isKeywordsSet, ref isPackageAuthorSet);
this.ParseSummaryInformationElement(child, ref isCodepageSet, ref isCommentsSet, ref isPackageNameSet, ref isKeywordsSet, ref isPackageAuthorSet);
break;
case "SymbolPath":
if (null != symbols)
Expand Down Expand Up @@ -383,6 +378,15 @@ private void ParsePackageElement(XElement node)
Codepage = codepage,
});

if (!isCommentsSet)
{
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
{
PropertyId = SummaryInformationType.Comments,
Value = String.Format(CultureInfo.InvariantCulture, "This installer database contains the logic and data required to install {0}.", this.activeName)
});
}

if (!isPackageNameSet)
{
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
Expand Down Expand Up @@ -780,13 +784,15 @@ private YesNoType ParseODBCDataSource(XElement node, string componentId, string
/// </summary>
/// <param name="node">Element to parse.</param>
/// <param name="isCodepageSet"></param>
/// <param name="isCommentsSet"></param>
/// <param name="isPackageNameSet"></param>
/// <param name="isKeywordsSet"></param>
/// <param name="isPackageAuthorSet"></param>
private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSet, ref bool isPackageNameSet, ref bool isKeywordsSet, ref bool isPackageAuthorSet)
private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSet, ref bool isCommentsSet, ref bool isPackageNameSet, ref bool isKeywordsSet, ref bool isPackageAuthorSet)
{
var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
string codepage = null;
string comments = null;
string packageName = null;
string keywords = null;
string packageAuthor = null;
Expand All @@ -800,6 +806,9 @@ private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSe
case "Codepage":
codepage = this.Core.GetAttributeLocalizableCodePageValue(sourceLineNumbers, attrib, true);
break;
case "Comments":
comments = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
break;
case "Description":
packageName = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
break;
Expand Down Expand Up @@ -838,6 +847,16 @@ private void ParseSummaryInformationElement(XElement node, ref bool isCodepageSe
});
}

if (null != comments)
{
isCommentsSet = true;
this.Core.AddSymbol(new SummaryInformationSymbol(sourceLineNumbers)
{
PropertyId = SummaryInformationType.Comments,
Value = comments
});
}

if (null != packageName)
{
isPackageNameSet = true;
Expand Down
160 changes: 160 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/CommentsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolsetTest.CoreIntegration
{
using System.IO;
using System.Linq;
using WixInternal.Core.TestPackage;
using WixInternal.TestSupport;
using WixToolset.Data;
using WixToolset.Data.Symbols;
using WixToolset.Data.WindowsInstaller;
using Xunit;

public class CommentsFixture
{
[Fact]
public void PackageNoSummaryInformation()
{
var propertyRows = BuildPackageAndQuerySummaryInformation("PackageNoSummaryInformation.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
}, propertyRows);
}

[Fact]
public void PackageDefaultComments()
{
var propertyRows = BuildPackageAndQuerySummaryInformation("PackageDefault.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tThis installer database contains the logic and data required to install MsiPackage."
}, propertyRows);
}

[Fact]
public void PackageEmptyCommentsThrows()
{
var exception = Assert.Throws<WixException>(() => BuildPackageAndQuerySummaryInformation("PackageEmpty.wxs"));
WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
}

[Fact]
public void PackageCustomComments()
{
var propertyRows = BuildPackageAndQuerySummaryInformation("PackageCustom.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tExample comments"
}, propertyRows);
}

[Fact]
public void ModuleNoSummaryInformation()
{
var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleNoSummaryInformation.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
}, propertyRows);
}

[Fact]
public void ModuleDefaultComments()
{
var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleDefault.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tThis merge module contains the logic and data required to install Module."
}, propertyRows);
}

[Fact]
public void ModuleEmptyCommentsThrows()
{
var exception = Assert.Throws<WixException>(() => BuildModuleAndQuerySummaryInformation("ModuleEmpty.wxs"));
WixAssert.StringEqual("The SummaryInformation/@Comments attribute's value cannot be an empty string. If a value is not required, simply remove the entire attribute.", exception.Message);
}

[Fact]
public void ModuleCustomComments()
{
var propertyRows = BuildModuleAndQuerySummaryInformation("ModuleCustom.wxs");

WixAssert.CompareLineByLine(new[]
{
"_SummaryInformation:Comments\tExample comments"
}, propertyRows);
}

private static string[] BuildPackageAndQuerySummaryInformation(string file)
{
var folder = TestData.Get("TestData", "Comments");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var binFolder = Path.Combine(baseFolder, "bin");
var msiPath = Path.Combine(binFolder, "test.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, file),
"-intermediateFolder", intermediateFolder,
"-bindpath", folder,
"-o", msiPath,
});

if(result.ExitCode != 0)
{
throw new WixException(result.Messages.First());
}

return Query.QueryDatabase(msiPath, new[] { "Property", "_SummaryInformation" })
.Where(s => s.StartsWith("_SummaryInformation:Comments"))
.OrderBy(s => s)
.ToArray();
}
}

private static string[] BuildModuleAndQuerySummaryInformation(string file)
{
var folder = TestData.Get("TestData", "Comments");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var binFolder = Path.Combine(baseFolder, "bin");
var msmPath = Path.Combine(binFolder, "test.msm");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, file),
"-intermediateFolder", intermediateFolder,
"-bindpath", Path.Combine(folder, "data"),
"-o", msmPath,
});

if (result.ExitCode != 0)
{
throw new WixException(result.Messages.First());
}

return Query.QueryDatabase(msmPath, new[] { "Property", "_SummaryInformation" })
.Where(s => s.StartsWith("_SummaryInformation:Comments"))
.OrderBy(s => s)
.ToArray();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Module
Id="Module"
Language="1033"
Version="1.0.0.0"
Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
<SummaryInformation Comments="Example comments" />

<Directory Id="ModuleFolder">
<Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
<File Id="File1" Name="file.txt" Source="test.txt" />
</Component>
</Directory>

</Module>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Module
Id="Module"
Language="1033"
Version="1.0.0.0"
Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
<SummaryInformation />

<Directory Id="ModuleFolder">
<Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
<File Id="File1" Name="file.txt" Source="test.txt" />
</Component>
</Directory>

</Module>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Module
Id="Module"
Language="1033"
Version="1.0.0.0"
Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">
<SummaryInformation Comments="" />

<Directory Id="ModuleFolder">
<Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
<File Id="File1" Name="file.txt" Source="test.txt" />
</Component>
</Directory>

</Module>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Module
Id="Module"
Language="1033"
Version="1.0.0.0"
Guid="243FB739-4D05-472F-9CFB-EF6B1017B6DE">

<Directory Id="ModuleFolder">
<Component Id="ModuleComponent" Guid="A04E61B2-3ED4-4803-B2EB-4B773576FA45">
<File Id="File1" Name="file.txt" Source="test.txt" />
</Component>
</Directory>

</Module>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
<SummaryInformation Comments="Example comments" />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
<SummaryInformation />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
<SummaryInformation Comments="" />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test.txt.

0 comments on commit 95bf601

Please sign in to comment.