12
12
using Microsoft . Build . Framework ;
13
13
using Microsoft . Build . Shared ;
14
14
15
- #nullable disable
16
-
17
15
namespace Microsoft . Build . Internal
18
16
{
19
17
internal static class EngineFileUtilities
@@ -22,7 +20,7 @@ internal static class EngineFileUtilities
22
20
23
21
// Regexes for wildcard filespecs that should not get expanded
24
22
// By default all wildcards are expanded.
25
- private static List < Regex > s_lazyWildCardExpansionRegexes ;
23
+ private static List < Regex > ? s_lazyWildCardExpansionRegexes ;
26
24
27
25
static EngineFileUtilities ( )
28
26
{
@@ -59,8 +57,8 @@ internal static void CaptureLazyWildcardRegexes()
59
57
internal static string [ ] GetFileListUnescaped (
60
58
string directoryEscaped ,
61
59
string filespecEscaped ,
62
- object loggingMechanism = null ,
63
- IElementLocation excludeLocation = null )
60
+ object ? loggingMechanism = null ,
61
+ IElementLocation ? excludeLocation = null )
64
62
{
65
63
return GetFileList (
66
64
directoryEscaped ,
@@ -100,17 +98,17 @@ internal static string[] GetFileListUnescaped(
100
98
/// for the Exclude attribute after detecting a drive enumerating wildcard.</param>
101
99
/// <returns>Array of file paths, escaped.</returns>
102
100
internal static string [ ] GetFileListEscaped (
103
- string directoryEscaped ,
101
+ string ? directoryEscaped ,
104
102
string filespecEscaped ,
105
- IEnumerable < string > excludeSpecsEscaped = null ,
103
+ IEnumerable < string > ? excludeSpecsEscaped = null ,
106
104
bool forceEvaluate = false ,
107
- FileMatcher fileMatcher = null ,
108
- object loggingMechanism = null ,
109
- IElementLocation includeLocation = null ,
110
- IElementLocation excludeLocation = null ,
111
- IElementLocation importLocation = null ,
112
- BuildEventContext buildEventContext = null ,
113
- string buildEventFileInfoFullPath = null ,
105
+ FileMatcher ? fileMatcher = null ,
106
+ object ? loggingMechanism = null ,
107
+ IElementLocation ? includeLocation = null ,
108
+ IElementLocation ? excludeLocation = null ,
109
+ IElementLocation ? importLocation = null ,
110
+ BuildEventContext ? buildEventContext = null ,
111
+ string ? buildEventFileInfoFullPath = null ,
114
112
bool disableExcludeDriveEnumerationWarning = false )
115
113
{
116
114
return GetFileList (
@@ -171,18 +169,18 @@ internal static bool FilespecHasWildcards(string filespecEscaped)
171
169
/// for the Exclude attribute after detecting a drive enumerating wildcard.</param>
172
170
/// <returns>Array of file paths.</returns>
173
171
private static string [ ] GetFileList (
174
- string directoryEscaped ,
175
- string filespecEscaped ,
172
+ string ? directoryEscaped ,
173
+ string ? filespecEscaped ,
176
174
bool returnEscaped ,
177
175
bool forceEvaluateWildCards ,
178
- IEnumerable < string > excludeSpecsEscaped ,
176
+ IEnumerable < string > ? excludeSpecsEscaped ,
179
177
FileMatcher fileMatcher ,
180
- object loggingMechanism = null ,
181
- IElementLocation includeLocation = null ,
182
- IElementLocation excludeLocation = null ,
183
- IElementLocation importLocation = null ,
184
- BuildEventContext buildEventContext = null ,
185
- string buildEventFileInfoFullPath = null ,
178
+ object ? loggingMechanism = null ,
179
+ IElementLocation ? includeLocation = null ,
180
+ IElementLocation ? excludeLocation = null ,
181
+ IElementLocation ? importLocation = null ,
182
+ BuildEventContext ? buildEventContext = null ,
183
+ string ? buildEventFileInfoFullPath = null ,
186
184
bool disableExcludeDriveEnumerationWarning = false )
187
185
{
188
186
ErrorUtilities . VerifyThrowInternalLength ( filespecEscaped , nameof ( filespecEscaped ) ) ;
@@ -286,7 +284,7 @@ private static string[] GetFileList(
286
284
default :
287
285
throw new InternalErrorException ( ResourceUtilities . FormatResourceStringIgnoreCodeAndKeyword (
288
286
"UnknownLoggingType" ,
289
- loggingMechanism . GetType ( ) ,
287
+ loggingMechanism ? . GetType ( ) ,
290
288
nameof ( GetFileList ) ) ) ;
291
289
}
292
290
}
@@ -327,7 +325,7 @@ private static string[] GetFileList(
327
325
default :
328
326
throw new InternalErrorException ( ResourceUtilities . FormatResourceStringIgnoreCodeAndKeyword (
329
327
"UnknownLoggingType" ,
330
- loggingMechanism . GetType ( ) ,
328
+ loggingMechanism ? . GetType ( ) ,
331
329
nameof ( GetFileList ) ) ) ;
332
330
}
333
331
}
@@ -338,10 +336,10 @@ private static string[] GetFileList(
338
336
// as a relative path, we will get back a bunch of relative paths.
339
337
// If the filespec started out as an absolute path, we will get
340
338
// back a bunch of absolute paths
341
- ( fileList , _ , _ , string globFailure ) = fileMatcher . GetFiles ( directoryUnescaped , filespecUnescaped , excludeSpecsUnescaped ) ;
339
+ ( fileList , _ , _ , string ? globFailure ) = fileMatcher . GetFiles ( directoryUnescaped , filespecUnescaped , excludeSpecsUnescaped ) ;
342
340
343
- // log globing failure with the present logging mechanism
344
- if ( globFailure != null )
341
+ // log globing failure with the present logging mechanism, skip if there is no logging mechanism
342
+ if ( globFailure != null && loggingMechanism != null )
345
343
{
346
344
switch ( loggingMechanism )
347
345
{
@@ -388,7 +386,7 @@ private static string[] GetFileList(
388
386
return fileList ;
389
387
}
390
388
391
- private static void LogDriveEnumerationWarningWithTargetLoggingContext ( TargetLoggingContext targetLoggingContext , IElementLocation includeLocation , IElementLocation excludeLocation , bool excludeFileSpecIsEmpty , bool disableExcludeDriveEnumerationWarning , string fileSpec )
389
+ private static void LogDriveEnumerationWarningWithTargetLoggingContext ( TargetLoggingContext targetLoggingContext , IElementLocation ? includeLocation , IElementLocation ? excludeLocation , bool excludeFileSpecIsEmpty , bool disableExcludeDriveEnumerationWarning , string fileSpec )
392
390
{
393
391
// Both condition lines are necessary to skip for the first GetFileListEscaped call
394
392
// and reach for the GetFileListUnescaped call when the wildcarded Exclude attribute results
@@ -404,7 +402,7 @@ private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLog
404
402
fileSpec ,
405
403
XMakeAttributes . exclude ,
406
404
XMakeElements . itemGroup ,
407
- excludeLocation . LocationString ) ;
405
+ excludeLocation ? . LocationString ?? "" ) ;
408
406
}
409
407
410
408
// Both conditions are necessary to reach for both GetFileListEscaped calls
@@ -421,7 +419,7 @@ private static void LogDriveEnumerationWarningWithTargetLoggingContext(TargetLog
421
419
}
422
420
}
423
421
424
- private static void LogDriveEnumerationWarningWithLoggingService ( ILoggingService loggingService , IElementLocation includeLocation , BuildEventContext buildEventContext , string buildEventFileInfoFullPath , string filespecUnescaped )
422
+ private static void LogDriveEnumerationWarningWithLoggingService ( ILoggingService loggingService , IElementLocation ? includeLocation , BuildEventContext ? buildEventContext , string ? buildEventFileInfoFullPath , string filespecUnescaped )
425
423
{
426
424
if ( buildEventContext != null && includeLocation != null )
427
425
{
@@ -437,7 +435,7 @@ private static void LogDriveEnumerationWarningWithLoggingService(ILoggingService
437
435
}
438
436
}
439
437
440
- private static void LogDriveEnumerationWarningWithEvaluationLoggingContext ( EvaluationLoggingContext evaluationLoggingContext , IElementLocation importLocation , IElementLocation includeLocation , IElementLocation excludeLocation , bool excludeFileSpecIsEmpty , string filespecUnescaped , string fileSpec )
438
+ private static void LogDriveEnumerationWarningWithEvaluationLoggingContext ( EvaluationLoggingContext evaluationLoggingContext , IElementLocation ? importLocation , IElementLocation ? includeLocation , IElementLocation ? excludeLocation , bool excludeFileSpecIsEmpty , string filespecUnescaped , string fileSpec )
441
439
{
442
440
if ( importLocation != null )
443
441
{
@@ -468,7 +466,7 @@ private static void LogDriveEnumerationWarningWithEvaluationLoggingContext(Evalu
468
466
}
469
467
}
470
468
471
- private static void ThrowDriveEnumerationExceptionWithTargetLoggingContext ( IElementLocation includeLocation , IElementLocation excludeLocation , bool excludeFileSpecIsEmpty , string filespecUnescaped , string fileSpec )
469
+ private static void ThrowDriveEnumerationExceptionWithTargetLoggingContext ( IElementLocation ? includeLocation , IElementLocation ? excludeLocation , bool excludeFileSpecIsEmpty , string filespecUnescaped , string fileSpec )
472
470
{
473
471
// The first condition is necessary to reach for both GetFileListEscaped calls
474
472
// whenever the wildcarded Include attribute results in drive enumeration, and
@@ -501,18 +499,18 @@ private static void ThrowDriveEnumerationExceptionWithTargetLoggingContext(IElem
501
499
}
502
500
}
503
501
504
- private static void ThrowDriveEnumerationExceptionWithLoggingService ( IElementLocation includeLocation , string filespecUnescaped )
502
+ private static void ThrowDriveEnumerationExceptionWithLoggingService ( IElementLocation ? includeLocation , string filespecUnescaped )
505
503
{
506
504
ProjectErrorUtilities . ThrowInvalidProject (
507
505
includeLocation ,
508
506
DriveEnumeratingWildcardMessageResourceName ,
509
507
filespecUnescaped ,
510
508
XMakeAttributes . include ,
511
509
XMakeElements . itemGroup ,
512
- includeLocation . LocationString ) ;
510
+ includeLocation ? . LocationString ?? "" ) ;
513
511
}
514
512
515
- private static void ThrowDriveEnumerationExceptionWithEvaluationLoggingContext ( IElementLocation importLocation , IElementLocation includeLocation , IElementLocation excludeLocation , string filespecUnescaped , string fileSpec , bool excludeFileSpecIsEmpty )
513
+ private static void ThrowDriveEnumerationExceptionWithEvaluationLoggingContext ( IElementLocation ? importLocation , IElementLocation ? includeLocation , IElementLocation ? excludeLocation , string filespecUnescaped , string fileSpec , bool excludeFileSpecIsEmpty )
516
514
{
517
515
if ( importLocation != null )
518
516
{
@@ -565,7 +563,7 @@ private static bool IsValidExclude(string exclude)
565
563
566
564
private static List < Regex > PopulateRegexFromEnvironment ( )
567
565
{
568
- string wildCards = Environment . GetEnvironmentVariable ( "MsBuildSkipEagerWildCardEvaluationRegexes" ) ;
566
+ string ? wildCards = Environment . GetEnvironmentVariable ( "MsBuildSkipEagerWildCardEvaluationRegexes" ) ;
569
567
if ( string . IsNullOrEmpty ( wildCards ) )
570
568
{
571
569
return new List < Regex > ( 0 ) ;
@@ -590,7 +588,7 @@ private static List<Regex> PopulateRegexFromEnvironment()
590
588
591
589
private static bool MatchesLazyWildcard ( string fileSpec )
592
590
{
593
- return _regexMatchCache . Value . GetOrAdd ( fileSpec , file => s_lazyWildCardExpansionRegexes . Any ( regex => regex . IsMatch ( fileSpec ) ) ) ;
591
+ return _regexMatchCache . Value . GetOrAdd ( fileSpec , file => s_lazyWildCardExpansionRegexes ! . Any ( regex => regex . IsMatch ( fileSpec ) ) ) ;
594
592
}
595
593
596
594
/// <summary>
@@ -601,7 +599,7 @@ private static bool MatchesLazyWildcard(string fileSpec)
601
599
/// <param name="filespecsEscaped"></param>
602
600
/// <param name="currentDirectory"></param>
603
601
/// <returns>A Func that will return true IFF its argument matches any of the specified filespecs.</returns>
604
- internal static Func < string , bool > GetFileSpecMatchTester ( IList < string > filespecsEscaped , string currentDirectory )
602
+ internal static Func < string , bool > GetFileSpecMatchTester ( IList < string > filespecsEscaped , string ? currentDirectory )
605
603
{
606
604
var matchers = filespecsEscaped
607
605
. Select ( fs => new Lazy < FileSpecMatcherTester > ( ( ) => FileSpecMatcherTester . Parse ( currentDirectory , fs ) ) )
0 commit comments