diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-03-26 15:21:06 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-03-30 21:30:04 +1000 |
| commit | afbc6889c73d58136cb8851858ca3c17f41dc2c5 (patch) | |
| tree | 1d7c66218176c7e8a28d49a4e22c60fe1e4e4c0d /src/WixToolset.Core.TestPackage | |
| parent | 192c5aa59b5d8e5e9df9095982317c224f3d4f04 (diff) | |
| download | wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.tar.gz wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.tar.bz2 wix-afbc6889c73d58136cb8851858ca3c17f41dc2c5.zip | |
Add BundleExtension element.
Add GetTestXml.
Fix issue with building with current version of burn.
Diffstat (limited to 'src/WixToolset.Core.TestPackage')
| -rw-r--r-- | src/WixToolset.Core.TestPackage/BundleExtractor.cs | 44 | ||||
| -rw-r--r-- | src/WixToolset.Core.TestPackage/ExtractBAContainerResult.cs | 39 | ||||
| -rw-r--r-- | src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs | 75 |
3 files changed, 158 insertions, 0 deletions
diff --git a/src/WixToolset.Core.TestPackage/BundleExtractor.cs b/src/WixToolset.Core.TestPackage/BundleExtractor.cs new file mode 100644 index 00000000..3d7b2932 --- /dev/null +++ b/src/WixToolset.Core.TestPackage/BundleExtractor.cs | |||
| @@ -0,0 +1,44 @@ | |||
| 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 | |||
| 3 | namespace WixToolset.Core.TestPackage | ||
| 4 | { | ||
| 5 | using System.IO; | ||
| 6 | using System.Xml; | ||
| 7 | using WixToolset.Core.Burn.Bundles; | ||
| 8 | using WixToolset.Extensibility.Services; | ||
| 9 | |||
| 10 | public class BundleExtractor | ||
| 11 | { | ||
| 12 | public static ExtractBAContainerResult ExtractBAContainer(IMessaging messaging, string bundleFilePath, string destinationFolderPath, string tempFolderPath) | ||
| 13 | { | ||
| 14 | var result = new ExtractBAContainerResult(); | ||
| 15 | Directory.CreateDirectory(tempFolderPath); | ||
| 16 | using (var burnReader = BurnReader.Open(messaging, bundleFilePath)) | ||
| 17 | { | ||
| 18 | result.Success = burnReader.ExtractUXContainer(destinationFolderPath, tempFolderPath); | ||
| 19 | } | ||
| 20 | |||
| 21 | if (result.Success) | ||
| 22 | { | ||
| 23 | result.ManifestDocument = LoadBurnManifest(destinationFolderPath); | ||
| 24 | result.ManifestNamespaceManager = GetBurnNamespaceManager(result.ManifestDocument, "burn"); | ||
| 25 | } | ||
| 26 | |||
| 27 | return result; | ||
| 28 | } | ||
| 29 | |||
| 30 | public static XmlNamespaceManager GetBurnNamespaceManager(XmlDocument document, string prefix) | ||
| 31 | { | ||
| 32 | var namespaceManager = new XmlNamespaceManager(document.NameTable); | ||
| 33 | namespaceManager.AddNamespace(prefix, BurnCommon.BurnNamespace); | ||
| 34 | return namespaceManager; | ||
| 35 | } | ||
| 36 | |||
| 37 | public static XmlDocument LoadBurnManifest(string baFolderPath) | ||
| 38 | { | ||
| 39 | var document = new XmlDocument(); | ||
| 40 | document.Load(Path.Combine(baFolderPath, "manifest.xml")); | ||
| 41 | return document; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
diff --git a/src/WixToolset.Core.TestPackage/ExtractBAContainerResult.cs b/src/WixToolset.Core.TestPackage/ExtractBAContainerResult.cs new file mode 100644 index 00000000..6d2ea943 --- /dev/null +++ b/src/WixToolset.Core.TestPackage/ExtractBAContainerResult.cs | |||
| @@ -0,0 +1,39 @@ | |||
| 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 | |||
| 3 | namespace WixToolset.Core.TestPackage | ||
| 4 | { | ||
| 5 | using System.IO; | ||
| 6 | using System.Xml; | ||
| 7 | using Xunit; | ||
| 8 | |||
| 9 | public class ExtractBAContainerResult | ||
| 10 | { | ||
| 11 | public XmlDocument ManifestDocument { get; set; } | ||
| 12 | public XmlNamespaceManager ManifestNamespaceManager { get; set; } | ||
| 13 | public bool Success { get; set; } | ||
| 14 | |||
| 15 | public ExtractBAContainerResult AssertSuccess() | ||
| 16 | { | ||
| 17 | Assert.True(this.Success); | ||
| 18 | return this; | ||
| 19 | } | ||
| 20 | |||
| 21 | public string GetBAFilePath(string extractedBAContainerFolderPath) | ||
| 22 | { | ||
| 23 | var uxPayloads = this.SelectManifestNodes("/burn:BurnManifest/burn:UX/burn:Payload"); | ||
| 24 | var baPayload = uxPayloads[0]; | ||
| 25 | var relativeBAPath = baPayload.Attributes["FilePath"].Value; | ||
| 26 | return Path.Combine(extractedBAContainerFolderPath, relativeBAPath); | ||
| 27 | } | ||
| 28 | |||
| 29 | /// <summary> | ||
| 30 | /// | ||
| 31 | /// </summary> | ||
| 32 | /// <param name="xpath">elements must have the 'burn' prefix</param> | ||
| 33 | /// <returns></returns> | ||
| 34 | public XmlNodeList SelectManifestNodes(string xpath) | ||
| 35 | { | ||
| 36 | return this.ManifestDocument.SelectNodes(xpath, this.ManifestNamespaceManager); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs b/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs new file mode 100644 index 00000000..a7f04508 --- /dev/null +++ b/src/WixToolset.Core.TestPackage/XmlNodeExtensions.cs | |||
| @@ -0,0 +1,75 @@ | |||
| 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 | |||
| 3 | namespace WixToolset.Core.TestPackage | ||
| 4 | { | ||
| 5 | using System.Collections.Generic; | ||
| 6 | using System.IO; | ||
| 7 | using System.Text.RegularExpressions; | ||
| 8 | using System.Xml; | ||
| 9 | |||
| 10 | public static class XmlNodeExtensions | ||
| 11 | { | ||
| 12 | public static string GetTestXml(this XmlNode node, Dictionary<string, List<string>> ignoredAttributesByElementName = null) | ||
| 13 | { | ||
| 14 | return node.OuterXml.GetTestXml(ignoredAttributesByElementName); | ||
| 15 | } | ||
| 16 | |||
| 17 | public static string GetTestXml(this string xml, Dictionary<string, List<string>> ignoredAttributesByElementName = null) | ||
| 18 | { | ||
| 19 | string formattedXml; | ||
| 20 | using (var sw = new StringWriter()) | ||
| 21 | using (var writer = new TestXmlWriter(sw)) | ||
| 22 | { | ||
| 23 | var doc = new XmlDocument(); | ||
| 24 | doc.LoadXml(xml); | ||
| 25 | |||
| 26 | if (ignoredAttributesByElementName != null) | ||
| 27 | { | ||
| 28 | HandleIgnoredAttributes(doc, ignoredAttributesByElementName); | ||
| 29 | } | ||
| 30 | |||
| 31 | doc.Save(writer); | ||
| 32 | formattedXml = sw.ToString(); | ||
| 33 | } | ||
| 34 | |||
| 35 | return Regex.Replace(formattedXml, " xmlns(:[^=]+)?='[^']*'", ""); | ||
| 36 | } | ||
| 37 | |||
| 38 | private static void HandleIgnoredAttributes(XmlNode node, Dictionary<string, List<string>> ignoredAttributesByElementName) | ||
| 39 | { | ||
| 40 | if (node.Attributes != null && ignoredAttributesByElementName.TryGetValue(node.LocalName, out var ignoredAttributes)) | ||
| 41 | { | ||
| 42 | foreach (var ignoredAttribute in ignoredAttributes) | ||
| 43 | { | ||
| 44 | var attribute = node.Attributes[ignoredAttribute]; | ||
| 45 | if (attribute != null) | ||
| 46 | { | ||
| 47 | attribute.Value = "*"; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | if (node.ChildNodes != null) | ||
| 53 | { | ||
| 54 | foreach (XmlNode childNode in node.ChildNodes) | ||
| 55 | { | ||
| 56 | HandleIgnoredAttributes(childNode, ignoredAttributesByElementName); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | private class TestXmlWriter : XmlTextWriter | ||
| 62 | { | ||
| 63 | public TestXmlWriter(TextWriter w) | ||
| 64 | : base(w) | ||
| 65 | { | ||
| 66 | this.QuoteChar = '\''; | ||
| 67 | } | ||
| 68 | |||
| 69 | public override void WriteStartDocument() | ||
| 70 | { | ||
| 71 | //OmitXmlDeclaration | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
