From d085e938317c80f62a3b484d20ed1a6cf89bb59d Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Mon, 21 Dec 2020 05:05:45 -0600 Subject: Add CanExtractBundleWithDetachedContainer test. --- src/WixToolset.Core.Burn/BundleBackend.cs | 3 +- src/WixToolset.Core.TestPackage/BundleExtractor.cs | 17 +++++++ src/WixToolset.Core.TestPackage/WixRunnerResult.cs | 12 ++++- src/WixToolset.Core.WindowsInstaller/Unbinder.cs | 10 +++- .../WixToolsetCoreServiceProviderExtensions.cs | 1 + src/WixToolset.Core/Compiler_Bundle.cs | 12 ++++- src/WixToolset.Core/IUnbinder.cs | 12 +++++ .../BundleExtractionFixture.cs | 57 ++++++++++++++++++++++ .../BundleWithDetachedContainer/Bundle.wxs | 10 ++++ .../WixToolsetTest.CoreIntegration.csproj | 1 + 10 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 src/WixToolset.Core/IUnbinder.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs (limited to 'src') diff --git a/src/WixToolset.Core.Burn/BundleBackend.cs b/src/WixToolset.Core.Burn/BundleBackend.cs index 4a2f44b1..081e4464 100644 --- a/src/WixToolset.Core.Burn/BundleBackend.cs +++ b/src/WixToolset.Core.Burn/BundleBackend.cs @@ -62,8 +62,9 @@ namespace WixToolset.Core.Burn { var uxExtractPath = Path.Combine(context.ExportBasePath, "UX"); var acExtractPath = Path.Combine(context.ExportBasePath, "AttachedContainer"); + var messaging = context.ServiceProvider.GetService(); - using (var reader = BurnReader.Open(context.InputFilePath)) + using (var reader = BurnReader.Open(messaging, context.InputFilePath)) { reader.ExtractUXContainer(uxExtractPath, context.IntermediateFolder); reader.ExtractAttachedContainer(acExtractPath, context.IntermediateFolder); diff --git a/src/WixToolset.Core.TestPackage/BundleExtractor.cs b/src/WixToolset.Core.TestPackage/BundleExtractor.cs index ad97f113..8c9f31e6 100644 --- a/src/WixToolset.Core.TestPackage/BundleExtractor.cs +++ b/src/WixToolset.Core.TestPackage/BundleExtractor.cs @@ -44,6 +44,23 @@ namespace WixToolset.Core.TestPackage return result; } + /// + /// Extracts the attached container. + /// + /// + /// Path to the bundle. + /// Path to extract to. + /// Temp path for extraction. + /// True if there was an attached container. + public static bool ExtractAttachedContainer(IMessaging messaging, string bundleFilePath, string destinationFolderPath, string tempFolderPath) + { + Directory.CreateDirectory(tempFolderPath); + using (var burnReader = BurnReader.Open(messaging, bundleFilePath)) + { + return burnReader.ExtractAttachedContainer(destinationFolderPath, tempFolderPath); + } + } + /// /// Gets an for BootstrapperApplicationData.xml with the given prefix assigned to the root namespace. /// diff --git a/src/WixToolset.Core.TestPackage/WixRunnerResult.cs b/src/WixToolset.Core.TestPackage/WixRunnerResult.cs index 13e3a9e0..6a3d714c 100644 --- a/src/WixToolset.Core.TestPackage/WixRunnerResult.cs +++ b/src/WixToolset.Core.TestPackage/WixRunnerResult.cs @@ -28,10 +28,20 @@ namespace WixToolset.Core.TestPackage /// public WixRunnerResult AssertSuccess() { - Assert.True(0 == this.ExitCode, $"\r\n\r\nWixRunner failed with exit code: {this.ExitCode}\r\n Output: {String.Join("\r\n ", FormatMessages(this.Messages))}\r\n"); + AssertSuccess(this.ExitCode, this.Messages); return this; } + /// + /// + /// + /// + /// + public static void AssertSuccess(int exitCode, IEnumerable messages) + { + Assert.True(0 == exitCode, $"\r\n\r\nWixRunner failed with exit code: {exitCode}\r\n Output: {String.Join("\r\n ", FormatMessages(messages))}\r\n"); + } + private static IEnumerable FormatMessages(IEnumerable messages) { foreach (var message in messages) diff --git a/src/WixToolset.Core.WindowsInstaller/Unbinder.cs b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs index a2f02269..99caaba9 100644 --- a/src/WixToolset.Core.WindowsInstaller/Unbinder.cs +++ b/src/WixToolset.Core.WindowsInstaller/Unbinder.cs @@ -11,8 +11,16 @@ namespace WixToolset.Core /// /// Unbinder core of the WiX toolset. /// - internal sealed class Unbinder + internal sealed class Unbinder : IUnbinder { + public Unbinder(IWixToolsetServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + + var extensionManager = this.ServiceProvider.GetService(); + this.BackendFactories = extensionManager.GetServices(); + } + public IEnumerable BackendFactories { get; } /// diff --git a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs index c69f1af1..e013cefb 100644 --- a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs +++ b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs @@ -31,6 +31,7 @@ namespace WixToolset.Core.WindowsInstaller { // Singletons. coreProvider.AddService((provider, singletons) => AddSingleton(singletons, new WindowsInstallerBackendHelper())); + coreProvider.AddService((provider, singletons) => new Unbinder(provider)); } private static T AddSingleton(Dictionary singletons, T service) where T : class diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index 86fec16e..b8386138 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs @@ -566,9 +566,17 @@ namespace WixToolset.Core break; case "Type": var typeString = this.Core.GetAttributeValue(sourceLineNumbers, attrib); - if (!Enum.TryParse(typeString, out type)) + switch (typeString) { - this.Core.Write(ErrorMessages.IllegalAttributeValueWithLegalList(sourceLineNumbers, node.Name.LocalName, "Type", typeString, "attached, detached")); + case "attached": + type = ContainerType.Attached; + break; + case "detached": + type = ContainerType.Detached; + break; + default: + this.Core.Write(ErrorMessages.IllegalAttributeValueWithLegalList(sourceLineNumbers, node.Name.LocalName, "Type", typeString, "attached, detached")); + break; } break; default: diff --git a/src/WixToolset.Core/IUnbinder.cs b/src/WixToolset.Core/IUnbinder.cs new file mode 100644 index 00000000..2b4daaa5 --- /dev/null +++ b/src/WixToolset.Core/IUnbinder.cs @@ -0,0 +1,12 @@ +// 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. + +namespace WixToolset.Core +{ + using WixToolset.Data; + +#pragma warning disable 1591 // TODO: add documentation, move into Extensibility + public interface IUnbinder + { + Intermediate Unbind(string file, OutputType outputType, string exportBasePath); + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs new file mode 100644 index 00000000..5c37c25b --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/BundleExtractionFixture.cs @@ -0,0 +1,57 @@ +// 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. + +namespace WixToolsetTest.CoreIntegration +{ + using System.IO; + using System.Linq; + using WixBuildTools.TestSupport; + using WixToolset.Core; + using WixToolset.Core.TestPackage; + using WixToolset.Data; + using Xunit; + + public class BundleExtractionFixture + { + [Fact] + public void CanExtractBundleWithDetachedContainer() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + var baFolderPath = Path.Combine(extractFolderPath, "UX"); + var attachedContainerFolderPath = Path.Combine(extractFolderPath, "AttachedContainer"); + + // TODO: use WixRunner.Execute(string[]) to always go through the command line. + var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithDetachedContainer", "Bundle.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }, serviceProvider, out var messages).Result; + + WixRunnerResult.AssertSuccess(result, messages); + Assert.Empty(messages.Where(m => m.Level == MessageLevel.Warning)); + + Assert.True(File.Exists(exePath)); + + var unbinder = serviceProvider.GetService(); + unbinder.Unbind(exePath, OutputType.Bundle, extractFolderPath); + + Assert.True(File.Exists(Path.Combine(baFolderPath, "manifest.xml"))); + Assert.False(Directory.Exists(attachedContainerFolderPath)); + } + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs new file mode 100644 index 00000000..a93b23ef --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithDetachedContainer/Bundle.wxs @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index a38e89ce..918635e9 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj @@ -32,6 +32,7 @@ + -- cgit v1.2.3-55-g6feb