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

Allow DirectoryCheck to match a pattern #42

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions recipe/package-checks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class Check
private static FileCheck HasFile(FilePath file) => HasFiles(new[] { file });
private static FileCheck HasFiles(params FilePath[] files) => new FileCheck(files);

private static DirectoryCheck HasDirectory(string dir) => new DirectoryCheck(dir);
private static DirectoryCheck HasDirectory(string dirPathOrPattern) => new DirectoryCheck(dirPathOrPattern);

//////////////////////////////////////////////////////////////////////
// PACKAGECHECK CLASS
Expand Down Expand Up @@ -106,12 +106,12 @@ public class FileCheck : PackageCheck

public class DirectoryCheck : PackageCheck
{
private DirectoryPath _relDirPath;
private string _dirPathOrPattern;
private List<FilePath> _files = new List<FilePath>();

public DirectoryCheck(DirectoryPath relDirPath)
public DirectoryCheck(string dirPathOrPattern)
{
_relDirPath = relDirPath;
_dirPathOrPattern = dirPathOrPattern;
}

public DirectoryCheck WithFiles(params FilePath[] files)
Expand All @@ -138,11 +138,24 @@ public class DirectoryCheck : PackageCheck

public override bool ApplyTo(DirectoryPath testDirPath)
{
DirectoryPath absDirPath = testDirPath.Combine(_relDirPath);
if (_dirPathOrPattern.Contains('*') || _dirPathOrPattern.Contains('?')) // Wildcard
{
var absDirPattern = testDirPath.Combine(_dirPathOrPattern).ToString();
foreach (var dir in _context.GetDirectories(absDirPattern))
{
// Use first one found
return CheckFilesExist(_files.Select(file => dir.CombineWithFilePath(file)));
}
}
else // No wildcard
{
var absDirPath = testDirPath.Combine(_dirPathOrPattern);
if (!CheckDirectoryExists(absDirPath))
return false;

return CheckFilesExist(_files.Select(file => absDirPath.CombineWithFilePath(file)));
}

if (!CheckDirectoryExists(absDirPath))
return false;

return CheckFilesExist(_files.Select(file => absDirPath.CombineWithFilePath(file)));
return false;
}
}
Loading