diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/WixToolsetTest.WixCop/ConverterFixture.cs | 28 | ||||
| -rw-r--r-- | src/wixcop/Converter.cs | 37 |
2 files changed, 53 insertions, 12 deletions
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 | |||
| @@ -421,6 +421,34 @@ namespace WixToolsetTest.WixCop | |||
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | [Fact] | 423 | [Fact] |
| 424 | public void CanConvertShortNameDirectoryWithoutName() | ||
| 425 | { | ||
| 426 | var parse = String.Join(Environment.NewLine, | ||
| 427 | "<?xml version='1.0' encoding='utf-8'?>", | ||
| 428 | "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", | ||
| 429 | " <Directory ShortName='iamshort' />", | ||
| 430 | "</Wix>"); | ||
| 431 | |||
| 432 | var expected = String.Join(Environment.NewLine, | ||
| 433 | "<?xml version=\"1.0\" encoding=\"utf-16\"?>", | ||
| 434 | "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", | ||
| 435 | " <Directory Name=\"iamshort\" />", | ||
| 436 | "</Wix>"); | ||
| 437 | |||
| 438 | var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); | ||
| 439 | |||
| 440 | var messaging = new DummyMessaging(); | ||
| 441 | var converter = new Converter(messaging, 2, null, null); | ||
| 442 | |||
| 443 | var errors = converter.ConvertDocument(document); | ||
| 444 | |||
| 445 | var actual = UnformattedDocumentString(document); | ||
| 446 | |||
| 447 | Assert.Equal(1, errors); | ||
| 448 | Assert.Equal(expected, actual); | ||
| 449 | } | ||
| 450 | |||
| 451 | [Fact] | ||
| 424 | public void CanConvertSuppressSignatureValidationNo() | 452 | public void CanConvertSuppressSignatureValidationNo() |
| 425 | { | 453 | { |
| 426 | var parse = String.Join(Environment.NewLine, | 454 | var parse = String.Join(Environment.NewLine, |
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 | |||
| 22 | private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n". | 22 | private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n". |
| 23 | private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; | 23 | private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; |
| 24 | 24 | ||
| 25 | private static readonly XName DirectoryElementName = WixNamespace + "Directory"; | ||
| 25 | private static readonly XName FileElementName = WixNamespace + "File"; | 26 | private static readonly XName FileElementName = WixNamespace + "File"; |
| 26 | private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; | 27 | private static readonly XName ExePackageElementName = WixNamespace + "ExePackage"; |
| 27 | private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; | 28 | private static readonly XName MsiPackageElementName = WixNamespace + "MsiPackage"; |
| @@ -71,19 +72,9 @@ namespace WixToolset.Tools.WixCop | |||
| 71 | /// <param name="ignoreErrors">Test errors to ignore.</param> | 72 | /// <param name="ignoreErrors">Test errors to ignore.</param> |
| 72 | public Converter(IMessaging messaging, int indentationAmount, IEnumerable<string> errorsAsWarnings = null, IEnumerable<string> ignoreErrors = null) | 73 | public Converter(IMessaging messaging, int indentationAmount, IEnumerable<string> errorsAsWarnings = null, IEnumerable<string> ignoreErrors = null) |
| 73 | { | 74 | { |
| 74 | // workaround IDE0009 bug | ||
| 75 | /*this.ConvertElementMapping = new Dictionary<XName, Action<XElement>>() | ||
| 76 | { | ||
| 77 | { Converter.FileElementName, this.ConvertFileElement }, | ||
| 78 | { Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, | ||
| 79 | { Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, | ||
| 80 | { Converter.MspPackageElementName, this.ConvertSuppressSignatureValidation }, | ||
| 81 | { Converter.MsuPackageElementName, this.ConvertSuppressSignatureValidation }, | ||
| 82 | { Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, | ||
| 83 | { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace }, | ||
| 84 | };*/ | ||
| 85 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> | 75 | this.ConvertElementMapping = new Dictionary<XName, Action<XElement>> |
| 86 | { | 76 | { |
| 77 | { Converter.DirectoryElementName, this.ConvertDirectoryElement }, | ||
| 87 | { Converter.FileElementName, this.ConvertFileElement }, | 78 | { Converter.FileElementName, this.ConvertFileElement }, |
| 88 | { Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, | 79 | { Converter.ExePackageElementName, this.ConvertSuppressSignatureValidation }, |
| 89 | { Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, | 80 | { Converter.MsiPackageElementName, this.ConvertSuppressSignatureValidation }, |
| @@ -92,7 +83,7 @@ namespace WixToolset.Tools.WixCop | |||
| 92 | { Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, | 83 | { Converter.PayloadElementName, this.ConvertSuppressSignatureValidation }, |
| 93 | { Converter.CustomActionElementName, this.ConvertCustomActionElement }, | 84 | { Converter.CustomActionElementName, this.ConvertCustomActionElement }, |
| 94 | { Converter.PropertyElementName, this.ConvertPropertyElement }, | 85 | { Converter.PropertyElementName, this.ConvertPropertyElement }, |
| 95 | { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace } | 86 | { Converter.WixElementWithoutNamespaceName, this.ConvertWixElementWithoutNamespace }, |
| 96 | }; | 87 | }; |
| 97 | 88 | ||
| 98 | this.Messaging = messaging; | 89 | this.Messaging = messaging; |
| @@ -296,6 +287,23 @@ namespace WixToolset.Tools.WixCop | |||
| 296 | } | 287 | } |
| 297 | } | 288 | } |
| 298 | 289 | ||
| 290 | private void ConvertDirectoryElement(XElement element) | ||
| 291 | { | ||
| 292 | if (null == element.Attribute("Name")) | ||
| 293 | { | ||
| 294 | var attribute = element.Attribute("ShortName"); | ||
| 295 | if (null != attribute) | ||
| 296 | { | ||
| 297 | var shortName = attribute.Value; | ||
| 298 | if (this.OnError(ConverterTestType.AssignDirectoryNameFromShortName, element, "The directory ShortName attribute is being renamed to Name since Name wasn't specified for value '{0}'", shortName)) | ||
| 299 | { | ||
| 300 | element.Add(new XAttribute("Name", shortName)); | ||
| 301 | attribute.Remove(); | ||
| 302 | } | ||
| 303 | } | ||
| 304 | } | ||
| 305 | } | ||
| 306 | |||
| 299 | private void ConvertFileElement(XElement element) | 307 | private void ConvertFileElement(XElement element) |
| 300 | { | 308 | { |
| 301 | if (null == element.Attribute("Id")) | 309 | if (null == element.Attribute("Id")) |
| @@ -611,6 +619,11 @@ namespace WixToolset.Tools.WixCop | |||
| 611 | /// QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout. | 619 | /// QtExecCmdTimeout was previously used for both CAQuietExec and CAQuietExec64. For WixQuietExec, use WixQuietExecCmdTimeout. For WixQuietExec64, use WixQuietExec64CmdTimeout. |
| 612 | /// </summary> | 620 | /// </summary> |
| 613 | QtExecCmdTimeoutAmbiguous, | 621 | QtExecCmdTimeoutAmbiguous, |
| 622 | |||
| 623 | /// <summary> | ||
| 624 | /// Directory/@ShortName may only be specified with Directory/@Name. | ||
| 625 | /// </summary> | ||
| 626 | AssignDirectoryNameFromShortName, | ||
| 614 | } | 627 | } |
| 615 | } | 628 | } |
| 616 | } | 629 | } |
