예제 #1
0
		// FIXME: I made it private temporarily, later we can change it to internal (but not protected)
		private InternalLoggerException (SerializationInfo info, StreamingContext context)
			: base (info, context)
		{
			buildEventArgs = (BuildEventArgs) info.GetValue ("BuildEventArgs", typeof (BuildEventArgs));
			errorCode = info.GetString ("ErrorCode");
			helpKeyword = info.GetString ("HelpKeywordPrefix");
		}
예제 #2
0
 private void eventSource_AnyEventRaised(object sender, Microsoft.Build.Framework.BuildEventArgs e)
 {
     if (needToLog)
     {
         this.AddNode(e.Message);
     }
 }
예제 #3
0
        /// <summary>
        /// Called to add a logging event to the posting queue.
        /// </summary>
        /// <param name="e"></param>
        internal void PostLoggingEvent(BuildEventArgs e)
        {
            ErrorUtilities.VerifyThrowArgumentNull(e, "e");

            if (paused)
            {
                // Throw out the event
                return;
            }

            if (flushBuildEventsImmediatly)
            {
                ProcessBuildEvent(e);
            }
            else
            {
                // queue the event
                loggingQueueOfBuildEvents.Enqueue(e);

                if (!requestedQueueFlush && loggingQueueOfBuildEvents.WritingQueueCount > flushQueueSize)
                {
                    requestedQueueFlush = true;
                    flushRequestEvent.Set();
                }
            }
        }
            public void HandleBuildEvent(Microsoft.Build.Framework.BuildEventArgs e)
            {
                TaskStartedEventArgs start = e as TaskStartedEventArgs;

                if (start != null && string.Equals(start.TaskName, desc.taskname, StringComparison.OrdinalIgnoreCase))
                {
                    insideTask = true;
                    if (baseFilter == null)
                    {
                        IMSBuildLoggerFilter baseLoggerFilter = (IMSBuildLoggerFilter)desc.addIn.CreateObject(desc.classname);
                        if (baseLoggerFilter != null)
                        {
                            baseFilter = baseLoggerFilter.CreateFilter(context, nextFilter) ?? nextFilter;
                        }
                        else
                        {
                            baseFilter = nextFilter;
                        }
                    }
                }
                if (insideTask)
                {
                    baseFilter.HandleBuildEvent(e);
                }
                else
                {
                    nextFilter.HandleBuildEvent(e);
                }
                if (insideTask && e is TaskFinishedEventArgs)
                {
                    insideTask = false;
                }
            }
예제 #5
0
 public void AnyEventRaisedHandler(object sender, BuildEventArgs e)
 {
     if (!(e is BuildStartedEventArgs) && !(e is BuildFinishedEventArgs))
     {
         ErrorUtilities.VerifyThrowInvalidOperation(false, "Should not recieve any events other than build started or finished");
     }
 }
		internal InternalLoggerException (string message, Exception innerException, BuildEventArgs buildEventArgs, string errorCode, string helpKeyword, bool initializationException)
			: base (message, innerException)
		{
			BuildEventArgs = buildEventArgs;
			ErrorCode = errorCode;
			HelpKeyword = helpKeyword;
			InitializationException = initializationException;
		}
        private object BuildMessage(BuildEventArgs buildEvent)
        {
            var error = buildEvent as BuildErrorEventArgs;
              if (error == null)
            return string.Format("{0}: {1}", buildEvent.SenderName, buildEvent.Message);

              return string.Format("{0}({1}/{2}): error {3}: {4}", error.File, error.LineNumber, error.ColumnNumber, error.Code, error.Message);
        }
예제 #8
0
 public void HandleBuildEvent(Microsoft.Build.Framework.BuildEventArgs e)
 {
     nextFilter.HandleBuildEvent(e);
     if (e is TaskFinishedEventArgs && lastFile != null)
     {
         lastFile.Close();
         lastFile = null;
     }
 }
예제 #9
0
 /// <summary>
 /// This method is called by the node loggers to forward the events to cenral logger
 /// </summary>
 void IEventRedirector.ForwardEvent(BuildEventArgs buildEvent)
 {
     // Don't allow forwarding loggers to forward build started
     ErrorUtilities.VerifyThrowInvalidOperation(!(buildEvent is BuildStartedEventArgs), "DontForwardBuildStarted");
     // Don't allow forwarding loggers to forward build finished
     ErrorUtilities.VerifyThrowInvalidOperation(!(buildEvent is BuildFinishedEventArgs), "DontForwardBuildFinished");
     // Mark the event with the logger id metadata and post it to the queue
     NodeLoggingEventWithLoggerId loggingEvent = new NodeLoggingEventWithLoggerId(buildEvent, loggerId);
     loggingService.PostLoggingEvent(loggingEvent);
 }
예제 #10
0
        protected string GetLogMessage(string eventName, BuildEventArgs e) {
            if (string.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); }

            ////e.SenderName is typically set to MSBuild when called through msbuild.exe
            string eMessage = string.Format("{0}\t{1}\t{2}",
                        eventName,
                        FormatString(e.Message),
                        FormatString(e.HelpKeyword)
                        );
            return eMessage;
        }
예제 #11
0
        /// <summary>
        /// Extension method to help our tests without adding shipping code.
        /// Compare this build event context with another object to determine 
        /// equality. This means the values inside the object are identical.
        /// </summary>
        /// <param name="args">The 'this' object</param>
        /// <param name="other">Object to compare to this object</param>
        /// <returns>True if the object values are identical, false if they are not identical</returns>
        public static bool IsEquivalent(this BuildEventArgs args, BuildEventArgs other)
        {
            if (Object.ReferenceEquals(args, other))
            {
                return true;
            }

            if (Object.ReferenceEquals(other, null) || Object.ReferenceEquals(args, null))
            {
                return false;
            }

            if (args.GetType() != other.GetType())
            {
                return false;
            }

            if (args.Timestamp.Ticks != other.Timestamp.Ticks)
            {
                return false;
            }

            if (args.BuildEventContext != other.BuildEventContext)
            {
                return false;
            }

            if (!String.Equals(args.HelpKeyword, other.HelpKeyword, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            // Just in case we're matching chk against ret or vice versa, make sure the message still registers as the same
            string fixedArgsMessage = args.Message.Replace("\r\nThis is an unhandled exception from a task -- PLEASE OPEN A BUG AGAINST THE TASK OWNER.", String.Empty);
            string fixedOtherMessage = other.Message.Replace("\r\nThis is an unhandled exception from a task -- PLEASE OPEN A BUG AGAINST THE TASK OWNER.", String.Empty);

            if (!String.Equals(fixedArgsMessage, fixedOtherMessage, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            if (!String.Equals(args.SenderName, other.SenderName, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            if (args.ThreadId != other.ThreadId)
            {
                return false;
            }

            return true;
        }
예제 #12
0
 private void WriteLineWithSenderAndMessage(string line, BuildEventArgs e)
 {
     if (0 == String.Compare(e.SenderName, "MSBuild", true /*ignore case*/))
     {
         // Well, if the sender name is MSBuild, let's leave it out for prettiness
         //WriteLine(line, e);
     }
     else
     {
         //   WriteLine(e.SenderName + ": " + line, e);
     }
 }
예제 #13
0
		public void RaiseEvent(BuildEventArgs e)
		{
			if (e is BuildStatusEventArgs) {
				if (e is TaskStartedEventArgs) {
					if (TaskStarted != null)
						TaskStarted(this, (TaskStartedEventArgs)e);
				} else if (e is TaskFinishedEventArgs) {
					if (TaskFinished != null)
						TaskFinished(this, (TaskFinishedEventArgs)e);
				} else if (e is TargetStartedEventArgs) {
					if (TargetStarted != null)
						TargetStarted(this, (TargetStartedEventArgs)e);
				} else if (e is TargetFinishedEventArgs) {
					if (TargetFinished != null)
						TargetFinished(this, (TargetFinishedEventArgs)e);
				} else if (e is ProjectStartedEventArgs) {
					if (ProjectStarted != null)
						ProjectStarted(this, (ProjectStartedEventArgs)e);
				} else if (e is ProjectFinishedEventArgs) {
					if (ProjectFinished != null)
						ProjectFinished(this, (ProjectFinishedEventArgs)e);
				} else if (e is BuildStartedEventArgs) {
					if (BuildStarted != null)
						BuildStarted(this, (BuildStartedEventArgs)e);
				} else if (e is BuildFinishedEventArgs) {
					if (BuildFinished != null)
						BuildFinished(this, (BuildFinishedEventArgs)e);
				}
				if (StatusEventRaised != null)
					StatusEventRaised(this, (BuildStatusEventArgs)e);
			} else if (e is BuildMessageEventArgs) {
				if (MessageRaised != null)
					MessageRaised(this, (BuildMessageEventArgs)e);
			} else if (e is BuildWarningEventArgs) {
				if (WarningRaised != null)
					WarningRaised(this, (BuildWarningEventArgs)e);
			} else if (e is BuildErrorEventArgs) {
				if (ErrorRaised != null)
					ErrorRaised(this, (BuildErrorEventArgs)e);
			} else if (e is CustomBuildEventArgs) {
				if (CustomEventRaised != null)
					CustomEventRaised(this, (CustomBuildEventArgs)e);
			}
			
			if (AnyEventRaised != null)
				AnyEventRaised(this, e);
		}
예제 #14
0
        public BuildEventInfo(M.BuildEventArgs args)
        {
            this.ThreadId    = args.ThreadId.ToString();
            this.Timestamp   = args.Timestamp.ToString();
            this.SenderName  = args.SenderName;
            this.HelpKeyword = args.HelpKeyword;
            this.Message     = args.Message;


            if (args.BuildEventContext != null)
            {
                this.BuildRequestId    = args.BuildEventContext.BuildRequestId.ToString();
                this.NodeId            = args.BuildEventContext.NodeId.ToString();
                this.ProjectContextId  = args.BuildEventContext.ProjectContextId.ToString();
                this.ProjectInstanceId = args.BuildEventContext.ProjectInstanceId.ToString();
                this.SubmissionId      = args.BuildEventContext.SubmissionId.ToString();
                this.TargetId          = args.BuildEventContext.TargetId.ToString();
                this.TaskId            = args.BuildEventContext.TaskId.ToString();
            }
        }
예제 #15
0
        /// <summary>
        /// Creates an instance of this exception using rich error information.
        /// Internal for unit testing
        /// </summary>
        /// <remarks>This is the only usable constructor.</remarks>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        /// <param name="e">Can be null.</param>
        /// <param name="errorCode"></param>
        /// <param name="helpKeyword"></param>
        internal InternalLoggerException
        (
            string message,
            Exception innerException,
            BuildEventArgs e,
            string errorCode,
            string helpKeyword,
            bool initializationException
         )
            : base(message, innerException)
        {
            ErrorUtilities.VerifyThrow((message != null) && (message.Length > 0), "Need error message.");
            ErrorUtilities.VerifyThrow(innerException != null || initializationException == true, "Need the logger exception.");
            ErrorUtilities.VerifyThrow((errorCode != null) && (errorCode.Length > 0), "Must specify the error message code.");
            ErrorUtilities.VerifyThrow((helpKeyword != null) && (helpKeyword.Length > 0), "Must specify the help keyword for the IDE.");

            this.e = e;
            this.errorCode = errorCode;
            this.helpKeyword = helpKeyword;
            this.initializationException = initializationException;
        }
예제 #16
0
        public ErrorItem(int? errorNumber, ErrorLevel errorLevel, BuildEventArgs args)
        {
            _number = errorNumber;
            _level = errorLevel;
            switch (errorLevel)
            {
                case ErrorLevel.Message:
                    Init((BuildMessageEventArgs)args);
                    break;

                case ErrorLevel.Warning:
                    Init((BuildWarningEventArgs)args);
                    break;

                case ErrorLevel.Error:
                    Init((BuildErrorEventArgs)args);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("errorLevel");
            }

            VerifyValues();
        }
예제 #17
0
        /*
         * Method:  LoggerEventHandler
         * Owner:   jomof
         *
         * Recieves build events and logs them the way we like.
         *
         */
        internal void LoggerEventHandler(object sender, BuildEventArgs eventArgs)
        {
            if (eventArgs is BuildWarningEventArgs)
            {
                BuildWarningEventArgs w = (BuildWarningEventArgs) eventArgs;

                // hack: disregard the MTA warning.
                // need the second condition to pass on ploc builds
                if (w.Code != "MSB4056" && !w.Message.Contains("MSB4056"))
                {
                    fullLog.AppendFormat("{0}({1},{2}): {3} warning {4}: {5}\r\n",
                        w.File, 
                        w.LineNumber,
                        w.ColumnNumber,
                        w.Subcategory,
                        w.Code,
                        w.Message);

                    ++warningCount;
                    this.warnings.Add(w);
                }
            }
            else if (eventArgs is BuildErrorEventArgs)
            {
                BuildErrorEventArgs e = (BuildErrorEventArgs) eventArgs;

                fullLog.AppendFormat("{0}({1},{2}): {3} error {4}: {5}\r\n",
                    e.File, 
                    e.LineNumber,
                    e.ColumnNumber,
                    e.Subcategory,
                    e.Code,
                    e.Message);

                ++errorCount;
                this.errors.Add(e);
            }
            else
            {
                fullLog.Append(eventArgs.Message);
                fullLog.Append("\r\n");
            }

            if (eventArgs is ExternalProjectStartedEventArgs)
            {
                this.ExternalProjectStartedEvents.Add((ExternalProjectStartedEventArgs)eventArgs);
            }
            else if (eventArgs is ExternalProjectFinishedEventArgs)
            {
                this.ExternalProjectFinishedEvents.Add((ExternalProjectFinishedEventArgs)eventArgs);
            }

            if (eventArgs is BuildFinishedEventArgs)
            {
                // Console.Write in the context of a unit test is very expensive.  A hundred
                // calls to Console.Write can easily take two seconds on a fast machine.  Therefore, only
                // do the Console.Write once at the end of the build.
                Console.Write(FullLog);
            }
        }
예제 #18
0
 /// <summary>
 /// This is the method that does the main work of logging an event
 /// when one is sent to this logger.
 /// </summary>
 private void LogEvent(object sender, BuildEventArgs buildEvent)
 {
     // Fill in the Message text
     if (OutputWindowPane != null && !String.IsNullOrEmpty(buildEvent.Message))
     {
         StringBuilder msg = new StringBuilder(this.currentIndent + buildEvent.Message.Length + 1);
         if (this.currentIndent > 0)
         {
             msg.Append('\t', this.currentIndent);
         }
         msg.AppendLine(buildEvent.Message);
         this.OutputWindowPane.OutputStringThreadSafe(msg.ToString());
     }
 }
예제 #19
0
        /// <summary>
        /// Add the error/warning to the error list and potentially to the output window.
        /// </summary>
        private void AddToErrorList(
            BuildEventArgs errorEvent,
            string errorCode,
            string file,
            int line,
            int column)
        {
            TaskPriority priority = (errorEvent is BuildErrorEventArgs) ? TaskPriority.High : TaskPriority.Normal;
            if (OutputWindowPane != null
                && (this.Verbosity != LoggerVerbosity.Quiet || errorEvent is BuildErrorEventArgs))
            {
                // Format error and output it to the output window
                string message = this.FormatMessage(errorEvent.Message);
                CompilerError e = new CompilerError(file,
                                                    line,
                                                    column,
                                                    errorCode,
                                                    message);
                e.IsWarning = (errorEvent is BuildWarningEventArgs);

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(OutputWindowPane.OutputStringThreadSafe(GetFormattedErrorMessage(e)));
            }

            // Add error to task list
            ErrorTask task = new ErrorTask();
            task.Document = file;
            task.Line = line - 1; // The task list does +1 before showing this number.
            task.Column = column;
            task.Text = errorEvent.Message;
            task.Priority = priority;
            task.Category = TaskCategory.BuildCompile;
            task.HierarchyItem = hierarchy;
            task.Navigate += new EventHandler(NavigateTo);
            if (errorEvent is BuildWarningEventArgs)
                task.ErrorCategory = TaskErrorCategory.Warning;
            this.taskProvider.Tasks.Add(task);
        }
예제 #20
0
 void eventSource_VerboseEventRaised(object sender, BuildEventArgs e)
 {
     m_task.Log(Level.Verbose, e.Message);
 }
예제 #21
0
        protected void QueueOutputEvent(MessageImportance importance, BuildEventArgs buildEvent)
        {
            // NOTE: This may run on a background thread!
            if (LogAtImportance(importance) && !string.IsNullOrEmpty(buildEvent.Message))
            {
                StringBuilder message = new StringBuilder(this.currentIndent + buildEvent.Message.Length);
                if (this.currentIndent > 0)
                {
                    message.Append('\t', this.currentIndent);
                }
                message.AppendLine(buildEvent.Message);

                QueueOutputText(message.ToString());
            }
        }
예제 #22
0
 public void HandleBuildEvent(Microsoft.Build.Framework.BuildEventArgs e)
 {
     nextChainElement.HandleBuildEvent(e);
 }
 /// <summary>
 /// When a forwarding logger forwards an event we need to check to see
 /// if the event the logger sent us is the same one we sent in.
 /// </summary>
 /// <param name="buildEvent">Build event to forward</param>
 public void ForwardEvent(BuildEventArgs buildEvent)
 {
     Assert.IsTrue(_expectedEvent == buildEvent, "Expected the forwarded event to match the expected event");
 }
예제 #24
0
 /// <summary>
 /// Verify the LoggingMessagePacket is properly created from a build event. 
 /// This includes the packet type and the event type depending on which build event arg is passed in.
 /// </summary>
 /// <param name="buildEvent">Build event to put into a packet, and verify after packet creation</param>
 /// <param name="logEventType">What is the expected logging event type</param>
 private static void VerifyLoggingPacket(BuildEventArgs buildEvent, LoggingEventType logEventType)
 {
     LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(0, buildEvent));
     Assert.Equal(logEventType, packet.EventType);
     Assert.Equal(NodePacketType.LogMessage, packet.Type);
     Assert.True(Object.ReferenceEquals(buildEvent, packet.NodeBuildEvent.Value.Value)); // "Expected buildEvent to have the same object reference as packet.BuildEvent"
 }
 public void HandleBuildEvent(Microsoft.Build.Framework.BuildEventArgs e)
 {
     engine.eventSource.ForwardEvent(e);
 }
예제 #26
0
 private void eventSource_AnyEventRaised(object sender, Microsoft.Build.Framework.BuildEventArgs e)
 {
     textBox.Text += Environment.NewLine + e.ToString();
 }
 /// <summary>
 /// Create a new forwarding logger, event redirector, and event source.
 /// The returned event source can then have and event raised on it and it can 
 /// check to see if the event raised matches the one we were expecting.
 /// </summary>
 /// <param name="buildEventToCheck">A build event we are expecting to be forwarded by the forwarding logger</param>
 /// <returns>An event source on which one can raise an event.</returns>
 private static EventSourceSink AttachForwardingLoggerAndRedirector(BuildEventArgs buildEventToCheck)
 {
     EventSourceSink loggerEventSource = new EventSourceSink();
     CentralForwardingLogger forwardingLogger = new CentralForwardingLogger();
     TestEventRedirector eventRedirector = new TestEventRedirector(buildEventToCheck);
     forwardingLogger.BuildEventRedirector = eventRedirector;
     forwardingLogger.Initialize(loggerEventSource);
     return loggerEventSource;
 }
 /// <summary>
 /// Take in an expected event and when the event is forwarded make sure
 /// the events are the same.
 /// </summary>
 /// <param name="eventToExpect">Event we expect to see in the ForwardEvent method</param>
 public TestEventRedirector(BuildEventArgs eventToExpect)
 {
     _expectedEvent = eventToExpect;
 }
예제 #29
0
		/// <summary>
		/// Add the error/warning to the error list and potentially to the output window.
		/// </summary>
		private void AddToErrorList(
			BuildEventArgs errorEvent,
            string subcategory,
			string errorCode,
			string file,
			int startLine,
			int startColumn,
            int endLine,
            int endColumn)
		{
            if (file == null)
                file = String.Empty;
            
            bool isWarning = errorEvent is BuildWarningEventArgs;
            TaskPriority priority = isWarning ? TaskPriority.Normal : TaskPriority.High;
            
            TextSpan span;
            span.iStartLine = startLine;
            span.iStartIndex = startColumn;
            span.iEndLine = endLine < startLine ? span.iStartLine : endLine;
            span.iEndIndex = (endColumn < startColumn) && (span.iStartLine == span.iEndLine) ? span.iStartIndex : endColumn;

			if (OutputWindowPane != null
				&& (this.Verbosity != LoggerVerbosity.Quiet || errorEvent is BuildErrorEventArgs))
			{
				// Format error and output it to the output window
				string message = this.FormatMessage(errorEvent.Message);
                DefaultCompilerError e = new DefaultCompilerError(file,
                                                span.iStartLine,
                                                span.iStartIndex,
                                                span.iEndLine,
                                                span.iEndIndex,
                                                errorCode,
					                            message);
				e.IsWarning = isWarning;

				Output(GetFormattedErrorMessage(e));
			}

            UIThread.Run(delegate()
            {
                IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDoc == null)
                    return;

                IVsWindowFrame frame;
                IOleServiceProvider sp;
                IVsUIHierarchy hier;
                uint itemid;
                Guid logicalView = VSConstants.LOGVIEWID_Code;

                IVsTextLines buffer = null;
                // JAF 
                // Notes about acquiring the buffer:
                // If the file physically exists then this will open the document in the current project. It doesn't matter if the file is a member of the project.
                // Also, it doesn't matter if this is an F# file. For example, an error in Microsoft.Common.targets will cause a file to be opened here.
                // However, opening the document does not mean it will be shown in VS. 
                if (!Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) && frame != null) {
                    object docData;
                    frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

                    // Get the text lines
                    buffer = docData as IVsTextLines;

                    if (buffer == null) {
                        IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                        if (bufferProvider != null) {
                            bufferProvider.GetTextBuffer(out buffer);
                        }
                    }
                }

                // Need to adjust line and column indexing for the task window, which assumes zero-based values
                if (span.iStartLine > 0 && span.iStartIndex > 0)
                {
                    span.iStartLine -= 1;
                    span.iEndLine -= 1;
                    span.iStartIndex -= 1;
                    span.iEndIndex -= 1;
                }

                // Add new document task to task list
                DocumentTask task = new DocumentTask(serviceProvider,
                    buffer, // May be null
                    // This seems weird. Why would warning status make this a 'compile error'? 
                    // The “code sense” errors produce red squiggles, whereas the “compile” errors produce blue squiggles.  (This is in line with C#’s pre-VS2008-SP1 behavior.)  Swapping these two gives us a look consistent with that of the language service.
                    isWarning ? MARKERTYPE.MARKER_COMPILE_ERROR : MARKERTYPE.MARKER_CODESENSE_ERROR, 
                    span,
                    file,
                    subcategory);

                // Add error to task list
                task.Text = Microsoft.FSharp.Compiler.ErrorLogger.NewlineifyErrorString(errorEvent.Message);
                task.Priority = priority;
                task.ErrorCategory = isWarning ? TaskErrorCategory.Warning : TaskErrorCategory.Error;
                task.Category = TaskCategory.BuildCompile;
                task.HierarchyItem = hierarchy;
                task.Navigate += new EventHandler(NavigateTo);

                if (null != this.TaskReporter)
                {
                    this.taskReporter.AddTask(task);
                }
                else
                {
                    this.taskProvider.Tasks.Add(task);
                }
            });
		}
예제 #30
0
        /// <summary>
        /// Sends the requested packet across to the main node. 
        /// </summary>
        private void SendBuildEvent(BuildEventArgs e)
        {
            if (_nodeEndpoint != null && _nodeEndpoint.LinkStatus == LinkStatus.Active)
            {
                if (!e.GetType().IsSerializable)
                {
                    // log a warning and bail.  This will end up re-calling SendBuildEvent, but we know for a fact
                    // that the warning that we constructed is serializable, so everything should be good.  
                    LogWarningFromResource("ExpectedEventToBeSerializable", e.GetType().Name);
                    return;
                }

                _nodeEndpoint.SendData(new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(_currentConfiguration.NodeId, e)));
            }
        }
예제 #31
0
 /// <summary>
 /// This method is called by the node loggers to forward the events to cenral logger
 /// </summary>
 /// <param name="buildEvent">Build event to forward</param>
 /// <exception cref="InternalErrorException">BuildEvent is null</exception>
 void IEventRedirector.ForwardEvent(BuildEventArgs buildEvent)
 {
     ErrorUtilities.VerifyThrow(buildEvent != null, "buildEvent is null");
     _sink.Consume(buildEvent, _centralLoggerId);
 }
예제 #32
0
        public void TestTranslation()
        {
            TaskItem item = new TaskItem("Hello", "my.proj");
            List<TaskItem> targetOutputs = new List<TaskItem>();
            targetOutputs.Add(item);

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", "1");
            BuildEventArgs[] testArgs = new BuildEventArgs[]
            {
                new BuildFinishedEventArgs("Message", "Keyword", true),
                new BuildStartedEventArgs("Message", "Help"),
                new BuildMessageEventArgs("Message", "help", "sender", MessageImportance.Low),
                new TaskStartedEventArgs("message", "help", "projectFile", "taskFile", "taskName"),
                new TaskFinishedEventArgs("message", "help", "projectFile", "taskFile", "taskName", true),
                new TaskCommandLineEventArgs("commandLine", "taskName", MessageImportance.Low),
                new BuildWarningEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new BuildErrorEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"),
                new TargetStartedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile"),
                new TargetFinishedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile", true, targetOutputs),
                new ProjectStartedEventArgs(-1, "message", "help", "ProjectFile", "targetNames", null, null, null),
                new ProjectFinishedEventArgs("message", "help", "ProjectFile", true),
                new ExternalProjectStartedEventArgs("message", "help", "senderName", "projectFile", "targetNames")
            };

            foreach (BuildEventArgs arg in testArgs)
            {
                LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(0, arg));

                ((INodePacketTranslatable)packet).Translate(TranslationHelpers.GetWriteTranslator());
                INodePacket tempPacket = LogMessagePacket.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()) as LogMessagePacket;

                LogMessagePacket deserializedPacket = tempPacket as LogMessagePacket;

                CompareLogMessagePackets(packet, deserializedPacket);
            }

            Environment.SetEnvironmentVariable("MSBUILDTARGETOUTPUTLOGGING", null);
        }
