// 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.Harvesters { using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using WixToolset.Core; using WixToolset.Core.Burn; using WixToolset.Core.TestPackage; using WixToolset.Data; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; using WixToolset.Harvesters; /// /// Utility class to emulate heat.exe. /// public static class HeatRunner { /// /// Emulates calling heat.exe. /// /// /// /// /// public static int Execute(string[] args, out List messages, bool warningsAsErrors = true) { var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); var task = Execute(args, serviceProvider, out messages, warningsAsErrors: warningsAsErrors); return task.Result; } /// /// Emulates calling wix.exe with standard backends. /// This overload always treats warnings as errors. /// /// /// public static WixRunnerResult Execute(params string[] args) { return Execute(true, args); } /// /// Emulates calling wix.exe with standard backends. /// /// /// /// public static WixRunnerResult Execute(bool warningsAsErrors, params string[] args) { var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); var exitCode = Execute(args, serviceProvider, out var messages, warningsAsErrors: warningsAsErrors); return new WixRunnerResult { ExitCode = exitCode.Result, Messages = messages.ToArray() }; } /// /// Emulates calling wix.exe with standard backends. /// /// /// /// /// /// public static Task Execute(string[] args, IWixToolsetCoreServiceProvider coreProvider, out List messages, bool warningsAsErrors = true) { coreProvider.AddBundleBackend(); var listener = new TestMessageListener(); messages = listener.Messages; var messaging = coreProvider.GetService(); messaging.SetListener(listener); if (warningsAsErrors) { messaging.WarningsAsError = true; } var arguments = coreProvider.GetService(); arguments.Populate(args); var commandLine = HeatCommandLineFactory.CreateCommandLine(coreProvider); var command = commandLine.ParseStandardCommandLine(arguments); return command?.ExecuteAsync(CancellationToken.None) ?? Task.FromResult(1); } } }