示例#1
0
        public void Handle(CustomBuildEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (_context.Parameters.ShowOnlyErrors || _context.Parameters.ShowOnlyWarnings)
            {
                return;
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }

            if (!_context.IsVerbosityAtLeast(LoggerVerbosity.Detailed) || e.Message == null)
            {
                return;
            }

            _deferredMessageWriter.DisplayDeferredStartedEvents(e.BuildEventContext);
            _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
            _messageWriter.WriteMessageAligned(e.Message, true);
            _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
        }
示例#2
0
        public void Handle(TaskStartedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }
            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Detailed))
            {
                _deferredMessageWriter.DisplayDeferredStartedEvents(e.BuildEventContext);
                if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                {
                    var prefixAlreadyWritten = _messageWriter.WriteTargetMessagePrefix(e, e.BuildEventContext, e.Timestamp);
                    _logWriter.SetColor(Color.Task);
                    if (_context.IsVerbosityAtLeast(LoggerVerbosity.Diagnostic) || (_context.Parameters.ShowEventId ?? false))
                    {
                        _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TaskMessageWithId", (object)e.Message, (object)e.BuildEventContext.TaskId), prefixAlreadyWritten);
                    }
                    else
                    {
                        _messageWriter.WriteMessageAligned(e.Message, prefixAlreadyWritten);
                    }

                    _logWriter.ResetColor();
                }

                _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
            }

            if (!_context.Parameters.ShowPerfSummary)
            {
                return;
            }

            _performanceCounterFactory.GetOrCreatePerformanceCounter(e.TaskName, _context.TaskPerformanceCounters).AddEventStarted(null, e.BuildEventContext, e.Timestamp, null);
        }
示例#3
0
        public void PrintMessage(BuildMessageEventArgs e, bool lightenText)
        {
            var message          = e.File == null ? (e.Message ?? string.Empty) : _eventFormatter.FormatEventMessage(e, false, _context.Parameters.ShowProjectFile);
            var prefixAdjustment = 0;

            if (e.BuildEventContext.TaskId != -1 && e.File == null)
            {
                prefixAdjustment = 2;
            }

            if (lightenText)
            {
                _logWriter.SetColor(Color.Details);
            }

            PrintTargetNamePerMessage(e, lightenText);
            if ((_context.IsVerbosityAtLeast(LoggerVerbosity.Diagnostic) || (_context.Parameters.ShowEventId ?? false)) && e.BuildEventContext.TaskId != -1)
            {
                var prefixAlreadyWritten = WriteTargetMessagePrefix(e, e.BuildEventContext, e.Timestamp);
                WriteMessageAligned(_stringService.FormatResourceString("TaskMessageWithId", message, e.BuildEventContext.TaskId), prefixAlreadyWritten, prefixAdjustment);
            }
            else if (_context.Parameters.ShowTimeStamp || _context.IsVerbosityAtLeast(LoggerVerbosity.Detailed))
            {
                var prefixAlreadyWritten = WriteTargetMessagePrefix(e, e.BuildEventContext, e.Timestamp);
                WriteMessageAligned(message, prefixAlreadyWritten, prefixAdjustment);
            }
            else
            {
                WriteMessageAligned(message, false, prefixAdjustment);
            }

            if (!lightenText)
            {
                return;
            }

            _logWriter.ResetColor();
        }
示例#4
0
        public void Handle(BuildStartedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            _context.BuildStarted    = e.Timestamp;
            _context.HasBuildStarted = true;
            if (_context.Parameters.ShowOnlyErrors || _context.Parameters.ShowOnlyWarnings)
            {
                return;
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
            {
                _messageWriter.WriteLinePrettyFromResource("BuildStartedWithTime", e.Timestamp);
            }

            WriteEnvironment(e.BuildEnvironment);
        }
示例#5
0
        public void Handle(BuildErrorEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }

            _context.ErrorCount = _context.ErrorCount + 1;
            _buildEventManager.SetErrorWarningFlagOnCallStack(e.BuildEventContext);
            var targetStartedEvent = _buildEventManager.GetTargetStartedEvent(e.BuildEventContext);

            if (targetStartedEvent != null)
            {
                targetStartedEvent.ErrorInTarget = true;
            }

            _deferredMessageWriter.DisplayDeferredStartedEvents(e.BuildEventContext);
            if (_context.Parameters.ShowOnlyWarnings && !_context.Parameters.ShowOnlyErrors)
            {
                return;
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
            {
                _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
            }

            _logWriter.SetColor(Color.Error);
            _messageWriter.WriteMessageAligned(_eventFormatter.FormatEventMessage(e, false, _context.Parameters.ShowProjectFile), true);
            _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
            if (_context.ErrorList != null && (_context.Parameters.ShowSummary ?? false) && !_context.ErrorList.Contains(e))
            {
                _context.ErrorList.Add(e);
            }

            _logWriter.ResetColor();
        }
 public void Handle(TargetStartedEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (e.BuildEventContext == null)
     {
         throw new ArgumentException(nameof(e));
     }
     _buildEventManager.AddTargetStartedEvent(e, _context.Parameters.ShowTimeStamp || _context.IsVerbosityAtLeast(LoggerVerbosity.Detailed));
     if (_context.Parameters.ShowPerfSummary)
     {
         _performanceCounterFactory.GetOrCreatePerformanceCounter(e.TargetName, _context.TargetPerformanceCounters).AddEventStarted(null, e.BuildEventContext, e.Timestamp, ComparerContextNodeIdTargetId.Shared);
     }
 }
示例#7
0
        public void DisplayDeferredTargetStartedEvent(BuildEventContext e)
        {
            if (_context.Parameters.ShowOnlyErrors || _context.Parameters.ShowOnlyWarnings)
            {
                return;
            }

            var targetStartedEvent = _buildEventManager.GetTargetStartedEvent(e);

            if (targetStartedEvent == null || targetStartedEvent.ShowTargetFinishedEvent)
            {
                return;
            }

            targetStartedEvent.ShowTargetFinishedEvent = true;
            DisplayDeferredStartedEvents(targetStartedEvent.TargetBuildEventContext);
            var projectStartedEvent = _buildEventManager.GetProjectStartedEvent(e);

            if (projectStartedEvent == null)
            {
                throw new InvalidOperationException("Project Started should not be null in deferred target started");
            }

            var    projectFile = projectStartedEvent.ProjectFile ?? string.Empty;
            string targetName;
            var    shortTargetName = $"Target \"{targetStartedEvent.TargetName}\"";

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Diagnostic) || (_context.Parameters.ShowEventId ?? false))
            {
                targetName = _stringService.FormatResourceString("TargetMessageWithId", targetStartedEvent.TargetName, targetStartedEvent.TargetBuildEventContext.TargetId);
            }
            else
            {
                targetName = targetStartedEvent.TargetName;
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Detailed))
            {
                if (string.Equals(projectFile, targetStartedEvent.TargetFile, StringComparison.OrdinalIgnoreCase))
                {
                    if (!string.IsNullOrEmpty(targetStartedEvent.ParentTarget))
                    {
                        _hierarchicalMessageWriter.StartBlock(shortTargetName);

                        _messageWriter.WriteLinePrefix(targetStartedEvent.TargetBuildEventContext, targetStartedEvent.TimeStamp, false);
                        _logWriter.SetColor(Color.BuildStage);
                        _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetStartedProjectDepends", targetName, projectFile, targetStartedEvent.ParentTarget), true);
                    }
                    else
                    {
                        _hierarchicalMessageWriter.StartBlock(shortTargetName);

                        _messageWriter.WriteLinePrefix(targetStartedEvent.TargetBuildEventContext, targetStartedEvent.TimeStamp, false);
                        _logWriter.SetColor(Color.BuildStage);
                        _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetStartedProjectEntry", targetName, projectFile), true);
                    }
                }
                else
                if (!string.IsNullOrEmpty(targetStartedEvent.ParentTarget))
                {
                    _hierarchicalMessageWriter.StartBlock(shortTargetName);

                    _messageWriter.WriteLinePrefix(targetStartedEvent.TargetBuildEventContext, targetStartedEvent.TimeStamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetStartedFileProjectDepends", targetName, targetStartedEvent.TargetFile, projectFile, targetStartedEvent.ParentTarget), true);
                }
                else
                {
                    _hierarchicalMessageWriter.StartBlock(shortTargetName);

                    _messageWriter.WriteLinePrefix(targetStartedEvent.TargetBuildEventContext, targetStartedEvent.TimeStamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetStartedFileProjectEntry", targetName, targetStartedEvent.TargetFile, projectFile), true);
                }
            }
            else
            {
                _hierarchicalMessageWriter.StartBlock(shortTargetName);

                _messageWriter.WriteLinePrefix(targetStartedEvent.TargetBuildEventContext, targetStartedEvent.TimeStamp, false);
                _logWriter.SetColor(Color.BuildStage);
                _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetStartedFileProjectEntry", targetName, targetStartedEvent.TargetFile, projectFile), true);
            }

            _logWriter.ResetColor();
            ShownBuildEventContext(e);
        }
示例#8
0
        public void Handle(BuildFinishedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            _statistics.Publish();

            if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings && _context.DeferredMessages.Count > 0 && _context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
            {
                _messageWriter.WriteLinePrettyFromResource("DeferredMessages");
                foreach (var message in _context.DeferredMessages.Values.SelectMany(i => i))
                {
                    _messageWriter.PrintMessage(message, false);
                }
            }

            if (_context.Parameters.ShowPerfSummary)
            {
                ShowPerfSummary();
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal) || (_context.Parameters.ShowSummary ?? false))
            {
                if (e.Succeeded)
                {
                    _logWriter.SetColor(Color.Success);
                }
                else
                {
                    if (_context.ErrorCount > 0)
                    {
                        _logWriter.SetColor(Color.Error);
                    }
                    else
                    {
                        _logWriter.SetColor(Color.Warning);
                    }
                }

                _messageWriter.WriteNewLine();
                _messageWriter.WriteLinePretty(e.Message);
                _logWriter.ResetColor();
            }

            if (_context.Parameters.ShowSummary ?? false)
            {
                if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
                {
                    ShowNestedErrorWarningSummary();
                }
                else
                {
                    ShowFlatErrorWarningSummary();
                }

                if (_context.WarningCount > 0)
                {
                    _logWriter.SetColor(Color.Warning);
                }

                _messageWriter.WriteLinePrettyFromResource(2, "WarningCount", _context.WarningCount);

                _logWriter.ResetColor();
                if (_context.ErrorCount > 0)
                {
                    _logWriter.SetColor(Color.Error);
                }

                _messageWriter.WriteLinePrettyFromResource(2, "ErrorCount", _context.ErrorCount);
                _logWriter.ResetColor();
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal) || (_context.Parameters.ShowSummary ?? false))
            {
                var str = _logFormatter.FormatTimeSpan(e.Timestamp - _context.BuildStarted);
                _messageWriter.WriteNewLine();
                _messageWriter.WriteLinePrettyFromResource("TimeElapsed", str);
            }

            _context.ResetConsoleLoggerState();
        }
        public void Handle(ProjectFinishedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            var projectStartedEvent = _buildEventManager.GetProjectStartedEvent(e.BuildEventContext);

            // ReSharper disable once LocalizableElement
            if (projectStartedEvent == null)
            {
                throw new ArgumentException($"Project finished event for {e.ProjectFile} received without matching start event", nameof(e));
            }
            if (_context.Parameters.ShowPerfSummary)
            {
                _performanceCounterFactory.GetOrCreatePerformanceCounter(e.ProjectFile, _context.ProjectPerformanceCounters).AddEventFinished(projectStartedEvent.TargetNames, e.BuildEventContext, e.Timestamp);
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Normal) && projectStartedEvent.ShowProjectFinishedEvent)
            {
                _context.LastProjectFullKey = _context.GetFullProjectKey(e.BuildEventContext);
                if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                {
                    _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
                    _logWriter.SetColor(Color.BuildStage);
                    var targetNames = projectStartedEvent.TargetNames;
                    var projectFile = projectStartedEvent.ProjectFile ?? string.Empty;
                    if (string.IsNullOrEmpty(targetNames))
                    {
                        if (e.Succeeded)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithDefaultTargetsMultiProc", projectFile), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithDefaultTargetsMultiProcFailed", projectFile), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                    }
                    else
                    {
                        if (e.Succeeded)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithTargetNamesMultiProc", projectFile, targetNames), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("ProjectFinishedPrefixWithTargetNamesMultiProcFailed", projectFile, targetNames), true);
                            _hierarchicalMessageWriter.FinishBlock();
                        }
                    }
                }

                _deferredMessageWriter.ShownBuildEventContext(projectStartedEvent.ProjectBuildEventContext);
                _logWriter.ResetColor();
            }

            _buildEventManager.RemoveProjectStartedEvent(e.BuildEventContext);
        }
示例#10
0
        public void Handle(ProjectStartedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }

            _buildEventManager.AddProjectStartedEvent(e, _context.Parameters.ShowTimeStamp || _context.IsVerbosityAtLeast(LoggerVerbosity.Detailed));
            if (_context.Parameters.ShowPerfSummary)
            {
                _performanceCounterFactory.GetOrCreatePerformanceCounter(e.ProjectFile, _context.ProjectPerformanceCounters).AddEventStarted(e.TargetNames, e.BuildEventContext, e.Timestamp, ComparerContextNodeId.Shared);
            }

            if (_context.DeferredMessages.TryGetValue(e.BuildEventContext, out IList <BuildMessageEventArgs> messages))
            {
                if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                {
                    foreach (var message in messages)
                    {
                        _messageHandler.Handle(message);
                    }
                }

                _context.DeferredMessages.Remove(e.BuildEventContext);
            }

            if (_context.Verbosity != LoggerVerbosity.Diagnostic || !_context.Parameters.ShowItemAndPropertyList)
            {
                return;
            }

            if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
            {
                _deferredMessageWriter.DisplayDeferredProjectStartedEvent(e.BuildEventContext);
            }

            if (e.Properties != null)
            {
                WriteProperties(e, e.Properties.Cast <DictionaryEntry>().Select(i => new Property((string)i.Key, (string)i.Value)).ToList());
            }

            if (e.Items != null)
            {
                WriteItems(e, e.Items.Cast <DictionaryEntry>().Select(i => new TaskItem((string)i.Key, (ITaskItem)i.Value)).ToList());
            }
        }