예제 #33
0
 /// <summary>
 /// Write the specified text and the message in the <see cref="BuildEventArgs"/> to the 
 /// output window, adding the sender name.
 /// </summary>
 private void WriteLineWithSenderAndMessage(string text, BuildEventArgs eventArgs)
 {
     if (String.Compare(eventArgs.SenderName, "MSBuild", StringComparison.OrdinalIgnoreCase) == 0)
     {
         // The sender is MSBuild.
         WriteLine(text, eventArgs);
     }
     else
     {
         text = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", eventArgs.SenderName, text);
         WriteLine(text, eventArgs);
     }
 }
예제 #34
0
		/// <summary>
		/// This is the method that does the main work of logging an event
		/// when one is sent to this logger.
		/// </summary>
		private void LogEvent(object sender, BuildEventArgs buildEvent)
		{
            try
            {
                // Fill in the Message text
                if (OutputWindowPane != null && !String.IsNullOrEmpty(buildEvent.Message))
                {
                    int startingSize = this.currentIndent + buildEvent.Message.Length + 1;
                    StringBuilder msg = new StringBuilder(startingSize);
                    if (this.currentIndent > 0)
                    {
                        msg.Append('\t', this.currentIndent);
                    }
                    msg.AppendLine(buildEvent.Message);
                    Output(msg.ToString());
                }
            }
            catch (Exception e)
            {
                try
                {
                    System.Diagnostics.Debug.Assert(false, "Error thrown from IDEBuildLogger::LogEvent");
                    System.Diagnostics.Debug.Assert(false, e.ToString());
                    // For retail, also try to show in the output window.
                    Output(e.ToString());
                }
                catch 
                { 
                    // We're going to throw the original exception anyway
                }
                throw;
            }
		}
