aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-06-27 22:55:44 -0700
committerRob Mensching <rob@firegiant.com>2020-06-27 22:59:20 -0700
commitc8e5b2b045b35bd6e5b8b2021a3173df16500887 (patch)
treed8f191dd3cc939e81fca73d631d9f227f4d0331b /src
parentf17f7138de534891a2605c9a86c0acc36cc41154 (diff)
downloadwix-c8e5b2b045b35bd6e5b8b2021a3173df16500887.tar.gz
wix-c8e5b2b045b35bd6e5b8b2021a3173df16500887.tar.bz2
wix-c8e5b2b045b35bd6e5b8b2021a3173df16500887.zip
Correctly detect wix4 for better conversions
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Converters/WixConverter.cs23
-rw-r--r--src/test/WixToolsetTest.Converters/ConverterFixture.cs4
-rw-r--r--src/test/WixToolsetTest.Converters/Wix4ConversionFixture.cs53
3 files changed, 69 insertions, 11 deletions
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
24 24
25 private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n". 25 private const char XDocumentNewLine = '\n'; // XDocument normalizes "\r\n" to just "\n".
26 private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; 26 private static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs";
27 private static readonly XNamespace Wix3Namespace = "http://schemas.microsoft.com/wix/2006/wi";
27 private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util"; 28 private static readonly XNamespace WixUtilNamespace = "http://wixtoolset.org/schemas/v4/wxs/util";
28 29
29 private static readonly XName AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence"; 30 private static readonly XName AdminExecuteSequenceElementName = WixNamespace + "AdminExecuteSequence";
@@ -68,7 +69,11 @@ namespace WixToolset.Converters
68 private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig"; 69 private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig";
69 private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; 70 private static readonly XName CustomActionElementName = WixNamespace + "CustomAction";
70 private static readonly XName PropertyElementName = WixNamespace + "Property"; 71 private static readonly XName PropertyElementName = WixNamespace + "Property";
72 private static readonly XName Wix4ElementName = WixNamespace + "Wix";
73 private static readonly XName Wix3ElementName = Wix3Namespace + "Wix";
71 private static readonly XName WixElementWithoutNamespaceName = XNamespace.None + "Wix"; 74 private static readonly XName WixElementWithoutNamespaceName = XNamespace.None + "Wix";
75 private static readonly XName Include4ElementName = WixNamespace + "Include";
76 private static readonly XName Include3ElementName = Wix3Namespace + "Include";
72 private static readonly XName IncludeElementWithoutNamespaceName = XNamespace.None + "Include"; 77 private static readonly XName IncludeElementWithoutNamespaceName = XNamespace.None + "Include";
73 78
74 private static readonly Dictionary<string, XNamespace> OldToNewNamespaceMapping = new Dictionary<string, XNamespace>() 79 private static readonly Dictionary<string, XNamespace> OldToNewNamespaceMapping = new Dictionary<string, XNamespace>()
@@ -343,17 +348,17 @@ namespace WixToolset.Converters
343 348
344 foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration)) 349 foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration))
345 { 350 {
346 if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns)) 351 if (element.Name == Wix3ElementName || element.Name == Include3ElementName)
347 { 352 {
348 if (Wix3Namespaces.Contains(declaration.Value)) 353 this.SourceVersion = 3;
349 { 354 }
350 this.SourceVersion = 3; 355 else if (element.Name == Wix4ElementName || element.Name == Include4ElementName)
351 } 356 {
352 else if (Wix4Namespaces.Contains(declaration.Value)) 357 this.SourceVersion = 4;
353 { 358 }
354 this.SourceVersion = 4;
355 }
356 359
360 if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns))
361 {
357 if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName)) 362 if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName))
358 { 363 {
359 deprecatedToUpdatedNamespaces.Add(declaration.Value, ns); 364 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
331 { 331 {
332 var parse = String.Join(Environment.NewLine, 332 var parse = String.Join(Environment.NewLine,
333 "<?xml version='1.0' encoding='utf-8'?>", 333 "<?xml version='1.0' encoding='utf-8'?>",
334 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>", 334 "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
335 " <File Source='path\\to\\foo.txt' />", 335 " <File Source='path\\to\\foo.txt' />",
336 "</Wix>"); 336 "</Wix>");
337 337
@@ -349,7 +349,7 @@ namespace WixToolsetTest.Converters
349 349
350 var actual = UnformattedDocumentString(document); 350 var actual = UnformattedDocumentString(document);
351 351
352 Assert.Equal(2, errors); 352 Assert.Equal(3, errors);
353 Assert.Equal(expected, actual); 353 Assert.Equal(expected, actual);
354 } 354 }
355 355
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 @@
1// 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.
2
3namespace WixToolsetTest.Converters
4{
5 using System;
6 using System.Xml.Linq;
7 using WixToolset.Converters;
8 using WixToolsetTest.Converters.Mocks;
9 using Xunit;
10
11 public class Wix4ConversionFixture : BaseConverterFixture
12 {
13 [Fact]
14 public void DoesNotAddFileId()
15 {
16 var parse = String.Join(Environment.NewLine,
17 "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
18 "<Wix xmlns='http://wixtoolset.org/schemas/v4/wxs'>",
19 " <Fragment>",
20 " <ComponentGroup Id='ProductComponents' Directory='INSTALLFOLDER'>",
21 " <Component>",
22 " <File Source='example.txt' />",
23 " </Component>",
24 " </ComponentGroup>",
25 " </Fragment>",
26 "</Wix>");
27
28 var expected = new[]
29 {
30 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
31 " <Fragment>",
32 " <ComponentGroup Id=\"ProductComponents\" Directory=\"INSTALLFOLDER\">",
33 " <Component>",
34 " <File Source=\"example.txt\" />",
35 " </Component>",
36 " </ComponentGroup>",
37 " </Fragment>",
38 "</Wix>"
39 };
40
41 var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
42
43 var messaging = new MockMessaging();
44 var converter = new WixConverter(messaging, 2, null, null);
45
46 var errors = converter.ConvertDocument(document);
47 Assert.Equal(1, errors);
48
49 var actualLines = UnformattedDocumentLines(document);
50 CompareLineByLine(expected, actualLines);
51 }
52 }
53}