Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added task assembly location to TaskStartedEventArgs #9948

Merged
merged 20 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.Build.BackEnd;
using Microsoft.Build.BackEnd.Logging;
Expand Down Expand Up @@ -1089,7 +1090,7 @@ public void TaskStartedNullBuildEventContext()
Assert.Throws<InternalErrorException>(() =>
{
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogTaskStarted(null, "MyTask", "ProjectFile", "ProjectFileOfTask");
service.LogTaskStarted(null, "MyTask", "ProjectFile", "ProjectFileOfTask", null);
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down Expand Up @@ -1443,14 +1444,15 @@ private void TestProjectFinishedEvent(string projectFile, bool success)
private void TestTaskStartedEvent(string taskName, string projectFile, string projectFileOfTask)
{
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskStarted", taskName);
string taskAssemblyName = Assembly.GetExecutingAssembly().GetName().FullName;

ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask);
VerifyTaskStartedEvent(taskName, projectFile, projectFileOfTask, message, service);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask, taskAssemblyName);
VerifyTaskStartedEvent(taskName, projectFile, projectFileOfTask, message, service, taskAssemblyName);

service.ResetProcessedBuildEvent();
service.OnlyLogCriticalEvents = true;
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask, taskAssemblyName);
Assert.Null(service.ProcessedBuildEvent);
}

Expand Down Expand Up @@ -1631,15 +1633,16 @@ private void VerifyTaskFinishedEvent(string taskName, string projectFile, string
/// <param name="projectFileOfTask">ProjectFileOfTask to create the comparison event with.</param>
/// <param name="message">Message to create the comparison event with.</param>
/// <param name="service">LoggingService mock object which overrides ProcessBuildEvent and can provide a ProcessedBuildEvent (the event which would have been sent to the loggers)</param>
private void VerifyTaskStartedEvent(string taskName, string projectFile, string projectFileOfTask, string message, ProcessBuildEventHelper service)
private void VerifyTaskStartedEvent(string taskName, string projectFile, string projectFileOfTask, string message, ProcessBuildEventHelper service, string taskAssemblyName)
{
TaskStartedEventArgs taskEvent = new TaskStartedEventArgs(
message,
null, // no help keyword
projectFile,
projectFileOfTask,
taskName,
service.ProcessedBuildEvent.Timestamp);
service.ProcessedBuildEvent.Timestamp,
taskAssemblyName);
taskEvent.BuildEventContext = s_buildEventContext;
Assert.True(((TaskStartedEventArgs)service.ProcessedBuildEvent).IsEquivalent(taskEvent));
}
Expand Down
7 changes: 5 additions & 2 deletions src/Build.UnitTests/BackEnd/MockLoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
Expand Down Expand Up @@ -573,7 +574,8 @@ public void LogTargetFinished(BuildEventContext targetBuildEventContext, string
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file</param>
/// <param name="projectFileOfTaskNode">The project file containing the task node.</param>
public void LogTaskStarted(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode)
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
public void LogTaskStarted(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, string taskAssemblyName)
{
}

Expand All @@ -584,8 +586,9 @@ public void LogTaskStarted(BuildEventContext targetBuildEventContext, string tas
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file</param>
/// <param name="projectFileOfTaskNode">The project file containing the task node.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
/// <returns>The task logging context</returns>
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column)
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, string taskAssemblyName)
{
return new BuildEventContext(0, 0, 0, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class TaskExecutionHost_Tests : ITestTaskHost, IBuildEngine2, IDisposable
/// <summary>
/// The task execution host
/// </summary>
private ITaskExecutionHost _host;
private TaskExecutionHost _host;

/// <summary>
/// The mock logging service
Expand Down Expand Up @@ -1190,7 +1190,7 @@ private void InitializeHost(bool throwOnExecute)
CancellationToken.None);

ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First();
TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance);
TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance, typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory).GetTypeInfo().Assembly.GetName().FullName);
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved

ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();

Expand Down
7 changes: 5 additions & 2 deletions src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public void RoundtripTaskStartedEventArgs()
null,
projectFile: "C:\\project.proj",
taskFile: "C:\\common.targets",
taskName: "Csc");
taskName: "Csc",
DateTime.Now,
"TaskAssemblyName");
args.LineNumber = 42;
args.ColumnNumber = 999;

Expand All @@ -200,7 +202,8 @@ public void RoundtripTaskStartedEventArgs()
e => e.TaskFile,
e => e.TaskName,
e => e.LineNumber.ToString(),
e => e.ColumnNumber.ToString());
e => e.ColumnNumber.ToString(),
e => e.TaskAssemblyName);
}

[Fact]
Expand Down
7 changes: 5 additions & 2 deletions src/Build/BackEnd/Components/Logging/ILoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -570,7 +571,8 @@ BuildEventContext LogProjectStarted(
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file which is being built</param>
/// <param name="projectFileOfTaskNode">The file in which the task is defined - typically a .targets file</param>
void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode);
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, string taskAssemblyName);

/// <summary>
/// Log that a task is about to start
Expand All @@ -581,8 +583,9 @@ BuildEventContext LogProjectStarted(
/// <param name="projectFileOfTaskNode">The file in which the task is defined - typically a .targets file</param>
/// <param name="line">The line number in the file where the task invocation is located.</param>
/// <param name="column">The column number in the file where the task invocation is located.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
/// <returns>The task build event context</returns>
BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column);
BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, string taskAssemblyName);

/// <summary>
/// Log that a task has just completed
Expand Down
13 changes: 9 additions & 4 deletions src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -688,8 +689,9 @@ public void LogTargetFinished(BuildEventContext targetBuildEventContext, string
/// <param name="taskName">Task Name</param>
/// <param name="projectFile">Project file being built</param>
/// <param name="projectFileOfTaskNode">Project file which contains the task</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
/// <exception cref="InternalErrorException">BuildEventContext is null</exception>
public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode)
public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, string taskAssemblyName)
{
ErrorUtilities.VerifyThrow(taskBuildEventContext != null, "targetBuildEventContext is null");
if (!OnlyLogCriticalEvents)
Expand All @@ -699,7 +701,8 @@ public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskN
helpKeyword: null,
projectFile,
projectFileOfTaskNode,
taskName);
taskName,
taskAssemblyName);
buildEvent.BuildEventContext = taskBuildEventContext;
ProcessLoggingEvent(buildEvent);
}
Expand All @@ -714,9 +717,10 @@ public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskN
/// <param name="projectFileOfTaskNode">Project file which contains the task</param>
/// <param name="line">The line number in the file where the task invocation is located.</param>
/// <param name="column">The column number in the file where the task invocation is located.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>The build event context for the task.</returns>
/// <exception cref="InternalErrorException">BuildEventContext is null</exception>
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column)
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, string taskAssemblyName)
{
ErrorUtilities.VerifyThrow(targetBuildEventContext != null, "targetBuildEventContext is null");
BuildEventContext taskBuildEventContext = new BuildEventContext(
Expand All @@ -734,7 +738,8 @@ public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventConte
helpKeyword: null,
projectFile,
projectFileOfTaskNode,
taskName);
taskName,
taskAssemblyName);
buildEvent.BuildEventContext = taskBuildEventContext;
buildEvent.LineNumber = line;
buildEvent.ColumnNumber = column;
Expand Down
5 changes: 3 additions & 2 deletions src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -108,11 +109,11 @@ internal void LogTargetBatchFinished(string projectFullPath, bool success, IEnum
/// <summary>
/// Log that a task is about to start
/// </summary>
internal TaskLoggingContext LogTaskBatchStarted(string projectFullPath, ProjectTargetInstanceChild task)
internal TaskLoggingContext LogTaskBatchStarted(string projectFullPath, ProjectTargetInstanceChild task, string taskAssemblyName)
{
ErrorUtilities.VerifyThrow(IsValid, "Should be valid");

return new TaskLoggingContext(this, projectFullPath, task);
return new TaskLoggingContext(this, projectFullPath, task, taskAssemblyName);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -34,7 +35,7 @@ internal class TaskLoggingContext : BuildLoggingContext
/// <summary>
/// Constructs a task logging context from a parent target context and a task node.
/// </summary>
internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string projectFullPath, ProjectTargetInstanceChild task)
internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string projectFullPath, ProjectTargetInstanceChild task, string taskAssemblyName)
: base(targetLoggingContext)
{
_targetLoggingContext = targetLoggingContext;
Expand Down Expand Up @@ -72,7 +73,8 @@ internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string pr
projectFullPath,
task.Location.File,
task.Location.Line,
task.Location.Column);
task.Location.Column,
taskAssemblyName);
this.IsValid = true;
}

Expand Down
Loading
Loading