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 Include/Exclude filtering capability to Unzip Task (#5169) #6018

Merged
merged 19 commits into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9987940
Added Include/Exclude RegEx filtering capability to Unzip Task
sc-ivanlieckens Jan 11, 2021
08cb0d1
Added Exclude Filter Unit Test for Unzip Task
sc-ivanlieckens Jan 11, 2021
86c25c2
Adjusted Unit Test according to feedback
sc-ivanlieckens Jan 14, 2021
fbc0a4f
Applied resource string suggestion
sc-ivanlieckens Jan 14, 2021
e71e37f
Adjusted Include and Exclude to IncludePattern and ExcludePattern as …
sc-ivanlieckens Jan 20, 2021
152aadc
Adjusted property names to "Include" and "Exclude" and altered them t…
sc-ivanlieckens Jan 26, 2021
941d7eb
Unzip task unit tests for pattern parsing
sc-ivanlieckens Jan 27, 2021
658c23a
Name adjustment to better match actual verification
sc-ivanlieckens Jan 28, 2021
8164bfd
Attempt to fail valid character path tests on MacOS and Linux
sc-ivanlieckens Jan 28, 2021
1f1aa6d
Made InvalidPath Unzip unit tests platform specific
sc-ivanlieckens Jan 28, 2021
5e489e2
Improved property or item reference detection
IvanLieckens Jan 29, 2021
9fedb34
Invalid path detection before splitting improvement
sc-ivanlieckens Jan 29, 2021
62d56a9
Added | to invalid path testing
sc-ivanlieckens Jan 29, 2021
76a94f1
Removed platform specific attribute on Invalid Path Character tests i…
sc-ivanlieckens Jan 29, 2021
e9e0f5f
Perf improvement detecting include pattern match
IvanLieckens Jan 29, 2021
8608320
Perf improvement detecting exclude pattern match
IvanLieckens Jan 29, 2021
e4d0286
Small FileMatcher correction, Removed return on parsing for patterns …
sc-ivanlieckens Jan 29, 2021
164e8e7
Updated Include description
IvanLieckens Jan 29, 2021
081c179
Updated Exclude description
IvanLieckens Jan 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Shared/FileMatcher.cs
Expand Up @@ -204,7 +204,7 @@ internal static bool HasWildcardsSemicolonItemOrPropertyReferences(string filesp
/// </summary>
internal static bool HasPropertyOrItemReferences(string filespec)
{
return s_propertyAndItemReferences.Any(ref=> filespec.Contains(ref));
return s_propertyAndItemReferences.Any(filespec.Contains);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice!

}

/// <summary>
Expand Down
49 changes: 23 additions & 26 deletions src/Tasks/Unzip.cs
Expand Up @@ -96,7 +96,9 @@ public override bool Execute()

try
{
if (ParseIncludeExclude())
ParseIncludeExclude();

if (!Log.HasLoggedErrors)
{
foreach (ITaskItem sourceFile in SourceFiles.TakeWhile(i => !_cancellationToken.IsCancellationRequested))
{
Expand Down Expand Up @@ -266,38 +268,33 @@ private bool ShouldSkipEntry(ZipArchiveEntry zipArchiveEntry, FileInfo fileInfo)
&& zipArchiveEntry.Length == fileInfo.Length;
}

private bool ParseIncludeExclude()
private void ParseIncludeExclude()
{
return ParsePattern(Include, out _includePatterns) && ParsePattern(Exclude, out _excludePatterns);
ParsePattern(Include, out _includePatterns);
ParsePattern(Exclude, out _excludePatterns);
}

private bool ParsePattern(string pattern, out string[] patterns)
private void ParsePattern(string pattern, out string[] patterns)
{
bool result = false;
patterns = Array.Empty<string>();
if (string.IsNullOrWhiteSpace(pattern))
if (!string.IsNullOrWhiteSpace(pattern))
{
result = true;
}
else if (FileMatcher.HasPropertyOrItemReferences(pattern))
{
// Supporting property references would require access to Expander which is unavailable in Microsoft.Build.Tasks
Log.LogErrorWithCodeFromResources("Unzip.ErrorParsingPatternPropertyReferences", pattern);
}
else if (pattern.IndexOfAny(FileUtilities.InvalidPathChars) != -1)
{
Log.LogErrorWithCodeFromResources("Unzip.ErrorParsingPatternInvalidPath", pattern);
}
else
{
patterns = pattern.Contains(';')
? pattern.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(FileMatcher.Normalize).ToArray()
: new[] { pattern };

result = true;
if (FileMatcher.HasPropertyOrItemReferences(pattern))
{
// Supporting property references would require access to Expander which is unavailable in Microsoft.Build.Tasks
Log.LogErrorWithCodeFromResources("Unzip.ErrorParsingPatternPropertyReferences", pattern);
}
else if (pattern.IndexOfAny(FileUtilities.InvalidPathChars) != -1)
{
Log.LogErrorWithCodeFromResources("Unzip.ErrorParsingPatternInvalidPath", pattern);
}
else
{
patterns = pattern.Contains(';')
? pattern.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(FileMatcher.Normalize).ToArray()
: new[] { pattern };
}
}

return result;
}
}
}