From c8e5b2b045b35bd6e5b8b2021a3173df16500887 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 27 Jun 2020 22:55:44 -0700 Subject: Correctly detect wix4 for better conversions --- src/WixToolset.Converters/WixConverter.cs | 23 ++++++---- .../WixToolsetTest.Converters/ConverterFixture.cs | 4 +- .../Wix4ConversionFixture.cs | 53 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 89d33598..7ac64710 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -24,6 +24,7 @@ namespace WixToolset.Converters private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n". private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; + private static readonly XNamespace Wix3Namespace = "http://schemas.microsoft.com/wix/2006/wi"; private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; private static readonly XName AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence"; @@ -68,7 +69,11 @@ namespace WixToolset.Converters private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig"; private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; private static readonly XName PropertyElementName = WixNamespace + "Property"; + private static readonly XName Wix4ElementName = WixNamespace + "Wix"; + private static readonly XName Wix3ElementName = Wix3Namespace + "Wix"; private static readonly XName WixElementWithoutNamespaceName = XNamespace.None + "Wix"; + private static readonly XName Include4ElementName = WixNamespace + "Include"; + private static readonly XName Include3ElementName = Wix3Namespace + "Include"; private static readonly XName IncludeElementWithoutNamespaceName = XNamespace.None + "Include"; private static readonly Dictionary OldToNewNamespaceMapping = new Dictionary() @@ -343,17 +348,17 @@ namespace WixToolset.Converters foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration)) { - if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns)) + if (element.Name == Wix3ElementName || element.Name == Include3ElementName) { - if (Wix3Namespaces.Contains(declaration.Value)) - { - this.SourceVersion = 3; - } - else if (Wix4Namespaces.Contains(declaration.Value)) - { - this.SourceVersion = 4; - } + this.SourceVersion = 3; + } + else if (element.Name == Wix4ElementName || element.Name == Include4ElementName) + { + this.SourceVersion = 4; + } + if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns)) + { if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName)) { deprecatedToUpdatedNamespaces.Add(declaration.Value, ns); diff --git a/src/test/WixToolsetTest.Converters/ConverterFixture.cs b/src/test/WixToolsetTest.Converters/ConverterFixture.cs index c205df39..6e2ad2c5 100644 --- a/src/test/WixToolsetTest.Converters/ConverterFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterFixture.cs @@ -331,7 +331,7 @@ namespace WixToolsetTest.Converters { var parse = String.Join(Environment.NewLine, "", - "", + "", " ", ""); @@ -349,7 +349,7 @@ namespace WixToolsetTest.Converters var actual = UnformattedDocumentString(document); - Assert.Equal(2, errors); + Assert.Equal(3, errors); Assert.Equal(expected, actual); } diff --git a/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs b/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs new file mode 100644 index 00000000..a3f2adc8 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs @@ -0,0 +1,53 @@ +// 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 Wix4ConversionFixture : BaseConverterFixture + { + [Fact] + public void DoesNotAddFileId() + { + 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(1, errors); + + var actualLines = UnformattedDocumentLines(document); + CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb