@joebigelow / wix / commits / 7dff5725

Fixup SoftwareTag deprecations and SoftwareTagRef conversion

Fixes wixtoolset/issues#6379

Rob Mensching committed Mar 23, 2021 at 16:26 UTC 7dff57257c06da8c861a1a54e32f97fd9f22357c
2 files changed +122 -39
src/WixToolset.Converters/WixConverter.cs
+56 -39
@@ -119,7 +119,9 @@ namespace WixToolset.Converters
119 private static readonly XName SetPropertyElementName = WixNamespace + "SetProperty";
120 private static readonly XName ShortcutPropertyElementName = WixNamespace + "ShortcutProperty";
121 private static readonly XName SoftwareTagElementName = WixNamespace + "SoftwareTag";
122 + private static readonly XName SoftwareTagRefElementName = WixNamespace + "SoftwareTagRef";
123 private static readonly XName TagElementName = XNamespace.None + "Tag";
124 + private static readonly XName TagRefElementName = XNamespace.None + "TagRef";
125 private static readonly XName TextElementName = WixNamespace + "Text";
126 private static readonly XName UITextElementName = WixNamespace + "UIText";
127 private static readonly XName VariableElementName = WixNamespace + "Variable";
@@ -235,6 +237,7 @@ namespace WixToolset.Converters
237 { WixConverter.SetPropertyElementName, this.ConvertSetPropertyElement },
238 { WixConverter.ShortcutPropertyElementName, this.ConvertShortcutPropertyElement },
239 { WixConverter.TagElementName, this.ConvertTagElement },
240 + { WixConverter.TagRefElementName, this.ConvertTagRefElement },
241 { WixConverter.TextElementName, this.ConvertTextElement },
242 { WixConverter.UITextElementName, this.ConvertUITextElement },
243 { WixConverter.VariableElementName, this.ConvertVariableElement },
@@ -686,13 +689,7 @@ namespace WixToolset.Converters
689
690 private void ConvertApprovedExeForElevationElement(XElement element)
691 {
689 - var win64 = element.Attribute("Win64");
690 - if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
691 - {
692 - var value = this.UpdateWin64ValueToBitnessValue(win64);
693 - element.Add(new XAttribute("Bitness", value));
694 - win64.Remove();
695 - }
692 + this.RenameWin64ToBitness(element);
693 }
694
695 private void ConvertBalBootstrapperApplicationRef(XElement element, string theme, XName balBAElementName, XName oldBalBAElementName = null)
@@ -897,13 +894,7 @@ namespace WixToolset.Converters
894 }
895 }
896
900 - var win64 = element.Attribute("Win64");
901 - if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
902 - {
903 - var value = this.UpdateWin64ValueToBitnessValue(win64);
904 - element.Add(new XAttribute("Bitness", value));
905 - win64.Remove();
906 - }
897 + this.RenameWin64ToBitness(element);
898 }
899
900 private void ConvertDirectoryElement(XElement element)
@@ -1289,28 +1280,13 @@ namespace WixToolset.Converters
1280
1281 this.OnError(ConverterTestType.BurnHashAlgorithmChanged, element, "The hash algorithm for bundles changed from SHA1 to SHA512.");
1282
1292 - RemoveIfPresent(element.Attribute("CertificatePublicKey"));
1293 - RemoveIfPresent(element.Attribute("CertificateThumbprint"));
1294 -
1295 - void RemoveIfPresent(XAttribute xAttribute)
1296 - {
1297 - if (null != xAttribute
1298 - && this.OnError(ConverterTestType.BundleSignatureValidationObsolete, element, "The chain package element contains obsolete '{0}' attribute. Signature validation is no longer supported. The attribute will be removed.", xAttribute.Name))
1299 - {
1300 - xAttribute.Remove();
1301 - }
1302 - }
1283 + this.RemoveAttributeIfPresent(element, "CertificatePublicKey", ConverterTestType.BundleSignatureValidationObsolete, "The {0} element contains obsolete '{1}' attribute. Signature validation is no longer supported. The attribute will be removed.");
1284 + this.RemoveAttributeIfPresent(element, "CertificateThumbprint", ConverterTestType.BundleSignatureValidationObsolete, "The {0} element contains obsolete '{1}' attribute. Signature validation is no longer supported. The attribute will be removed.");
1285 }
1286
1287 private void ConvertRegistrySearchElement(XElement element)
1288 {
1307 - var win64 = element.Attribute("Win64");
1308 - if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
1309 - {
1310 - var value = this.UpdateWin64ValueToBitnessValue(win64);
1311 - element.Add(new XAttribute("Bitness", value));
1312 - win64.Remove();
1313 - }
1289 + this.RenameWin64ToBitness(element);
1290 }
1291
1292 private void ConvertRequiredPrivilegeElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Name");
@@ -1394,6 +1370,18 @@ namespace WixToolset.Converters
1370 {
1371 element.Name = SoftwareTagElementName;
1372 }
1373 +
1374 + this.RemoveAttributeIfPresent(element, "Licensed", ConverterTestType.SoftwareTagLicensedObsolete, "The {0} element contains obsolete '{1}' attribute. The attribute will be removed.");
1375 + this.RemoveAttributeIfPresent(element, "Type", ConverterTestType.SoftwareTagLicensedObsolete, "The {0} element contains obsolete '{1}' attribute. The attribute will be removed.");
1376 + this.RenameWin64ToBitness(element);
1377 + }
1378 +
1379 + private void ConvertTagRefElement(XElement element)
1380 + {
1381 + if (this.OnError(ConverterTestType.TagRefElementRenamed, element, "The TagRef element has been renamed. Use the 'SoftwareTagRef' element instead."))
1382 + {
1383 + element.Name = SoftwareTagRefElementName;
1384 + }
1385 }
1386
1387 private void ConvertTextElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value");
@@ -1543,13 +1531,7 @@ namespace WixToolset.Converters
1531
1532 private void ConvertUtilRegistrySearchElement(XElement element)
1533 {
1546 - var win64 = element.Attribute("Win64");
1547 - if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead."))
1548 - {
1549 - var value = this.UpdateWin64ValueToBitnessValue(win64);
1550 - element.Add(new XAttribute("Bitness", value));
1551 - win64.Remove();
1552 - }
1534 + this.RenameWin64ToBitness(element);
1535
1536 if (this.SourceVersion < 4)
1537 {
@@ -1593,6 +1575,26 @@ namespace WixToolset.Converters
1575 }
1576 }
1577
1578 + void RemoveAttributeIfPresent(XElement element, string attributeName, ConverterTestType type, string format)
1579 + {
1580 + var xAttribute = element.Attribute(attributeName);
1581 + if (null != xAttribute && this.OnError(type, element, format, element.Name.LocalName, xAttribute.Name))
1582 + {
1583 + xAttribute.Remove();
1584 + }
1585 + }
1586 +
1587 + private void RenameWin64ToBitness(XElement element)
1588 + {
1589 + var win64 = element.Attribute("Win64");
1590 + if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The {0} element's Win64 attribute has been renamed. Use the Bitness attribute instead.", element.Name.LocalName))
1591 + {
1592 + var value = this.UpdateWin64ValueToBitnessValue(win64);
1593 + element.Add(new XAttribute("Bitness", value));
1594 + win64.Remove();
1595 + }
1596 + }
1597 +
1598 private string UpdateWin64ValueToBitnessValue(XAttribute xWin64Attribute)
1599 {
1600 var value = xWin64Attribute.Value ?? String.Empty;
@@ -2185,6 +2187,21 @@ namespace WixToolset.Converters
2187 /// The RegistryKey element's Action attribute is obsolete.
2188 /// </summary>
2189 RegistryKeyActionObsolete,
2190 +
2191 + /// <summary>
2192 + /// The TagRef element has been renamed. Use the element 'SoftwareTagRef' name.
2193 + /// </summary>
2194 + TagRefElementRenamed,
2195 +
2196 + /// <summary>
2197 + /// The SoftwareTag element's Licensed attribute is obsolete.
2198 + /// </summary>
2199 + SoftwareTagLicensedObsolete,
2200 +
2201 + /// <summary>
2202 + /// The SoftwareTag element's Type attribute is obsolete.
2203 + /// </summary>
2204 + SoftwareTagTypeObsolete,
2205 }
2206 }
2207 }
src/test/WixToolsetTest.Converters/TagFixture.cs
+66
@@ -41,5 +41,71 @@ namespace WixToolsetTest.Converters
41 var actualLines = UnformattedDocumentLines(document);
42 WixAssert.CompareLineByLine(expected, actualLines);
43 }
44 +
45 + [Fact]
46 + public void FixTagExtensionDeprecations()
47 + {
48 + var parse = String.Join(Environment.NewLine,
49 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:tag='http://schemas.microsoft.com/wix/TagExtension'>",
50 + " <Product>",
51 + " <tag:Tag Regid='wixtoolset.org' InstallDirectory='InstallFolder' Licensed='true' Type='component' Win64='yes' />",
52 + " </Product>",
53 + "</Wix>");
54 +
55 + var expected = new[]
56 + {
57 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
58 + " <Package>",
59 + " <SoftwareTag Regid=\"wixtoolset.org\" InstallDirectory=\"InstallFolder\" Bitness=\"always64\" />",
60 + " </Package>",
61 + "</Wix>"
62 + };
63 +
64 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
65 +
66 + var messaging = new MockMessaging();
67 + var converter = new WixConverter(messaging, 2, null, null);
68 +
69 + var errors = converter.ConvertDocument(document);
70 + Assert.Equal(7, errors);
71 +
72 + var actualLines = UnformattedDocumentLines(document);
73 + WixAssert.CompareLineByLine(expected, actualLines);
74 + }
75 +
76 + [Fact]
77 + public void FixTagExtensionTagRef()
78 + {
79 + var parse = String.Join(Environment.NewLine,
80 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:tag='http://schemas.microsoft.com/wix/TagExtension'>",
81 + " <Fragment>",
82 + " <PatchFamily>",
83 + " <tag:TagRef Regid='wixtoolset.org' />",
84 + " </PatchFamily>",
85 + " </Fragment>",
86 + "</Wix>");
87 +
88 + var expected = new[]
89 + {
90 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
91 + " <Fragment>",
92 + " <PatchFamily>",
93 + " <SoftwareTagRef Regid=\"wixtoolset.org\" />",
94 + " </PatchFamily>",
95 + " </Fragment>",
96 + "</Wix>"
97 + };
98 +
99 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
100 +
101 + var messaging = new MockMessaging();
102 + var converter = new WixConverter(messaging, 2, null, null);
103 +
104 + var errors = converter.ConvertDocument(document);
105 + Assert.Equal(3, errors);
106 +
107 + var actualLines = UnformattedDocumentLines(document);
108 + WixAssert.CompareLineByLine(expected, actualLines);
109 + }
110 }
111 }