From 3f0af880a3d8a41e1a6ac342f8fba06d22b223a0 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 1 Jul 2020 01:59:21 -0700 Subject: Make Feature/@Absent and Feature/@AllowAdvertise consistent Conversion for wixtoolset/issues#5990 --- src/WixToolset.Converters/WixConverter.cs | 36 ++++++++++ .../WixToolsetTest.Converters/FeatureFixture.cs | 77 ++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/test/WixToolsetTest.Converters/FeatureFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index c18b095e..a05c7f58 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -481,6 +481,32 @@ namespace WixToolset.Converters private void ConvertFeatureElement(XElement element) { + var xAbsent = element.Attribute("Absent"); + if (xAbsent != null && + this.OnError(ConverterTestType.FeatureAbsentAttributeReplaced, element, "The Feature element's Absent attribute has been replaced with the AllowAbsent attribute. Use the 'AllowAbsent' attribute instead.")) + { + if (xAbsent.Value == "allow") + { + element.Add(new XAttribute("AllowAbsent", "yes")); + } + xAbsent.Remove(); + } + + var xAllowAdvertise = element.Attribute("AllowAdvertise"); + if (xAllowAdvertise != null) + { + if ((xAllowAdvertise.Value == "system" || xAllowAdvertise.Value == "allow") && + this.OnError(ConverterTestType.FeatureAllowAdvertiseValueDeprecated, element, "The AllowAdvertise attribute's '{0}' value deprecated. Set the value to 'yes' instead.", xAllowAdvertise.Value)) + { + xAllowAdvertise.Value = "yes"; + } + else if (xAllowAdvertise.Value == "disallow" && + this.OnError(ConverterTestType.FeatureAllowAdvertiseValueDeprecated, element, "The AllowAdvertise attribute's '{0}' value deprecated. Remove the value instead.", xAllowAdvertise.Value)) + { + xAllowAdvertise.Remove(); + } + } + var xCondition = element.Element(ConditionElementName); if (xCondition != null) { @@ -1132,6 +1158,16 @@ namespace WixToolset.Converters /// Displayed when the XML declaration is present in the source file. /// DeclarationPresent, + + /// + /// The Feature Absent attribute renamed to AllowAbsent. + /// + FeatureAbsentAttributeReplaced, + + /// + /// The Feature AllowAdvertise attribute value deprecated. + /// + FeatureAllowAdvertiseValueDeprecated, } } } diff --git a/src/test/WixToolsetTest.Converters/FeatureFixture.cs b/src/test/WixToolsetTest.Converters/FeatureFixture.cs new file mode 100644 index 00000000..9d943773 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/FeatureFixture.cs @@ -0,0 +1,77 @@ +// 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 FeatureFixture : BaseConverterFixture + { + [Fact] + public void FixAllowAttributes() + { + 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 WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(4, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + + [Fact] + public void RemoveDeprecatedAllowAdvertiseAttributes() + { + 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 WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(3, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb