From db8641b5ab125679b028848d1747d7a4cef6fc37 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 10 Dec 2018 22:52:03 -0600 Subject: Make WixCop move Directory/@ShortName to @Name. (#7) Fixes wixtoolset/issues#5652. --- Tools.sln | 2 +- src/test/WixToolsetTest.WixCop/ConverterFixture.cs | 28 ++++++++++++++++ src/wixcop/Converter.cs | 37 +++++++++++++++------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Tools.sln b/Tools.sln index ca2e23d6..75f52adc 100644 --- a/Tools.sln +++ b/Tools.sln @@ -22,7 +22,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixCop", "src\wixcop\WixCop EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Tools.Core", "src\WixToolset.Tools.Core\WixToolset.Tools.Core.csproj", "{9C3B486F-AE0E-43BA-823A-30808B73C6B4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixCopTests", "src\test\wixcop\WixCopTests.csproj", "{F1A8112B-95A1-4AF7-81CB-523BE7DB8E5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.WixCop", "src\test\WixToolsetTest.WixCop\WixToolsetTest.WixCop.csproj", "{F1A8112B-95A1-4AF7-81CB-523BE7DB8E5C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/test/WixToolsetTest.WixCop/ConverterFixture.cs b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs index 863a781a..ceac07d6 100644 --- a/src/test/WixToolsetTest.WixCop/ConverterFixture.cs +++ b/src/test/WixToolsetTest.WixCop/ConverterFixture.cs @@ -420,6 +420,34 @@ namespace WixToolsetTest.WixCop Assert.Equal(expected, actual); } + [Fact] + public void CanConvertShortNameDirectoryWithoutName() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var expected = String.Join(Environment.NewLine, + "", + "", + " ", + ""); + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new DummyMessaging(); + var converter = new Converter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + + var actual = UnformattedDocumentString(document); + + Assert.Equal(1, errors); + Assert.Equal(expected, actual); + } + [Fact] public void CanConvertSuppressSignatureValidationNo() { diff --git a/src/wixcop/Converter.cs b/src/wixcop/Converter.cs index 5408d370..37016c19 100644 --- a/src/wixcop/Converter.cs +++ b/src/wixcop/Converter.cs @@ -22,6 +22,7 @@ namespace WixToolset.Tools.WixCop 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 XName DirectoryElementName = WixNamespace + "Directory"; private static readonly XName FileElementName = WixNamespace + "File"; private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; @@ -71,19 +72,9 @@ namespace WixToolset.Tools.WixCop /// Test errors to ignore. public Converter(IMessaging messaging, int indentationAmount, IEnumerable errorsAsWarnings = null, IEnumerable ignoreErrors = null) { - // workaround IDE0009 bug - /*this.ConvertElementMapping = new Dictionary>() - { - { Converter.FileElementName, this.ConvertFileElement }, - { Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, - { Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, - { Converter.MspPackageElementName, this.ConvertSuppressSignatureValidation }, - { Converter.MsuPackageElementName, this.ConvertSuppressSignatureValidation }, - { Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, - { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace }, - };*/ this.ConvertElementMapping = new Dictionary> { + { Converter.DirectoryElementName, this.ConvertDirectoryElement }, { Converter.FileElementName, this.ConvertFileElement }, { Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, { Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, @@ -92,7 +83,7 @@ namespace WixToolset.Tools.WixCop { Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, { Converter.CustomActionElementName, this.ConvertCustomActionElement }, { Converter.PropertyElementName, this.ConvertPropertyElement }, - { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace } + { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace }, }; this.Messaging = messaging; @@ -296,6 +287,23 @@ namespace WixToolset.Tools.WixCop } } + private void ConvertDirectoryElement(XElement element) + { + if (null == element.Attribute("Name")) + { + var attribute = element.Attribute("ShortName"); + if (null != attribute) + { + var shortName = attribute.Value; + if (this.OnError(ConverterTestType.AssignDirectoryNameFromShortName, element, "The directory ShortName attribute is being renamed to Name since Name wasn't specified for value '{0}'", shortName)) + { + element.Add(new XAttribute("Name", shortName)); + attribute.Remove(); + } + } + } + } + private void ConvertFileElement(XElement element) { if (null == element.Attribute("Id")) @@ -611,6 +619,11 @@ namespace WixToolset.Tools.WixCop /// QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout. /// QtExecCmdTimeoutAmbiguous, + + /// + /// Directory/@ShortName may only be specified with Directory/@Name. + /// + AssignDirectoryNameFromShortName, } } } -- cgit v1.2.3-55-g6feb