Make Feature/@Absent and Feature/@AllowAdvertise consistent
Conversion for wixtoolset/issues#5990
Rob Mensching committed
Jul 1, 2020 at 01:59 UTC
3f0af880a3d8a41e1a6ac342f8fba06d22b223a0
2 files changed
+113
src/WixToolset.Converters/WixConverter.cs
+36
@@ -481,6 +481,32 @@ namespace WixToolset.Converters
481
482
private void ConvertFeatureElement(XElement element)
483
{
484
+ var xAbsent = element.Attribute("Absent");
485
+ if (xAbsent != null &&
486
+ this.OnError(ConverterTestType.FeatureAbsentAttributeReplaced, element, "The Feature element's Absent attribute has been replaced with the AllowAbsent attribute. Use the 'AllowAbsent' attribute instead."))
487
+ {
488
+ if (xAbsent.Value == "allow")
489
+ {
490
+ element.Add(new XAttribute("AllowAbsent", "yes"));
491
+ }
492
+ xAbsent.Remove();
493
+ }
494
+
495
+ var xAllowAdvertise = element.Attribute("AllowAdvertise");
496
+ if (xAllowAdvertise != null)
497
+ {
498
+ if ((xAllowAdvertise.Value == "system" || xAllowAdvertise.Value == "allow") &&
499
+ this.OnError(ConverterTestType.FeatureAllowAdvertiseValueDeprecated, element, "The AllowAdvertise attribute's '{0}' value deprecated. Set the value to 'yes' instead.", xAllowAdvertise.Value))
500
+ {
501
+ xAllowAdvertise.Value = "yes";
502
+ }
503
+ else if (xAllowAdvertise.Value == "disallow" &&
504
+ this.OnError(ConverterTestType.FeatureAllowAdvertiseValueDeprecated, element, "The AllowAdvertise attribute's '{0}' value deprecated. Remove the value instead.", xAllowAdvertise.Value))
505
+ {
506
+ xAllowAdvertise.Remove();
507
+ }
508
+ }
509
+
510
var xCondition = element.Element(ConditionElementName);
511
if (xCondition != null)
512
{
@@ -1132,6 +1158,16 @@ namespace WixToolset.Converters
1158
/// Displayed when the XML declaration is present in the source file.
1159
/// </summary>
1160
DeclarationPresent,
1161
+
1162
+ /// <summary>
1163
+ /// The Feature Absent attribute renamed to AllowAbsent.
1164
+ /// </summary>
1165
+ FeatureAbsentAttributeReplaced,
1166
+
1167
+ /// <summary>
1168
+ /// The Feature AllowAdvertise attribute value deprecated.
1169
+ /// </summary>
1170
+ FeatureAllowAdvertiseValueDeprecated,
1171
}
1172
}
1173
}
src/test/WixToolsetTest.Converters/FeatureFixture.cs
new
+77
@@ -0,0 +1,77 @@
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 FeatureFixture : BaseConverterFixture
12
+ {
13
+ [Fact]
14
+ public void FixAllowAttributes()
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
+ " <Feature Absent='allow' AllowAdvertise='system' />",
21
+ " </Fragment>",
22
+ "</Wix>");
23
+
24
+ var expected = new[]
25
+ {
26
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
27
+ " <Fragment>",
28
+ " <Feature AllowAdvertise=\"yes\" AllowAbsent=\"yes\" />",
29
+ " </Fragment>",
30
+ "</Wix>"
31
+ };
32
+
33
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
34
+
35
+ var messaging = new MockMessaging();
36
+ var converter = new WixConverter(messaging, 2, null, null);
37
+
38
+ var errors = converter.ConvertDocument(document);
39
+ Assert.Equal(4, errors);
40
+
41
+ var actualLines = UnformattedDocumentLines(document);
42
+ CompareLineByLine(expected, actualLines);
43
+ }
44
+
45
+ [Fact]
46
+ public void RemoveDeprecatedAllowAdvertiseAttributes()
47
+ {
48
+ var parse = String.Join(Environment.NewLine,
49
+ "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
50
+ "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
51
+ " <Fragment>",
52
+ " <Feature AllowAdvertise='disallow' />",
53
+ " </Fragment>",
54
+ "</Wix>");
55
+
56
+ var expected = new[]
57
+ {
58
+ "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
59
+ " <Fragment>",
60
+ " <Feature />",
61
+ " </Fragment>",
62
+ "</Wix>"
63
+ };
64
+
65
+ var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
66
+
67
+ var messaging = new MockMessaging();
68
+ var converter = new WixConverter(messaging, 2, null, null);
69
+
70
+ var errors = converter.ConvertDocument(document);
71
+ Assert.Equal(3, errors);
72
+
73
+ var actualLines = UnformattedDocumentLines(document);
74
+ CompareLineByLine(expected, actualLines);
75
+ }
76
+ }
77
+}