-
Notifications
You must be signed in to change notification settings - Fork 1
/
Globbing.cs
109 lines (103 loc) · 4.06 KB
/
Globbing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Cake.Common.IO;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;
using System.Linq;
namespace Dnn.CakeUtils
{
public static class ScriptAliases
{
[CakeMethodAlias]
public static FilePathCollection GetFilesByPatterns(this ICakeContext context, string[] includePatterns)
{
var res = new FilePathCollection();
for (var i = 0; i < includePatterns.Length; i++)
{
var incl = context.GetFiles(includePatterns[i]);
var crt = res.Select(ii => ii.FullPath);
foreach (var include in incl)
{
if (!crt.Contains(include.FullPath))
{
res.Add(include);
}
}
}
return res;
}
[CakeMethodAlias]
public static FilePathCollection GetFilesByPatterns(this ICakeContext context, string[] includePatterns, string[] excludePatterns)
{
if (excludePatterns.Length == 0)
{
return GetFilesByPatterns(context, includePatterns);
}
FilePathCollection excludeFiles = context.GetFiles(excludePatterns[0]);
for (var i = 1; i < excludePatterns.Length; i++)
{
excludeFiles.Add(context.GetFiles(excludePatterns[i]));
}
var excludePaths = excludeFiles.Select(e => e.FullPath);
var res = new FilePathCollection();
for (var i = 0; i < includePatterns.Length; i++)
{
var incl = context.GetFiles(includePatterns[i]);
var crt = res.Select(ii => ii.FullPath);
foreach (var include in incl)
{
if (!excludeFiles.Contains(include.FullPath) && !crt.Contains(include.FullPath))
{
res.Add(include);
}
}
}
return res;
}
[CakeMethodAlias]
public static FilePathCollection GetFilesByPatterns(this ICakeContext context, DirectoryPath root, string[] includePatterns)
{
var res = new FilePathCollection();
for (var i = 0; i < includePatterns.Length; i++)
{
var incl = context.GetFiles(root.CombineWithFilePath(includePatterns[i].TrimStart('/')).ToString());
var crt = res.Select(ii => ii.FullPath);
foreach (var include in incl)
{
if (!crt.Contains(include.FullPath))
{
res.Add(include);
}
}
}
return res;
}
[CakeMethodAlias]
public static FilePathCollection GetFilesByPatterns(this ICakeContext context, DirectoryPath root, string[] includePatterns, string[] excludePatterns)
{
if (excludePatterns.Length == 0)
{
return GetFilesByPatterns(context, includePatterns);
}
var excludeFiles = context.GetFiles(root.CombineWithFilePath(excludePatterns[0].TrimStart('/')).ToString());
for (var i = 1; i < excludePatterns.Length; i++)
{
excludeFiles.Add(context.GetFiles(root.CombineWithFilePath(excludePatterns[i].TrimStart('/')).ToString()));
}
var excludePaths = excludeFiles.Select(e => e.FullPath);
var res = new FilePathCollection();
for (var i = 0; i < includePatterns.Length; i++)
{
var incl = context.GetFiles(root.CombineWithFilePath(includePatterns[i].TrimStart('/')).ToString());
var crt = res.Select(ii => ii.FullPath);
foreach (var include in incl)
{
if (!excludeFiles.Contains(include.FullPath) && !crt.Contains(include.FullPath))
{
res.Add(include);
}
}
}
return res;
}
}
}