diff --git a/src/Cake.Core/IO/Directory.cs b/src/Cake.Core/IO/Directory.cs index f95f701ee9..92d08ad2cb 100644 --- a/src/Cake.Core/IO/Directory.cs +++ b/src/Cake.Core/IO/Directory.cs @@ -121,5 +121,12 @@ public IDirectory SetUnixFileMode(UnixFileMode unixFileMode) _directory.Refresh(); return this; } + + public IEnumerable GetFileSystemInfos(string filter, SearchScope scope) + { + var directories = GetDirectories(filter, scope).Cast(); + var files = GetFiles(filter, scope).Cast(); + return directories.Concat(files); + } } } \ No newline at end of file diff --git a/src/Cake.Core/IO/FileSystem.cs b/src/Cake.Core/IO/FileSystem.cs index efcb053f46..bc201cdb9f 100644 --- a/src/Cake.Core/IO/FileSystem.cs +++ b/src/Cake.Core/IO/FileSystem.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; + namespace Cake.Core.IO { /// @@ -20,5 +22,20 @@ public IDirectory GetDirectory(DirectoryPath path) { return new Directory(path); } + + /// + public IFileSystemInfo GetFileSystemInfo(DirectoryPath path) + { + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } + var directory = GetDirectory(path); + if (directory.Exists) + { + return directory; + } + return GetFile(path.FullPath); + } } } \ No newline at end of file diff --git a/src/Cake.Core/IO/Globber.cs b/src/Cake.Core/IO/Globber.cs index e24ef8a2d8..5f4610f391 100644 --- a/src/Cake.Core/IO/Globber.cs +++ b/src/Cake.Core/IO/Globber.cs @@ -18,6 +18,7 @@ public sealed class Globber : IGlobber private readonly GlobVisitor _visitor; private readonly PathComparer _comparer; private readonly ICakeEnvironment _environment; + private readonly IFileSystem _fileSystem; /// /// Initializes a new instance of the class. @@ -33,6 +34,7 @@ public Globber(IFileSystem fileSystem, ICakeEnvironment environment) _parser = new GlobParser(environment); _visitor = new GlobVisitor(fileSystem, environment); _comparer = new PathComparer(environment.Platform.IsUnix()); + _fileSystem = fileSystem; } /// @@ -52,5 +54,21 @@ public IEnumerable Match(GlobPattern pattern, GlobberSettings settings) .Select(x => x.Path) .Distinct(_comparer); } + + /// + public IEnumerable GetFileSystemInfos(string pattern) + { + if (pattern is null) + { + throw new ArgumentNullException(nameof(pattern)); + } + + var glob = _parser.Parse(pattern, new GlobberSettings + { + IsCaseSensitive = !_comparer.IsCaseSensitive + }); + var settings = new GlobberSettings { IsCaseSensitive = !_comparer.IsCaseSensitive }; + return _visitor.Walk(glob, settings); + } } } \ No newline at end of file diff --git a/src/Cake.Core/IO/IDirectory.cs b/src/Cake.Core/IO/IDirectory.cs index eee8fddcb7..6a711f06f8 100644 --- a/src/Cake.Core/IO/IDirectory.cs +++ b/src/Cake.Core/IO/IDirectory.cs @@ -100,5 +100,13 @@ public interface IDirectory : IFileSystemInfo /// The to set. /// The instance representing the specified path. IDirectory SetUnixFileMode(UnixFileMode unixFileMode) => this; + + /// + /// Gets all file system entries in the directory. + /// + /// The filter. + /// The search scope. + /// The file system entries. + IEnumerable GetFileSystemInfos(string filter, SearchScope scope); } } \ No newline at end of file diff --git a/src/Cake.Core/IO/IFileSystem.cs b/src/Cake.Core/IO/IFileSystem.cs index 3bdf5eacfb..e4478d8806 100644 --- a/src/Cake.Core/IO/IFileSystem.cs +++ b/src/Cake.Core/IO/IFileSystem.cs @@ -22,5 +22,12 @@ public interface IFileSystem /// The path. /// A instance representing the specified path. IDirectory GetDirectory(DirectoryPath path); + + /// + /// Gets a for the specified path. + /// + /// The path. + /// A for the specified path. + IFileSystemInfo GetFileSystemInfo(DirectoryPath path); } } \ No newline at end of file diff --git a/src/Cake.Core/IO/IGlobber.cs b/src/Cake.Core/IO/IGlobber.cs index e38aba0e6a..18c79041de 100644 --- a/src/Cake.Core/IO/IGlobber.cs +++ b/src/Cake.Core/IO/IGlobber.cs @@ -20,5 +20,12 @@ public interface IGlobber /// instances matching the specified pattern. /// IEnumerable Match(GlobPattern pattern, GlobberSettings settings); + + /// + /// Returns a list of matching the specified pattern. + /// + /// The pattern to match. + /// A list of . + IEnumerable GetFileSystemInfos(string pattern); } } \ No newline at end of file diff --git a/src/Cake.Testing/FakeDirectory.cs b/src/Cake.Testing/FakeDirectory.cs index d83546fc06..98b73417a6 100644 --- a/src/Cake.Testing/FakeDirectory.cs +++ b/src/Cake.Testing/FakeDirectory.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Text.RegularExpressions; using Cake.Core.IO; @@ -276,5 +277,15 @@ private static Regex CreateRegex(string pattern) pattern = pattern.Replace(".", "\\.").Replace("*", ".*").Replace("?", ".{1}"); return new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled); } + + /// + public IEnumerable GetFileSystemInfos(string filter, SearchScope scope) + { + // بنجمع المجلدات والملفات الوهمية + var directories = GetDirectories(filter, scope).Cast(); + var files = GetFiles(filter, scope).Cast(); + + return directories.Concat(files); + } } } \ No newline at end of file diff --git a/src/Cake.Testing/FakeFileSystem.cs b/src/Cake.Testing/FakeFileSystem.cs index 29d3526c1a..941b77e62e 100644 --- a/src/Cake.Testing/FakeFileSystem.cs +++ b/src/Cake.Testing/FakeFileSystem.cs @@ -70,5 +70,20 @@ IFile IFileSystem.GetFile(FilePath path) { return GetFile(path); } + + /// + public IFileSystemInfo GetFileSystemInfo(DirectoryPath path) + { + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } + var directory = GetDirectory(path); + if (directory.Exists) + { + return directory; + } + return GetFile(path.FullPath); + } } } \ No newline at end of file