예제 #35
0
 /// <summary>
 /// Log if we have received any event.
 /// </summary>
 internal void EventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
     if (e.Message != null)
     {
         Console.Out.WriteLine("AnyEvent:" + e.Message.ToString());
     }
 }
예제 #36
0
            /// <summary>
            /// Log the event
            /// </summary>
            internal void LoggerEventHandler(object sender, BuildEventArgs eventArgs)
            {
                if (eventArgs is BuildStartedEventArgs)
                {
                    ++BuildStartedCount;
                }

                if (eventArgs is BuildFinishedEventArgs)
                {
                    ++BuildFinishedCount;
                }
            }
예제 #37
0
        /*
         * Method:  LoggerEventHandler
         *
         * Receives build events and logs them the way we like.
         *
         */
        internal void LoggerEventHandler(object sender, BuildEventArgs eventArgs)
        {
            if (eventArgs is BuildWarningEventArgs)
            {
                BuildWarningEventArgs w = (BuildWarningEventArgs)eventArgs;

                // hack: disregard the MTA warning.
                // need the second condition to pass on ploc builds
                if (w.Code != "MSB4056" && !w.Message.Contains("MSB4056"))
                {
                    _fullLog.AppendFormat("{0}({1},{2}): {3} warning {4}: {5}\r\n",
                        w.File,
                        w.LineNumber,
                        w.ColumnNumber,
                        w.Subcategory,
                        w.Code,
                        w.Message);

                    ++_warningCount;
                    _warnings.Add(w);
                }
            }
            else if (eventArgs is BuildErrorEventArgs)
            {
                BuildErrorEventArgs e = (BuildErrorEventArgs)eventArgs;

                _fullLog.AppendFormat("{0}({1},{2}): {3} error {4}: {5}\r\n",
                    e.File,
                    e.LineNumber,
                    e.ColumnNumber,
                    e.Subcategory,
                    e.Code,
                    e.Message);

                ++_errorCount;
                _errors.Add(e);
            }
            else
            {
                // Log the message unless we are a build finished event and logBuildFinished is set to false.
                bool logMessage = !(eventArgs is BuildFinishedEventArgs) || (eventArgs is BuildFinishedEventArgs && _logBuildFinishedEvent);
                if (logMessage)
                {
                    _fullLog.Append(eventArgs.Message);
                    _fullLog.Append("\r\n");
                }
            }

            if (eventArgs is ExternalProjectStartedEventArgs)
            {
                this.ExternalProjectStartedEvents.Add((ExternalProjectStartedEventArgs)eventArgs);
            }
            else if (eventArgs is ExternalProjectFinishedEventArgs)
            {
                this.ExternalProjectFinishedEvents.Add((ExternalProjectFinishedEventArgs)eventArgs);
            }

            if (eventArgs is ProjectStartedEventArgs)
            {
                this.ProjectStartedEvents.Add((ProjectStartedEventArgs)eventArgs);
            }
            else if (eventArgs is ProjectFinishedEventArgs)
            {
                this.ProjectFinishedEvents.Add((ProjectFinishedEventArgs)eventArgs);
            }
            else if (eventArgs is TargetStartedEventArgs)
            {
                this.TargetStartedEvents.Add((TargetStartedEventArgs)eventArgs);
            }
            else if (eventArgs is TargetFinishedEventArgs)
            {
                this.TargetFinishedEvents.Add((TargetFinishedEventArgs)eventArgs);
            }
            else if (eventArgs is TaskStartedEventArgs)
            {
                this.TaskStartedEvents.Add((TaskStartedEventArgs)eventArgs);
            }
            else if (eventArgs is TaskFinishedEventArgs)
            {
                this.TaskFinishedEvents.Add((TaskFinishedEventArgs)eventArgs);
            }
            else if (eventArgs is BuildMessageEventArgs)
            {
                this.BuildMessageEvents.Add((BuildMessageEventArgs)eventArgs);
            }
            else if (eventArgs is BuildStartedEventArgs)
            {
                this.BuildStartedEvents.Add((BuildStartedEventArgs)eventArgs);
            }
            else if (eventArgs is BuildFinishedEventArgs)
            {
                this.BuildFinishedEvents.Add((BuildFinishedEventArgs)eventArgs);

                if (!AllowTaskCrashes)
                {
                    // We should not have any task crashes. Sometimes a test will validate that their expected error
                    // code appeared, but not realize it then crashed.
                    AssertLogDoesntContain("MSB4018");
                }

                // We should not have any Engine crashes.
                AssertLogDoesntContain("MSB0001");

                // Console.Write in the context of a unit test is very expensive.  A hundred
                // calls to Console.Write can easily take two seconds on a fast machine.  Therefore, only
                // do the Console.Write once at the end of the build.
                Console.Write(FullLog);
            }
        }
예제 #38
0
        protected void QueueTaskEvent(BuildEventArgs errorEvent)
        {
            this.taskQueue.Enqueue(() =>
            {
                ErrorTask task = new ErrorTask();

                if (errorEvent is BuildErrorEventArgs)
                {
                    BuildErrorEventArgs errorArgs = (BuildErrorEventArgs)errorEvent;
                    task.Document = errorArgs.File;
                    task.ErrorCategory = TaskErrorCategory.Error;
                    task.Line = errorArgs.LineNumber - 1; // The task list does +1 before showing this number.
                    task.Column = errorArgs.ColumnNumber;
                    task.Priority = TaskPriority.High;
                }
                else if (errorEvent is BuildWarningEventArgs)
                {
                    BuildWarningEventArgs warningArgs = (BuildWarningEventArgs)errorEvent;
                    task.Document = warningArgs.File;
                    task.ErrorCategory = TaskErrorCategory.Warning;
                    task.Line = warningArgs.LineNumber - 1; // The task list does +1 before showing this number.
                    task.Column = warningArgs.ColumnNumber;
                    task.Priority = TaskPriority.Normal;
                }
				else if (errorEvent is BuildMessageEventArgs)
				{
					BuildMessageEventArgs messageArgs = (BuildMessageEventArgs)errorEvent;
					task.ErrorCategory = TaskErrorCategory.Message;
					task.Priority = TaskPriority.Normal;
				}

                task.Text = errorEvent.Message;
                task.Category = TaskCategory.BuildCompile;
                task.HierarchyItem = hierarchy;

                return task;
            });

            // NOTE: Unlike output we dont want to interactively report the tasks. So we never queue
            // call ReportQueuedTasks here. We do this when the build finishes.
        }
예제 #39
0
 void eventSource_InfoEventRaised(object sender, BuildEventArgs e)
 {
     m_task.Log(Level.Info, e.Message);
 }