@joebigelow / wix-1 / commits / 90bdfa6e

Convert custom table Column Category and Modularize attributes

Rob Mensching committed Jun 12, 2020 at 06:54 UTC 90bdfa6e06862030f6b255a4dcacb5871a35b1a1
2 files changed +103 -1
src/WixToolset.Converters/Wix3Converter.cs
+53 -1
@@ -26,6 +26,7 @@ namespace WixToolset.Converters
26 private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs";
27 private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util";
28
29 + private static readonly XName ColumnElementName = WixNamespace + "Column";
30 private static readonly XName CreateFolderElementName = WixNamespace + "CreateFolder";
31 private static readonly XName CustomTableElementName = WixNamespace + "CustomTable";
32 private static readonly XName DirectoryElementName = WixNamespace + "Directory";
@@ -82,6 +83,7 @@ namespace WixToolset.Converters
83 {
84 this.ConvertElementMapping = new Dictionary<XName, Action<XElement>>
85 {
86 + { Wix3Converter.ColumnElementName, this.ConvertColumnElement },
87 { Wix3Converter.CustomTableElementName, this.ConvertCustomTableElement },
88 { Wix3Converter.DirectoryElementName, this.ConvertDirectoryElement },
89 { Wix3Converter.FileElementName, this.ConvertFileElement },
@@ -298,6 +300,31 @@ namespace WixToolset.Converters
300 }
301 }
302
303 + private void ConvertColumnElement(XElement element)
304 + {
305 + var category = element.Attribute("Category");
306 + if (category != null)
307 + {
308 + var camelCaseValue = LowercaseFirstChar(category.Value);
309 + if (category.Value != camelCaseValue &&
310 + this.OnError(ConverterTestType.ColumnCategoryCamelCase, element, "The CustomTable Category attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", category.Name))
311 + {
312 + category.Value = camelCaseValue;
313 + }
314 + }
315 +
316 + var modularization = element.Attribute("Modularize");
317 + if (modularization != null)
318 + {
319 + var camelCaseValue = LowercaseFirstChar(modularization.Value);
320 + if (category.Value != camelCaseValue &&
321 + this.OnError(ConverterTestType.ColumnModularizeCamelCase, element, "The CustomTable Modularize attribute contains an incorrectly cased '{0}' value. Lowercase the first character instead.", modularization.Name))
322 + {
323 + modularization.Value = camelCaseValue;
324 + }
325 + }
326 + }
327 +
328 private void ConvertCustomTableElement(XElement element)
329 {
330 var bootstrapperApplicationData = element.Attribute("BootstrapperApplicationData");
@@ -583,7 +610,7 @@ namespace WixToolset.Converters
610 /// <remarks>This is duplicated from WiX's Common class.</remarks>
611 private static string GetIdentifierFromName(string name)
612 {
586 - string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_".
613 + var result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_".
614
615 // MSI identifiers must begin with an alphabetic character or an
616 // underscore. Prefix all other values with an underscore.
@@ -595,6 +622,21 @@ namespace WixToolset.Converters
622 return result;
623 }
624
625 + private static string LowercaseFirstChar(string value)
626 + {
627 + if (!String.IsNullOrEmpty(value))
628 + {
629 + var c = Char.ToLowerInvariant(value[0]);
630 + if (c != value[0])
631 + {
632 + var remainder = value.Length > 1 ? value.Substring(1) : String.Empty;
633 + return c + remainder;
634 + }
635 + }
636 +
637 + return value;
638 + }
639 +
640 /// <summary>
641 /// Converter test types. These are used to condition error messages down to warnings.
642 /// </summary>
@@ -699,6 +741,16 @@ namespace WixToolset.Converters
741 /// Inheritable is new and is now defaulted to 'yes' which is a change in behavior for all but children of CreateFolder.
742 /// </summary>
743 AssignPermissionExInheritable,
744 +
745 + /// <summary>
746 + /// Column element's Category attribute is camel-case.
747 + /// </summary>
748 + ColumnCategoryCamelCase,
749 +
750 + /// <summary>
751 + /// Column element's Modularize attribute is camel-case.
752 + /// </summary>
753 + ColumnModularizeCamelCase,
754 }
755 }
756 }
src/test/WixToolsetTest.Converters/CustomTableFixture.cs new
+50
@@ -0,0 +1,50 @@
1 +// 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.
2 +
3 +namespace WixToolsetTest.Converters
4 +{
5 + using System;
6 + using System.Xml.Linq;
7 + using WixToolset.Converters;
8 + using WixToolsetTest.Converters.Mocks;
9 + using Xunit;
10 +
11 + public class CustomTableFixture : BaseConverterFixture
12 + {
13 + [Fact]
14 + public void FixCustomTableCategoryAndModularization()
15 + {
16 + var parse = String.Join(Environment.NewLine,
17 + "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
18 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
19 + " <Fragment>",
20 + " <CustomTable Id='Custom1'>",
21 + " <Column Id='Column1' Type='string' Category='Text' Modularize='Column' />",
22 + " </CustomTable>",
23 + " </Fragment>",
24 + "</Wix>");
25 +
26 + var expected = new[]
27 + {
28 + "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
29 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
30 + " <Fragment>",
31 + " <CustomTable Id=\"Custom1\">",
32 + " <Column Id=\"Column1\" Type=\"string\" Category=\"text\" Modularize=\"column\" />",
33 + " </CustomTable>",
34 + " </Fragment>",
35 + "</Wix>"
36 + };
37 +
38 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
39 +
40 + var messaging = new MockMessaging();
41 + var converter = new Wix3Converter(messaging, 2, null, null);
42 +
43 + var errors = converter.ConvertDocument(document);
44 + Assert.Equal(4, errors);
45 +
46 + var actualLines = UnformattedDocumentLines(document);
47 + CompareLineByLine(expected, actualLines);
48 + }
49 + }
50 +}