-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly evaluate PackInference.PackExclude
We were previously assuming Exclude was a valuated while doing the Include for entire item groups, while this is not the case. We need instead to evaluate using the same MSBuild syntax (we use minimatch for this) so we can properly exclude items. Fixes #128 and #122.
- Loading branch information
Showing
5 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using Minimatch; | ||
|
||
namespace NuGetizer.Tasks | ||
{ | ||
/// <summary> | ||
/// Evaluates one or more minimatch expressions against a set of | ||
/// items and returns two lists: those that matched and those that | ||
/// didn't. | ||
/// </summary> | ||
public class EvaluateWildcards : Task | ||
{ | ||
[Required] | ||
public ITaskItem[] Items { get; set; } | ||
|
||
[Required] | ||
public string Wildcards { get; set; } | ||
|
||
[Output] | ||
public ITaskItem[] MatchingItems { get; set; } | ||
|
||
[Output] | ||
public ITaskItem[] NonMatchingItems { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
var matching = new List<ITaskItem>(); | ||
var nonMatching = new List<ITaskItem>(); | ||
|
||
var options = new Options | ||
{ | ||
AllowWindowsPaths = true, | ||
Dot = true, | ||
IgnoreCase = true | ||
}; | ||
|
||
var matchers = Wildcards | ||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(wildcard => new Minimatcher(wildcard.Trim(), options)) | ||
.ToList(); | ||
|
||
foreach (var item in Items) | ||
{ | ||
if (matchers.Any(matcher => matcher.IsMatch(item.ItemSpec)) || | ||
matchers.Any(matcher => matcher.IsMatch(item.GetMetadata("Fullpath")))) | ||
matching.Add(item); | ||
else | ||
nonMatching.Add(item); | ||
} | ||
|
||
MatchingItems = matching.ToArray(); | ||
NonMatchingItems = nonMatching.ToArray(); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters