diff options
Diffstat (limited to 'src/WixToolset.BuildTasks/ToolsetTask.cs')
-rw-r--r-- | src/WixToolset.BuildTasks/ToolsetTask.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/WixToolset.BuildTasks/ToolsetTask.cs b/src/WixToolset.BuildTasks/ToolsetTask.cs new file mode 100644 index 00000000..713a938b --- /dev/null +++ b/src/WixToolset.BuildTasks/ToolsetTask.cs | |||
@@ -0,0 +1,105 @@ | |||
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.BuildTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Runtime.InteropServices; | ||
7 | using Microsoft.Build.Utilities; | ||
8 | using WixToolset.Core; | ||
9 | using WixToolset.Data; | ||
10 | using WixToolset.Extensibility; | ||
11 | using WixToolset.Extensibility.Services; | ||
12 | |||
13 | public abstract class ToolsetTask : Task | ||
14 | { | ||
15 | /// <summary> | ||
16 | /// Gets or sets additional options that are appended the the tool command-line. | ||
17 | /// </summary> | ||
18 | /// <remarks> | ||
19 | /// This allows the task to support extended options in the tool which are not | ||
20 | /// explicitly implemented as properties on the task. | ||
21 | /// </remarks> | ||
22 | public string AdditionalOptions { get; set; } | ||
23 | |||
24 | /// <summary> | ||
25 | /// Gets or sets whether to display the logo. | ||
26 | /// </summary> | ||
27 | public bool NoLogo { get; set; } | ||
28 | |||
29 | /// <summary> | ||
30 | /// Gets or sets whether all warnings should be suppressed. | ||
31 | /// </summary> | ||
32 | public bool SuppressAllWarnings { get; set; } | ||
33 | |||
34 | /// <summary> | ||
35 | /// Gets or sets a list of specific warnings to be suppressed. | ||
36 | /// </summary> | ||
37 | public string[] SuppressSpecificWarnings { get; set; } | ||
38 | |||
39 | /// <summary> | ||
40 | /// Gets or sets whether all warnings should be treated as errors. | ||
41 | /// </summary> | ||
42 | public bool TreatWarningsAsErrors { get; set; } | ||
43 | |||
44 | /// <summary> | ||
45 | /// Gets or sets a list of specific warnings to treat as errors. | ||
46 | /// </summary> | ||
47 | public string[] TreatSpecificWarningsAsErrors { get; set; } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Gets or sets whether to display verbose output. | ||
51 | /// </summary> | ||
52 | public bool VerboseOutput { get; set; } | ||
53 | |||
54 | public override bool Execute() | ||
55 | { | ||
56 | var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); | ||
57 | |||
58 | var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode); | ||
59 | |||
60 | try | ||
61 | { | ||
62 | var commandLineBuilder = new WixCommandLineBuilder(); | ||
63 | this.BuildCommandLine(commandLineBuilder); | ||
64 | |||
65 | var commandLineString = commandLineBuilder.ToString(); | ||
66 | this.ExecuteCore(serviceProvider, listener, commandLineString); | ||
67 | } | ||
68 | catch (WixException e) | ||
69 | { | ||
70 | listener.Write(e.Error); | ||
71 | } | ||
72 | catch (Exception e) | ||
73 | { | ||
74 | this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null); | ||
75 | |||
76 | if (e is NullReferenceException || e is SEHException) | ||
77 | { | ||
78 | throw; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return !this.Log.HasLoggedErrors; | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// Builds a command line from options in this and derivative tasks. | ||
87 | /// </summary> | ||
88 | /// <remarks> | ||
89 | /// Derivative classes should call BuildCommandLine() on the base class to ensure that common command line options are added to the command. | ||
90 | /// </remarks> | ||
91 | protected virtual void BuildCommandLine(WixCommandLineBuilder commandLineBuilder) | ||
92 | { | ||
93 | commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo); | ||
94 | commandLineBuilder.AppendArrayIfNotNull("-sw ", this.SuppressSpecificWarnings); | ||
95 | commandLineBuilder.AppendIfTrue("-sw", this.SuppressAllWarnings); | ||
96 | commandLineBuilder.AppendIfTrue("-v", this.VerboseOutput); | ||
97 | commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); | ||
98 | commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); | ||
99 | } | ||
100 | |||
101 | protected abstract void ExecuteCore(IWixToolsetServiceProvider serviceProvider, IMessageListener messageListener, string commandLineString); | ||
102 | |||
103 | protected abstract string TaskShortName { get; } | ||
104 | } | ||
105 | } | ||