Xamarin Public Jenkins (auto-signing) 19234507ba Imported Upstream version 5.14.0.78
Former-commit-id: 3494343bcc9ddb42b36b82dd9ae7b69e85e0229f
2018-05-10 08:37:03 +00:00

48 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace ILLink.Tasks
{
public class FindDuplicatesByMetadata : Task
{
/// <summary>
/// Items to scan.
/// </summary>
[Required]
public ITaskItem [] Items { get; set; }
/// <summary>
/// Name of metadata to scan for.
/// </summary>
[Required]
public String MetadataName { get; set; }
/// <summary>
/// Duplicate items: the input items for which the
/// specified metadata was shared by multiple input
/// items.
/// </summary>
[Output]
public ITaskItem [] DuplicateItems { get; set; }
/// <summary>
/// Duplicate representatives: includes one input
/// item from each set of duplicates.
/// </summary>
[Output]
public ITaskItem [] DuplicateRepresentatives { get; set; }
public override bool Execute ()
{
var duplicateGroups = Items.GroupBy (i => i.GetMetadata (MetadataName))
.Where (g => g.Count () > 1);
DuplicateItems = duplicateGroups.SelectMany (g => g).ToArray ();
DuplicateRepresentatives = duplicateGroups.Select (g => g.First ()).ToArray ();
return true;
}
}
}