Skip to content

Commit

Permalink
Fix populating metadata from legacy binlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Aug 24, 2021
1 parent 071bb14 commit 67b0b22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/StructuredLogger/Construction/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,10 @@ public void UpdateProject(Project project, ProjectStartedEventArgs args)
}
}

public static void AddMetadata(ITaskItem item, Item itemNode)
public void AddMetadata(ITaskItem item, Item itemNode)
{
if (item.CloneCustomMetadata() is ArrayDictionary<string, string> metadata)
var cloned = item.CloneCustomMetadata();
if (cloned is ArrayDictionary<string, string> metadata)
{
int count = metadata.Count;
if (count == 0)
Expand Down Expand Up @@ -858,6 +859,25 @@ public static void AddMetadata(ITaskItem item, Item itemNode)
metadataNode.Parent = itemNode;
}
}
else
{
if (cloned is ICollection collection)
{
itemNode.EnsureChildrenCapacity(collection.Count);
}

foreach (DictionaryEntry metadataName in cloned)
{
var metadataNode = new Metadata
{
Name = SoftIntern(Convert.ToString(metadataName.Key)),
Value = SoftIntern(Convert.ToString(metadataName.Value))
};

itemNode.Children.Add(metadataNode);
metadataNode.Parent = itemNode;
}
}
}

private void AddItems(TreeNode parent, IEnumerable itemList)
Expand Down
2 changes: 1 addition & 1 deletion src/StructuredLogger/Construction/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void AddItems(IEnumerable items, TreeNode parent)
foreach (ITaskItem item in items)
{
var itemNode = new Item { Text = item.ItemSpec };
Construction.AddMetadata(item, itemNode);
this.construction.AddMetadata(item, itemNode);
parent.AddChild(itemNode);
}
}
Expand Down

0 comments on commit 67b0b22

Please sign in to comment.