From 692f9292e733f0d5383f04dc55c78241785f7118 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 8 May 2020 21:55:18 +1000 Subject: Move MsbuildMessageListener into its own file. --- src/WixToolset.BuildTasks/DoIt.cs | 55 ------------------ .../MsbuildMessageListener.cs | 66 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 55 deletions(-) create mode 100644 src/WixToolset.BuildTasks/MsbuildMessageListener.cs (limited to 'src') 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 } } } - - private class MsbuildMessageListener : IMessageListener - { - public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName) - { - this.Logger = logger; - this.ShortAppName = shortName; - this.LongAppName = longName; - } - - public string ShortAppName { get; } - - public string LongAppName { get; } - - private TaskLoggingHelper Logger { get; } - - public void Write(Message message) - { - var code = this.ShortAppName + message.Id.ToString(); - var file = message.SourceLineNumbers?.FileName ?? this.LongAppName; - var lineNumber = message.SourceLineNumbers?.LineNumber ?? 0; - switch (message.Level) - { - case MessageLevel.Error: - this.Logger.LogError(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); - break; - - case MessageLevel.Verbose: - this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Low, message.ResourceNameOrFormat, message.MessageArgs); - break; - - case MessageLevel.Warning: - this.Logger.LogWarning(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); - break; - - default: - if (message.Id > 0) - { - this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); - } - else - { - this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); - } - break; - } - } - - public void Write(string message) - { - this.Logger.LogMessage(MessageImportance.Low, message); - } - - public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; - } } } 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 @@ +// 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.BuildTasks +{ + using System; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + public sealed class MsbuildMessageListener : IMessageListener + { + public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName) + { + this.Logger = logger; + this.ShortAppName = shortName; + this.LongAppName = longName; + } + + public string ShortAppName { get; } + + public string LongAppName { get; } + + private TaskLoggingHelper Logger { get; } + + public void Write(Message message) + { + var code = this.ShortAppName + message.Id.ToString(); + var file = message.SourceLineNumbers?.FileName ?? this.LongAppName; + var lineNumber = message.SourceLineNumbers?.LineNumber ?? 0; + switch (message.Level) + { + case MessageLevel.Error: + this.Logger.LogError(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); + break; + + case MessageLevel.Verbose: + this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Low, message.ResourceNameOrFormat, message.MessageArgs); + break; + + case MessageLevel.Warning: + this.Logger.LogWarning(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); + break; + + default: + if (message.Id > 0) + { + this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); + } + else + { + this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); + } + break; + } + } + + public void Write(string message) + { + this.Logger.LogMessage(MessageImportance.Low, message); + } + + public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; + } +} -- cgit v1.2.3-55-g6feb