aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-05-08 21:55:18 +1000
committerSean Hall <r.sean.hall@gmail.com>2020-05-08 22:11:35 +1000
commit692f9292e733f0d5383f04dc55c78241785f7118 (patch)
tree258a108be06ed751cd4974d703b363025c54fa6a
parentd840580127d99bf817332711f8a9c833f395d387 (diff)
downloadwix-692f9292e733f0d5383f04dc55c78241785f7118.tar.gz
wix-692f9292e733f0d5383f04dc55c78241785f7118.tar.bz2
wix-692f9292e733f0d5383f04dc55c78241785f7118.zip
Move MsbuildMessageListener into its own file.
-rw-r--r--src/WixToolset.BuildTasks/DoIt.cs55
-rw-r--r--src/WixToolset.BuildTasks/MsbuildMessageListener.cs66
2 files changed, 66 insertions, 55 deletions
diff --git a/src/WixToolset.BuildTasks/DoIt.cs b/src/WixToolset.BuildTasks/DoIt.cs
index 757c5313..1872f9e4 100644
--- a/src/WixToolset.BuildTasks/DoIt.cs
+++ b/src/WixToolset.BuildTasks/DoIt.cs
@@ -235,60 +235,5 @@ namespace WixToolset.BuildTasks
235 } 235 }
236 } 236 }
237 } 237 }
238
239 private class MsbuildMessageListener : IMessageListener
240 {
241 public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName)
242 {
243 this.Logger = logger;
244 this.ShortAppName = shortName;
245 this.LongAppName = longName;
246 }
247
248 public string ShortAppName { get; }
249
250 public string LongAppName { get; }
251
252 private TaskLoggingHelper Logger { get; }
253
254 public void Write(Message message)
255 {
256 var code = this.ShortAppName + message.Id.ToString();
257 var file = message.SourceLineNumbers?.FileName ?? this.LongAppName;
258 var lineNumber = message.SourceLineNumbers?.LineNumber ?? 0;
259 switch (message.Level)
260 {
261 case MessageLevel.Error:
262 this.Logger.LogError(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
263 break;
264
265 case MessageLevel.Verbose:
266 this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Low, message.ResourceNameOrFormat, message.MessageArgs);
267 break;
268
269 case MessageLevel.Warning:
270 this.Logger.LogWarning(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
271 break;
272
273 default:
274 if (message.Id > 0)
275 {
276 this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs);
277 }
278 else
279 {
280 this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs);
281 }
282 break;
283 }
284 }
285
286 public void Write(string message)
287 {
288 this.Logger.LogMessage(MessageImportance.Low, message);
289 }
290
291 public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel;
292 }
293 } 238 }
294} 239}
diff --git a/src/WixToolset.BuildTasks/MsbuildMessageListener.cs b/src/WixToolset.BuildTasks/MsbuildMessageListener.cs
new file mode 100644
index 00000000..47399a41
--- /dev/null
+++ b/src/WixToolset.BuildTasks/MsbuildMessageListener.cs
@@ -0,0 +1,66 @@
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 WixToolset.BuildTasks
4{
5 using System;
6 using Microsoft.Build.Framework;
7 using Microsoft.Build.Utilities;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10 using WixToolset.Extensibility.Services;
11
12 public sealed class MsbuildMessageListener : IMessageListener
13 {
14 public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName)
15 {
16 this.Logger = logger;
17 this.ShortAppName = shortName;
18 this.LongAppName = longName;
19 }
20
21 public string ShortAppName { get; }
22
23 public string LongAppName { get; }
24
25 private TaskLoggingHelper Logger { get; }
26
27 public void Write(Message message)
28 {
29 var code = this.ShortAppName + message.Id.ToString();
30 var file = message.SourceLineNumbers?.FileName ?? this.LongAppName;
31 var lineNumber = message.SourceLineNumbers?.LineNumber ?? 0;
32 switch (message.Level)
33 {
34 case MessageLevel.Error:
35 this.Logger.LogError(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
36 break;
37
38 case MessageLevel.Verbose:
39 this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Low, message.ResourceNameOrFormat, message.MessageArgs);
40 break;
41
42 case MessageLevel.Warning:
43 this.Logger.LogWarning(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs);
44 break;
45
46 default:
47 if (message.Id > 0)
48 {
49 this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs);
50 }
51 else
52 {
53 this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs);
54 }
55 break;
56 }
57 }
58
59 public void Write(string message)
60 {
61 this.Logger.LogMessage(MessageImportance.Low, message);
62 }
63
64 public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel;
65 }
66}