public void LogMessageConstructorNullBuildEvent()
 {
     Assert.Throws<InternalErrorException>(() =>
     {
         LogMessagePacket packet = new LogMessagePacket(null);
     }
    );
 }
Beispiel #2
0
        private void HandleLoggedMessage(LogMessagePacket logMessagePacket)
        {
            switch (logMessagePacket.EventType)
            {
            case LoggingEventType.BuildErrorEvent:
                this.BuildEngine.LogErrorEvent((BuildErrorEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                break;

            case LoggingEventType.BuildWarningEvent:
                this.BuildEngine.LogWarningEvent((BuildWarningEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                break;

            case LoggingEventType.TaskCommandLineEvent:
            case LoggingEventType.BuildMessageEvent:
                this.BuildEngine.LogMessageEvent((BuildMessageEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                break;

            case LoggingEventType.CustomEvent:
                BuildEventArgs buildEvent = logMessagePacket.NodeBuildEvent.Value.Value;

                // "Custom events" in terms of the communications infrastructure can also be, e.g. custom error events,
                // in which case they need to be dealt with in the same way as their base type of event.
                if (buildEvent is BuildErrorEventArgs buildErrorEventArgs)
                {
                    this.BuildEngine.LogErrorEvent(buildErrorEventArgs);
                }
                else if (buildEvent is BuildWarningEventArgs buildWarningEventArgs)
                {
                    this.BuildEngine.LogWarningEvent(buildWarningEventArgs);
                }
                else if (buildEvent is BuildMessageEventArgs buildMessageEventArgs)
                {
                    this.BuildEngine.LogMessageEvent(buildMessageEventArgs);
                }
                else if (buildEvent is CustomBuildEventArgs customBuildEventArgs)
                {
                    this.BuildEngine.LogCustomEvent(customBuildEventArgs);
                }
                else
                {
                    ErrorUtilities.ThrowInternalError("Unknown event args type.");
                }

                break;
            }
        }
        public void LoggingPacketReceived()
        {
            LoggingServicesLogMethod_Tests.ProcessBuildEventHelper loggingService = (LoggingServicesLogMethod_Tests.ProcessBuildEventHelper)LoggingServicesLogMethod_Tests.ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            BuildMessageEventArgs messageEvent = new BuildMessageEventArgs("MyMessage", "HelpKeyword", "Sender", MessageImportance.High);
            LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(1, messageEvent));
            loggingService.PacketReceived(1, packet);

            BuildMessageEventArgs messageEventFromPacket = loggingService.ProcessedBuildEvent as BuildMessageEventArgs;
            Assert.NotNull(messageEventFromPacket);
            Assert.Equal(messageEventFromPacket, messageEvent); // "Expected messages to match"
        }
        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);
        }
        /// <summary>
        /// Compares two LogMessagePacket objects for equivalence.
        /// </summary>
        private void CompareLogMessagePackets(LogMessagePacket left, LogMessagePacket right)
        {
            Assert.Equal(left.EventType, right.EventType);
            Assert.Equal(left.NodeBuildEvent.Value.Value.GetType(), right.NodeBuildEvent.Value.Value.GetType());

            CompareNodeBuildEventArgs(left.NodeBuildEvent.Value, right.NodeBuildEvent.Value, left.EventType == LoggingEventType.CustomEvent /* expectInvalidBuildEventContext */);

            switch (left.EventType)
            {
                case LoggingEventType.BuildErrorEvent:
                    BuildErrorEventArgs leftError = left.NodeBuildEvent.Value.Value as BuildErrorEventArgs;
                    BuildErrorEventArgs rightError = right.NodeBuildEvent.Value.Value as BuildErrorEventArgs;
                    Assert.NotNull(leftError);
                    Assert.NotNull(rightError);
                    Assert.Equal(leftError.Code, rightError.Code);
                    Assert.Equal(leftError.ColumnNumber, rightError.ColumnNumber);
                    Assert.Equal(leftError.EndColumnNumber, rightError.EndColumnNumber);
                    Assert.Equal(leftError.EndLineNumber, rightError.EndLineNumber);
                    Assert.Equal(leftError.File, rightError.File);
                    Assert.Equal(leftError.LineNumber, rightError.LineNumber);
                    Assert.Equal(leftError.Message, rightError.Message);
                    Assert.Equal(leftError.Subcategory, rightError.Subcategory);
                    break;

                case LoggingEventType.BuildFinishedEvent:
                    BuildFinishedEventArgs leftFinished = left.NodeBuildEvent.Value.Value as BuildFinishedEventArgs;
                    BuildFinishedEventArgs rightFinished = right.NodeBuildEvent.Value.Value as BuildFinishedEventArgs;
                    Assert.NotNull(leftFinished);
                    Assert.NotNull(rightFinished);
                    Assert.Equal(leftFinished.Succeeded, rightFinished.Succeeded);
                    break;

                case LoggingEventType.BuildMessageEvent:
                    BuildMessageEventArgs leftMessage = left.NodeBuildEvent.Value.Value as BuildMessageEventArgs;
                    BuildMessageEventArgs rightMessage = right.NodeBuildEvent.Value.Value as BuildMessageEventArgs;
                    Assert.NotNull(leftMessage);
                    Assert.NotNull(rightMessage);
                    Assert.Equal(leftMessage.Importance, rightMessage.Importance);
                    break;

                case LoggingEventType.BuildStartedEvent:
                    BuildStartedEventArgs leftBuildStart = left.NodeBuildEvent.Value.Value as BuildStartedEventArgs;
                    BuildStartedEventArgs rightBuildStart = right.NodeBuildEvent.Value.Value as BuildStartedEventArgs;
                    Assert.NotNull(leftBuildStart);
                    Assert.NotNull(rightBuildStart);
                    break;

                case LoggingEventType.BuildWarningEvent:
                    BuildWarningEventArgs leftBuildWarn = left.NodeBuildEvent.Value.Value as BuildWarningEventArgs;
                    BuildWarningEventArgs rightBuildWarn = right.NodeBuildEvent.Value.Value as BuildWarningEventArgs;
                    Assert.NotNull(leftBuildWarn);
                    Assert.NotNull(rightBuildWarn);
                    Assert.Equal(leftBuildWarn.Code, rightBuildWarn.Code);
                    Assert.Equal(leftBuildWarn.ColumnNumber, rightBuildWarn.ColumnNumber);
                    Assert.Equal(leftBuildWarn.EndColumnNumber, rightBuildWarn.EndColumnNumber);
                    Assert.Equal(leftBuildWarn.EndLineNumber, rightBuildWarn.EndLineNumber);
                    Assert.Equal(leftBuildWarn.File, rightBuildWarn.File);
                    Assert.Equal(leftBuildWarn.LineNumber, rightBuildWarn.LineNumber);
                    Assert.Equal(leftBuildWarn.Subcategory, rightBuildWarn.Subcategory);
                    break;

                case LoggingEventType.CustomEvent:
                    ExternalProjectStartedEventArgs leftCustom = left.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs;
                    ExternalProjectStartedEventArgs rightCustom = right.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs;
                    Assert.NotNull(leftCustom);
                    Assert.NotNull(rightCustom);
                    Assert.Equal(leftCustom.ProjectFile, rightCustom.ProjectFile);
                    Assert.Equal(leftCustom.TargetNames, rightCustom.TargetNames);
                    break;

                case LoggingEventType.ProjectFinishedEvent:
                    ProjectFinishedEventArgs leftProjectFinished = left.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs;
                    ProjectFinishedEventArgs rightProjectFinished = right.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs;
                    Assert.NotNull(leftProjectFinished);
                    Assert.NotNull(rightProjectFinished);
                    Assert.Equal(leftProjectFinished.ProjectFile, rightProjectFinished.ProjectFile);
                    Assert.Equal(leftProjectFinished.Succeeded, rightProjectFinished.Succeeded);
                    break;

                case LoggingEventType.ProjectStartedEvent:
                    ProjectStartedEventArgs leftProjectStarted = left.NodeBuildEvent.Value.Value as ProjectStartedEventArgs;
                    ProjectStartedEventArgs rightProjectStarted = right.NodeBuildEvent.Value.Value as ProjectStartedEventArgs;
                    Assert.NotNull(leftProjectStarted);
                    Assert.NotNull(rightProjectStarted);
                    Assert.Equal(leftProjectStarted.ParentProjectBuildEventContext, rightProjectStarted.ParentProjectBuildEventContext);
                    Assert.Equal(leftProjectStarted.ProjectFile, rightProjectStarted.ProjectFile);
                    Assert.Equal(leftProjectStarted.ProjectId, rightProjectStarted.ProjectId);
                    Assert.Equal(leftProjectStarted.TargetNames, rightProjectStarted.TargetNames);

                    // UNDONE: (Serialization.) We don't actually serialize the items at this time.
                    // Assert.AreEqual(leftProjectStarted.Items, rightProjectStarted.Items);
                    // UNDONE: (Serialization.) We don't actually serialize properties at this time.
                    // Assert.AreEqual(leftProjectStarted.Properties, rightProjectStarted.Properties);
                    break;

                case LoggingEventType.TargetFinishedEvent:
                    TargetFinishedEventArgs leftTargetFinished = left.NodeBuildEvent.Value.Value as TargetFinishedEventArgs;
                    TargetFinishedEventArgs rightTargetFinished = right.NodeBuildEvent.Value.Value as TargetFinishedEventArgs;
                    Assert.NotNull(leftTargetFinished);
                    Assert.NotNull(rightTargetFinished);
                    Assert.Equal(leftTargetFinished.ProjectFile, rightTargetFinished.ProjectFile);
                    Assert.Equal(leftTargetFinished.Succeeded, rightTargetFinished.Succeeded);
                    Assert.Equal(leftTargetFinished.TargetFile, rightTargetFinished.TargetFile);
                    Assert.Equal(leftTargetFinished.TargetName, rightTargetFinished.TargetName);
                    break;

                case LoggingEventType.TargetStartedEvent:
                    TargetStartedEventArgs leftTargetStarted = left.NodeBuildEvent.Value.Value as TargetStartedEventArgs;
                    TargetStartedEventArgs rightTargetStarted = right.NodeBuildEvent.Value.Value as TargetStartedEventArgs;
                    Assert.NotNull(leftTargetStarted);
                    Assert.NotNull(rightTargetStarted);
                    Assert.Equal(leftTargetStarted.ProjectFile, rightTargetStarted.ProjectFile);
                    Assert.Equal(leftTargetStarted.TargetFile, rightTargetStarted.TargetFile);
                    Assert.Equal(leftTargetStarted.TargetName, rightTargetStarted.TargetName);
                    break;

                case LoggingEventType.TaskCommandLineEvent:
                    TaskCommandLineEventArgs leftCommand = left.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs;
                    TaskCommandLineEventArgs rightCommand = right.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs;
                    Assert.NotNull(leftCommand);
                    Assert.NotNull(rightCommand);
                    Assert.Equal(leftCommand.CommandLine, rightCommand.CommandLine);
                    Assert.Equal(leftCommand.Importance, rightCommand.Importance);
                    Assert.Equal(leftCommand.TaskName, rightCommand.TaskName);
                    break;

                case LoggingEventType.TaskFinishedEvent:
                    TaskFinishedEventArgs leftTaskFinished = left.NodeBuildEvent.Value.Value as TaskFinishedEventArgs;
                    TaskFinishedEventArgs rightTaskFinished = right.NodeBuildEvent.Value.Value as TaskFinishedEventArgs;
                    Assert.NotNull(leftTaskFinished);
                    Assert.NotNull(rightTaskFinished);
                    Assert.Equal(leftTaskFinished.ProjectFile, rightTaskFinished.ProjectFile);
                    Assert.Equal(leftTaskFinished.Succeeded, rightTaskFinished.Succeeded);
                    Assert.Equal(leftTaskFinished.TaskFile, rightTaskFinished.TaskFile);
                    Assert.Equal(leftTaskFinished.TaskName, rightTaskFinished.TaskName);
                    break;

                case LoggingEventType.TaskStartedEvent:
                    TaskStartedEventArgs leftTaskStarted = left.NodeBuildEvent.Value.Value as TaskStartedEventArgs;
                    TaskStartedEventArgs rightTaskStarted = right.NodeBuildEvent.Value.Value as TaskStartedEventArgs;
                    Assert.NotNull(leftTaskStarted);
                    Assert.NotNull(rightTaskStarted);
                    Assert.Equal(leftTaskStarted.ProjectFile, rightTaskStarted.ProjectFile);
                    Assert.Equal(leftTaskStarted.TaskFile, rightTaskStarted.TaskFile);
                    Assert.Equal(leftTaskStarted.TaskName, rightTaskStarted.TaskName);
                    break;

                default:
                    Assert.True(false, string.Format("Unexpected logging event type {0}", left.EventType));
                    break;
            }
        }
 /// <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 LogMessageConstructorNullBuildEvent()
 {
     LogMessagePacket packet = new LogMessagePacket(null);
 }
Beispiel #8
0
 /// <summary>
 /// Adds data to the EventArgs of the log packet that the main node is aware of, but doesn't
 /// get serialized for perf reasons.
 /// </summary>
 internal void InjectNonSerializedData(LogMessagePacket loggingPacket)
 {
     if (loggingPacket != null && loggingPacket.NodeBuildEvent != null && _componentHost != null)
     {
         var projectStartedEventArgs = loggingPacket.NodeBuildEvent.Value.Value as ProjectStartedEventArgs;
         if (projectStartedEventArgs != null && _configCache.Value != null)
         {
             ErrorUtilities.VerifyThrow(_configCache.Value.HasConfiguration(projectStartedEventArgs.ProjectId), "Cannot find the project configuration while injecting non-serialized data from out-of-proc node.");
             BuildRequestConfiguration buildRequestConfiguration = _configCache.Value[projectStartedEventArgs.ProjectId];
             s_projectStartedEventArgsGlobalProperties.Value.SetValue(projectStartedEventArgs, buildRequestConfiguration.Properties.ToDictionary(), null);
             s_projectStartedEventArgsToolsVersion.Value.SetValue(projectStartedEventArgs, buildRequestConfiguration.ToolsVersion, null);
         }
     }
 }
Beispiel #9
0
        /// <summary>
        /// Handle logged messages from the task host.
        /// </summary>
        private void HandleLoggedMessage(LogMessagePacket logMessagePacket)
        {
            switch (logMessagePacket.EventType)
            {
                case LoggingEventType.BuildErrorEvent:
                    this.BuildEngine.LogErrorEvent((BuildErrorEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                    break;
                case LoggingEventType.BuildWarningEvent:
                    this.BuildEngine.LogWarningEvent((BuildWarningEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                    break;
                case LoggingEventType.TaskCommandLineEvent:
                case LoggingEventType.BuildMessageEvent:
                    this.BuildEngine.LogMessageEvent((BuildMessageEventArgs)logMessagePacket.NodeBuildEvent.Value.Value);
                    break;
                case LoggingEventType.CustomEvent:
                    BuildEventArgs buildEvent = logMessagePacket.NodeBuildEvent.Value.Value;

                    // "Custom events" in terms of the communications infrastructure can also be, e.g. custom error events, 
                    // in which case they need to be dealt with in the same way as their base type of event. 
                    if (buildEvent is BuildErrorEventArgs)
                    {
                        this.BuildEngine.LogErrorEvent((BuildErrorEventArgs)buildEvent);
                    }
                    else if (buildEvent is BuildWarningEventArgs)
                    {
                        this.BuildEngine.LogWarningEvent((BuildWarningEventArgs)buildEvent);
                    }
                    else if (buildEvent is BuildMessageEventArgs)
                    {
                        this.BuildEngine.LogMessageEvent((BuildMessageEventArgs)buildEvent);
                    }
                    else if (buildEvent is CustomBuildEventArgs)
                    {
                        this.BuildEngine.LogCustomEvent((CustomBuildEventArgs)buildEvent);
                    }
                    else
                    {
                        ErrorUtilities.ThrowInternalError("Unknown event args type.");
                    }

                    break;
            }
        }
        /// <summary>
        /// Consumes the buildEventArg and creates a logMessagePacket
        /// </summary>
        /// <param name="buildEvent">Build event to package into a INodePacket</param>
        /// <exception cref="InternalErrorException">buildEvent is null</exception>
        public void Consume(BuildEventArgs buildEvent, int sinkId)
        {
            ErrorUtilities.VerifyThrow(buildEvent != null, "buildEvent is null");
            if (buildEvent is BuildStartedEventArgs)
            {
                HaveLoggedBuildStartedEvent = true;
                return;
            }
            else if (buildEvent is BuildFinishedEventArgs)
            {
                HaveLoggedBuildFinishedEvent = true;
                return;
            }

            LogMessagePacket logPacket = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(sinkId, buildEvent));
            _sendDataDelegate(logPacket);
        }