示例#11
0
        public void Handle(BuildMessageEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (_context.Parameters.ShowOnlyErrors || _context.Parameters.ShowOnlyWarnings)
            {
                return;
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }
            bool showMessages;
            var  lightenText = false;

            if (e is TaskCommandLineEventArgs)
            {
                if (_context.Parameters.ShowCommandLine.HasValue && !_context.Parameters.ShowCommandLine.Value || !_context.Parameters.ShowCommandLine.HasValue && !_context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
                {
                    return;
                }

                showMessages = true;
            }
            else
            {
                switch (e.Importance)
                {
                case MessageImportance.High:
                    showMessages = _context.IsVerbosityAtLeast(LoggerVerbosity.Minimal);
                    break;

                case MessageImportance.Normal:
                    showMessages = _context.IsVerbosityAtLeast(LoggerVerbosity.Normal);
                    lightenText  = true;
                    break;

                case MessageImportance.Low:
                    showMessages = _context.IsVerbosityAtLeast(LoggerVerbosity.Detailed);
                    lightenText  = true;
                    break;

                default:
                    throw new InvalidOperationException("Impossible");
                }
            }

            if (!showMessages)
            {
                return;
            }

            if (_context.HasBuildStarted && e.BuildEventContext.ProjectContextId != -2 && _buildEventManager.GetProjectStartedEvent(e.BuildEventContext) == null && _context.IsVerbosityAtLeast(LoggerVerbosity.Normal))
            {
                if (!_context.DeferredMessages.TryGetValue(e.BuildEventContext, out var messageEventArgsList))
                {
                    messageEventArgsList = new List <BuildMessageEventArgs>();
                    _context.DeferredMessages.Add(e.BuildEventContext, messageEventArgsList);
                }

                messageEventArgsList.Add(e);
            }
            else
            {
                _deferredMessageWriter.DisplayDeferredStartedEvents(e.BuildEventContext);
                _messageWriter.PrintMessage(e, lightenText);
                _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
            }
        }
        public void Handle(TargetFinishedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.BuildEventContext == null)
            {
                throw new ArgumentException(nameof(e));
            }
            if (_context.Parameters.ShowPerfSummary)
            {
                _performanceCounterFactory.GetOrCreatePerformanceCounter(e.TargetName, _context.TargetPerformanceCounters).AddEventFinished(null, e.BuildEventContext, e.Timestamp);
            }

            if (_context.IsVerbosityAtLeast(LoggerVerbosity.Detailed))
            {
                _deferredMessageWriter.DisplayDeferredTargetStartedEvent(e.BuildEventContext);
                var targetStartedEvent = _buildEventManager.GetTargetStartedEvent(e.BuildEventContext);
                // ReSharper disable once NotResolvedInText
                if (targetStartedEvent == null)
                {
                    throw new ArgumentNullException("Started event should not be null in the finished event handler");
                }
                if (targetStartedEvent.ShowTargetFinishedEvent)
                {
                    if (_context.Parameters.ShowTargetOutputs)
                    {
                        var targetOutputs = e.TargetOutputs;
                        if (targetOutputs != null)
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetOutputItemsHeader"), false);
                            foreach (ITaskItem taskItem in targetOutputs)
                            {
                                _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetOutputItem", taskItem.ItemSpec), false);
                                foreach (DictionaryEntry dictionaryEntry in taskItem.CloneCustomMetadata())
                                {
                                    _messageWriter.WriteMessageAligned(new string(' ', 8) + dictionaryEntry.Key + " = " + taskItem.GetMetadata((string)dictionaryEntry.Key), false);
                                }
                            }
                        }
                    }

                    if (!_context.Parameters.ShowOnlyErrors && !_context.Parameters.ShowOnlyWarnings)
                    {
                        _context.LastProjectFullKey = _context.GetFullProjectKey(e.BuildEventContext);
                        _messageWriter.WriteLinePrefix(e.BuildEventContext, e.Timestamp, false);
                        _logWriter.SetColor(Color.BuildStage);
                        if (_context.IsVerbosityAtLeast(LoggerVerbosity.Diagnostic) || (_context.Parameters.ShowEventId ?? false))
                        {
                            _messageWriter.WriteMessageAligned(_stringService.FormatResourceString("TargetMessageWithId", (object)e.Message, (object)e.BuildEventContext.TargetId), true);
                        }
                        else
                        {
                            _messageWriter.WriteMessageAligned(e.Message, true);
                        }

                        _logWriter.ResetColor();
                    }

                    _deferredMessageWriter.ShownBuildEventContext(e.BuildEventContext);
                    _hierarchicalMessageWriter.FinishBlock();
                }
            }

            _buildEventManager.RemoveTargetStartedEvent(e.BuildEventContext);
        }