1
- // Copyright 2019 Maintainers of NUKE.
1
+ // Copyright 2019 Maintainers of NUKE.
2
2
// Distributed under the MIT License.
3
3
// https://github.com/nuke-build/nuke/blob/master/LICENSE
4
4
11
11
using System . Linq ;
12
12
using GlobExpressions ;
13
13
using JetBrains . Annotations ;
14
+ using Nuke . Common . Execution ;
14
15
using Nuke . Common . Utilities ;
15
16
16
17
// ReSharper disable ArrangeMethodOrOperatorBody
17
18
18
19
namespace Nuke . Common . IO
19
20
{
21
+ /// <summary>
22
+ /// Indicates the case sensitivity used for globbing.
23
+ /// </summary>
24
+ public enum GlobbingCaseSensitivity
25
+ {
26
+ /// <summary>
27
+ /// Automatically determines whether to use case-sensitive or case-insensitive matching when globbing. This
28
+ /// means using case-insensitive matching when running on Windows, and case-sensitive otherwise.
29
+ /// </summary>
30
+ Auto ,
31
+ /// <summary>
32
+ /// Globbing patterns will be case-sensitive.
33
+ /// </summary>
34
+ CaseSensitive ,
35
+ /// <summary>
36
+ /// Globbing patterns will be case-insensitive.
37
+ /// </summary>
38
+ CaseInsensitive
39
+ }
40
+
20
41
/// <summary>
21
42
/// <p>Provides an abstraction for generating Windows/Unix/UNC-compliant
22
43
/// file-system paths independently of the underlying operating system. Usages should be restricted to the moment
23
44
/// of construction, i.e., avoid using it as part of an API.</p>
24
45
/// <p>Casting a string with <c>(RelativePath)</c> will construct any intermediate part of a path using the specific separators
25
- /// for the currently running operating-system. By using <c>(WinRelativePath)</c> and <c>(UnixRelativePath)</c> other separators can be
46
+ /// for the currently running operating-system. By using <c>(WinRelativePath)</c> and <c>(UnixRelativePath)</c> other separators can be
26
47
/// used intentionally. Casting with <c>(AbsolutePath)</c> ensures that the path is rooted as Windows/Unix/UNC-path. The operators
27
48
/// <c>/</c> and <c>+</c> allow to append sub-directories.</p>
28
49
/// <p>Resulting paths are automatically normalized if possible. So <c>C:\foo\..\bar\.</c> will become <c>C:\bar</c>.</p>
@@ -45,6 +66,24 @@ namespace Nuke.Common.IO
45
66
[ PublicAPI ]
46
67
public static class PathConstruction
47
68
{
69
+ internal static GlobbingCaseSensitivity GlobbingCaseSensitivity ;
70
+
71
+ private static GlobOptions GlobOptions
72
+ {
73
+ get
74
+ {
75
+ switch ( GlobbingCaseSensitivity )
76
+ {
77
+ case GlobbingCaseSensitivity . CaseSensitive :
78
+ return GlobOptions . None ;
79
+ case GlobbingCaseSensitivity . CaseInsensitive :
80
+ return GlobOptions . CaseInsensitive ;
81
+ default :
82
+ return EnvironmentInfo . IsWin ? GlobOptions . CaseInsensitive : GlobOptions . None ;
83
+ }
84
+ }
85
+ }
86
+
48
87
// TODO: check usages
49
88
[ Pure ]
50
89
public static string GetRelativePath ( string basePath , string destinationPath , bool normalize = true )
@@ -75,7 +114,7 @@ public static bool IsDescendantPath(string basePath, string destinationPath)
75
114
public static IReadOnlyCollection < string > GlobFiles ( string directory , params string [ ] patterns )
76
115
{
77
116
var directoryInfo = new DirectoryInfo ( directory ) ;
78
- return patterns . SelectMany ( x => directoryInfo . GlobFiles ( x ) ) . Select ( x => x . FullName ) . ToList ( ) ;
117
+ return patterns . SelectMany ( x => Glob . Files ( directoryInfo , x , GlobOptions ) ) . Select ( x => x . FullName ) . ToList ( ) ;
79
118
}
80
119
81
120
public static IReadOnlyCollection < AbsolutePath > GlobFiles ( this AbsolutePath directory , params string [ ] patterns )
@@ -87,7 +126,7 @@ public static IReadOnlyCollection<AbsolutePath> GlobFiles(this AbsolutePath dire
87
126
public static IReadOnlyCollection < string > GlobDirectories ( string directory , params string [ ] patterns )
88
127
{
89
128
var directoryInfo = new DirectoryInfo ( directory ) ;
90
- return patterns . SelectMany ( x => directoryInfo . GlobDirectories ( x ) ) . Select ( x => x . FullName ) . ToList ( ) ;
129
+ return patterns . SelectMany ( x => Glob . Directories ( directoryInfo , x , GlobOptions ) ) . Select ( x => x . FullName ) . ToList ( ) ;
91
130
}
92
131
93
132
public static IReadOnlyCollection < AbsolutePath > GlobDirectories ( this AbsolutePath directory , params string [ ] patterns )
@@ -415,4 +454,24 @@ public override string ToString()
415
454
}
416
455
}
417
456
}
457
+
458
+ /// <summary>
459
+ /// Allows to configure the case-sensitivity used for globbing operations in <see cref="PathConstruction"/>.
460
+ /// </summary>
461
+ [ PublicAPI ]
462
+ [ AttributeUsage ( AttributeTargets . Class ) ]
463
+ public sealed class GlobbingOptionsAttribute : Attribute , IPreLogoBuildExtension
464
+ {
465
+ private readonly GlobbingCaseSensitivity _caseSensitivity ;
466
+
467
+ public GlobbingOptionsAttribute ( GlobbingCaseSensitivity caseSensitivity )
468
+ {
469
+ _caseSensitivity = caseSensitivity ;
470
+ }
471
+
472
+ public void Execute ( NukeBuild build , IReadOnlyCollection < ExecutableTarget > executableTargets , IReadOnlyCollection < ExecutableTarget > executionPlan )
473
+ {
474
+ PathConstruction . GlobbingCaseSensitivity = _caseSensitivity ;
475
+ }
476
+ }
418
477
}
0 commit comments