summaryrefslogtreecommitdiff
path: root/src/tools/test/WixToolsetTest.Heat/HeatRunner.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/test/WixToolsetTest.Heat/HeatRunner.cs')
-rw-r--r--src/tools/test/WixToolsetTest.Heat/HeatRunner.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/tools/test/WixToolsetTest.Heat/HeatRunner.cs b/src/tools/test/WixToolsetTest.Heat/HeatRunner.cs
new file mode 100644
index 00000000..287698a9
--- /dev/null
+++ b/src/tools/test/WixToolsetTest.Heat/HeatRunner.cs
@@ -0,0 +1,92 @@
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.Harvesters
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using WixToolset.Core;
10 using WixToolset.Core.Burn;
11 using WixToolset.Core.TestPackage;
12 using WixToolset.Data;
13 using WixToolset.Extensibility.Data;
14 using WixToolset.Extensibility.Services;
15 using WixToolset.Harvesters;
16
17 /// <summary>
18 /// Utility class to emulate heat.exe.
19 /// </summary>
20 public static class HeatRunner
21 {
22 /// <summary>
23 /// Emulates calling heat.exe.
24 /// </summary>
25 /// <param name="args"></param>
26 /// <param name="messages"></param>
27 /// <param name="warningsAsErrors"></param>
28 /// <returns></returns>
29 public static int Execute(string[] args, out List<Message> messages, bool warningsAsErrors = true)
30 {
31 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
32 var task = Execute(args, serviceProvider, out messages, warningsAsErrors: warningsAsErrors);
33 return task.Result;
34 }
35
36 /// <summary>
37 /// Emulates calling wix.exe with standard backends.
38 /// This overload always treats warnings as errors.
39 /// </summary>
40 /// <param name="args"></param>
41 /// <returns></returns>
42 public static WixRunnerResult Execute(params string[] args)
43 {
44 return Execute(true, args);
45 }
46
47 /// <summary>
48 /// Emulates calling wix.exe with standard backends.
49 /// </summary>
50 /// <param name="warningsAsErrors"></param>
51 /// <param name="args"></param>
52 /// <returns></returns>
53 public static WixRunnerResult Execute(bool warningsAsErrors, params string[] args)
54 {
55 var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
56 var exitCode = Execute(args, serviceProvider, out var messages, warningsAsErrors: warningsAsErrors);
57 return new WixRunnerResult { ExitCode = exitCode.Result, Messages = messages.ToArray() };
58 }
59
60 /// <summary>
61 /// Emulates calling wix.exe with standard backends.
62 /// </summary>
63 /// <param name="args"></param>
64 /// <param name="coreProvider"></param>
65 /// <param name="messages"></param>
66 /// <param name="warningsAsErrors"></param>
67 /// <returns></returns>
68 public static Task<int> Execute(string[] args, IWixToolsetCoreServiceProvider coreProvider, out List<Message> messages, bool warningsAsErrors = true)
69 {
70 coreProvider.AddBundleBackend();
71
72 var listener = new TestMessageListener();
73
74 messages = listener.Messages;
75
76 var messaging = coreProvider.GetService<IMessaging>();
77 messaging.SetListener(listener);
78
79 if (warningsAsErrors)
80 {
81 messaging.WarningsAsError = true;
82 }
83
84 var arguments = coreProvider.GetService<ICommandLineArguments>();
85 arguments.Populate(args);
86
87 var commandLine = HeatCommandLineFactory.CreateCommandLine(coreProvider);
88 var command = commandLine.ParseStandardCommandLine(arguments);
89 return command?.ExecuteAsync(CancellationToken.None) ?? Task.FromResult(1);
90 }
91 }
92}