aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2018-12-10 22:52:03 -0600
committerGitHub <noreply@github.com>2018-12-10 22:52:03 -0600
commitdb8641b5ab125679b028848d1747d7a4cef6fc37 (patch)
treee01af02b7bcee79de4c768c3e92b3552b61e45fd
parent06a7caade34cba18629024ea2ccce567d85898d7 (diff)
downloadwix-db8641b5ab125679b028848d1747d7a4cef6fc37.tar.gz
wix-db8641b5ab125679b028848d1747d7a4cef6fc37.tar.bz2
wix-db8641b5ab125679b028848d1747d7a4cef6fc37.zip
Make WixCop move Directory/@ShortName to @Name. (#7)
Fixes wixtoolset/issues#5652.
-rw-r--r--Tools.sln2
-rw-r--r--src/test/WixToolsetTest.WixCop/ConverterFixture.cs28
-rw-r--r--src/wixcop/Converter.cs37
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
22EndProject 22EndProject
23Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Tools.Core", "src\WixToolset.Tools.Core\WixToolset.Tools.Core.csproj", "{9C3B486F-AE0E-43BA-823A-30808B73C6B4}" 23Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Tools.Core", "src\WixToolset.Tools.Core\WixToolset.Tools.Core.csproj", "{9C3B486F-AE0E-43BA-823A-30808B73C6B4}"
24EndProject 24EndProject
25Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixCopTests", "src\test\wixcop\WixCopTests.csproj", "{F1A8112B-95A1-4AF7-81CB-523BE7DB8E5C}" 25Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.WixCop", "src\test\WixToolsetTest.WixCop\WixToolsetTest.WixCop.csproj", "{F1A8112B-95A1-4AF7-81CB-523BE7DB8E5C}"
26EndProject 26EndProject
27Global 27Global
28 GlobalSection(SolutionConfigurationPlatforms) = preSolution 28 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
@@ -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}