using Microsoft.Build.Framework; using Microsoft.Build.Utilities; namespace Xamarin.MacDev.Tasks { public static class LoggingExtensions { const MessageImportance TaskPropertyImportance = MessageImportance.Normal; internal static readonly string ErrorPrefix; static LoggingExtensions () { var name = typeof (LoggingExtensions).Assembly.GetName (); switch (name.Name) { case "Xamarin.Mac.Tasks": ErrorPrefix = "MM"; break; default: ErrorPrefix = "MT"; break; } } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, ITaskItem[] items) { if (items == null) { log.LogMessage (TaskPropertyImportance, " {0}: ", propertyName); return; } log.LogMessage (TaskPropertyImportance, " {0}:", propertyName); for (int i = 0; i < items.Length; i++) log.LogMessage (TaskPropertyImportance, " {0}", items[i].ItemSpec); } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, ITaskItem item) { if (item != null) log.LogMessage (TaskPropertyImportance, " {0}: {1}", propertyName, item.ItemSpec); else log.LogMessage (TaskPropertyImportance, " {0}: ", propertyName); } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, string[] items) { if (items == null) { log.LogMessage (TaskPropertyImportance, " {0}: ", propertyName); return; } log.LogMessage (TaskPropertyImportance, " {0}:", propertyName); for (int i = 0; i < items.Length; i++) log.LogMessage (TaskPropertyImportance, " {0}", items[i]); } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, string value) { log.LogMessage (TaskPropertyImportance, " {0}: {1}", propertyName, value ?? ""); } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, bool value) { log.LogMessage (TaskPropertyImportance, " {0}: {1}", propertyName, value); } public static void LogTaskProperty (this TaskLoggingHelper log, string propertyName, int value) { log.LogMessage (TaskPropertyImportance, " {0}: {1}", propertyName, value); } /// /// Creates an MSBuild error following our MTErrors convention. /// /// For every new error we need to update "docs/website/mtouch-errors.md" and "tools/mtouch/error.cs". /// In the 7xxx range for MSBuild error. /// The error's message to be displayed in the error pad. /// Path to the known guilty file or null. public static void LogError (this TaskLoggingHelper log, int errorCode, string fileName, string message, params object[] args) { log.LogError (null, $"{ErrorPrefix}{errorCode}", null, fileName ?? "MSBuild", 0, 0, 0, 0, message, args); } public static void LogWarning (this TaskLoggingHelper log, int errorCode, string fileName, string message, params object[] args) { log.LogWarning (null, $"{ErrorPrefix}{errorCode}", null, fileName ?? "MSBuild", 0, 0, 0, 0, message, args); } } }