From 90bdfa6e06862030f6b255a4dcacb5871a35b1a1 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 12 Jun 2020 06:54:42 -0700 Subject: Convert custom table Column Category and Modularize attributes --- src/WixToolset.Converters/Wix3Converter.cs | 54 +++++++++++++++++++++- .../CustomTableFixture.cs | 50 ++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/test/WixToolsetTest.Converters/CustomTableFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/Wix3Converter.cs b/src/WixToolset.Converters/Wix3Converter.cs index 66ccd9d3..559e5368 100644 --- a/src/WixToolset.Converters/Wix3Converter.cs +++ b/src/WixToolset.Converters/Wix3Converter.cs @@ -26,6 +26,7 @@ namespace WixToolset.Converters private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; + private static readonly XName ColumnElementName = WixNamespace + "Column"; private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder"; private static readonly XName CustomTableElementName = WixNamespace + "CustomTable"; private static readonly XName DirectoryElementName = WixNamespace + "Directory"; @@ -82,6 +83,7 @@ namespace WixToolset.Converters { this.ConvertElementMapping = new Dictionary> { + { Wix3Converter.ColumnElementName, this.ConvertColumnElement }, { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement }, { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement }, { Wix3Converter.FileElementName, this.ConvertFileElement }, @@ -298,6 +300,31 @@ namespace WixToolset.Converters } } + private void ConvertColumnElement(XElement element) + { + var category = element.Attribute("Category"); + if (category != null) + { + var camelCaseValue = LowercaseFirstChar(category.Value); + if (category.Value != camelCaseValue && + this.OnError(ConverterTestType.ColumnCategoryCamelCase, element, "The CustomTable Category attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", category.Name)) + { + category.Value = camelCaseValue; + } + } + + var modularization = element.Attribute("Modularize"); + if (modularization != null) + { + var camelCaseValue = LowercaseFirstChar(modularization.Value); + if (category.Value != camelCaseValue && + this.OnError(ConverterTestType.ColumnModularizeCamelCase, element, "The CustomTable Modularize attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", modularization.Name)) + { + modularization.Value = camelCaseValue; + } + } + } + private void ConvertCustomTableElement(XElement element) { var bootstrapperApplicationData = element.Attribute("BootstrapperApplicationData"); @@ -583,7 +610,7 @@ namespace WixToolset.Converters /// This is duplicated from WiX's Common class. private static string GetIdentifierFromName(string name) { - string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". + var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". // MSI identifiers must begin with an alphabetic character or an // underscore. Prefix all other values with an underscore. @@ -595,6 +622,21 @@ namespace WixToolset.Converters return result; } + private static string LowercaseFirstChar(string value) + { + if (!String.IsNullOrEmpty(value)) + { + var c = Char.ToLowerInvariant(value[0]); + if (c != value[0]) + { + var remainder = value.Length > 1 ? value.Substring(1) : String.Empty; + return c + remainder; + } + } + + return value; + } + /// /// Converter test types. These are used to condition error messages down to warnings. /// @@ -699,6 +741,16 @@ namespace WixToolset.Converters /// Inheritable is new and is now defaulted to 'yes' which is a change in behavior for all but children of CreateFolder. /// AssignPermissionExInheritable, + + /// + /// Column element's Category attribute is camel-case. + /// + ColumnCategoryCamelCase, + + /// + /// Column element's Modularize attribute is camel-case. + /// + ColumnModularizeCamelCase, } } } diff --git a/src/test/WixToolsetTest.Converters/CustomTableFixture.cs b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs new file mode 100644 index 00000000..5a572294 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/CustomTableFixture.cs @@ -0,0 +1,50 @@ +// 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.Converters +{ + using System; + using System.Xml.Linq; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class CustomTableFixture : BaseConverterFixture + { + [Fact] + public void FixCustomTableCategoryAndModularization() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + "", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new Wix3Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(4, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb