Skip to content

Commit

Permalink
Support getting task messages from a subfolder if present
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Sep 7, 2024
1 parent ac359d7 commit 2744686
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/StructuredLogger/Analyzers/CscTaskAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static (Folder Analyzers, Folder Generators) Analyze(Task task)
Folder currentReport = null;
Folder parent = null;

foreach (var message in task.Children.OfType<Message>().ToArray())
foreach (var message in task.GetMessages().ToArray())
{
var text = message.Text;
if (text.StartsWith(Strings.TotalAnalyzerExecutionTime, StringComparison.Ordinal))
Expand Down
16 changes: 15 additions & 1 deletion src/StructuredLogger/ObjectModel/Task.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Microsoft.Build.Logging.StructuredLogger
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Build.Logging.StructuredLogger
{
public class Task : TimedNode, IHasSourceFile, IHasLineNumber
{
Expand All @@ -11,6 +14,17 @@ public class Task : TimedNode, IHasSourceFile, IHasLineNumber
public virtual bool IsDerivedTask => this.GetType() != typeof(Task);

public int? LineNumber { get; set; }

public IReadOnlyList<Message> GetMessages()
{
TreeNode node = this;
if (this.FindChild<Folder>(Strings.Messages) is Folder messagesFolder)
{
node = messagesFolder;
}

return node.Children.OfType<Message>().ToArray();
}
}

public class MSBuildTask : Task
Expand Down
2 changes: 1 addition & 1 deletion src/StructuredLogger/ObjectModel/Tasks/CopyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected virtual IEnumerable<FileCopyOperation> GetFileCopyOperations()
List<FileCopyOperation> list = new List<FileCopyOperation>();

Match match;
foreach (var message in this.Children.OfType<Message>())
foreach (var message in this.GetMessages())
{
var text = message.Text;

Expand Down
2 changes: 1 addition & 1 deletion src/StructuredLogger/ObjectModel/Tasks/RobocopyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override IEnumerable<FileCopyOperation> GetFileCopyOperations()
List<FileCopyOperation> list = new List<FileCopyOperation>();

Match match;
foreach (var message in Children.OfType<Message>())
foreach (var message in GetMessages())
{
var text = message.Text;

Expand Down

0 comments on commit 2744686

Please sign in to comment.