File size: 24,922 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor.TestTools.CodeCoverage.CommandLineParser;
using UnityEditor.TestTools.CodeCoverage.Utils;
using UnityEngine;

namespace UnityEditor.TestTools.CodeCoverage
{
    internal class CommandLineManager : CommandLineManagerImplementation
    {
        private static CommandLineManager s_Instance = null;

        public static CommandLineManager instance
        {
            get
            {
                if (s_Instance == null)
                    s_Instance = new CommandLineManager();

                return s_Instance;
            }
        }

        protected CommandLineManager() : base(Environment.GetCommandLineArgs())
        {
        }
    }

    internal class CommandLineManagerImplementation
    {
        public bool runFromCommandLine
        {
            get;
            private set;
        }

        public string coverageResultsPath
        {
            get;
            private set;
        }

        public string coverageHistoryPath
        {
            get;
            private set;
        }

        public bool generateAdditionalMetrics
        {
            get;
            private set;
        }

        public bool generateTestReferences
        {
            get;
            private set;
        }

        public bool generateHTMLReportHistory
        {
            get;
            private set;
        }

        public bool generateHTMLReport
        {
            get;
            private set;
        }

        public bool generateBadgeReport
        {
            get;
            private set;
        }

        public bool generateAdditionalReports
        {
            get;
            private set;
        }

        public bool useProjectSettings
        {
            get;
            private set;
        }

        public bool generateRootEmptyReport
        {
            get;
            private set;
        }

        public bool dontClear
        {
            get;
            private set;
        }

        public bool verbosityLevelSpecified
        {
            get;
            private set;
        }

        public bool assemblyFiltersSpecified
        {
            get;
            private set;
        }

        public bool assemblyFiltersFromFileSpecified
        {
            get;
            private set;
        }

        public bool pathFiltersSpecified
        {
            get;
            private set;
        }

        public bool pathFiltersFromFileSpecified
        {
            get;
            private set;
        }

        public bool pathReplacingSpecified
        {
            get;
            private set;
        }

        public string sourcePaths
        {
            get;
            private set;
        }

        public bool sourcePathsSpecified
        {
            get;
            private set;
        }

        public AssemblyFiltering assemblyFiltering
        {
            get;
            private set;
        }

        public PathFiltering pathFiltering
        {
            get;
            private set;
        }

        public PathReplacing pathReplacing
        {
            get;
            private set;
        }

        public bool runTests
        {
            get;
            private set;
        }

        public bool batchmode
        {
            get;
            private set;
        }

        public bool burstDisabled
        {
            get;
            private set;
        }

        private string m_CoverageOptionsArg;
        private string m_IncludeAssemblies;
        private string m_ExcludeAssemblies;
        private string m_IncludePaths;
        private string m_ExcludePaths;
        private string m_PathReplacePatterns;

        public CommandLineManagerImplementation(string[] commandLineArgs)
        {
            runFromCommandLine = false;
            coverageResultsPath = string.Empty;
            coverageHistoryPath = string.Empty;
            sourcePaths = string.Empty;
            generateAdditionalMetrics = false;
            generateTestReferences = false;
            generateHTMLReportHistory = false;
            generateHTMLReport = false;
            generateBadgeReport = false;
            generateAdditionalReports = false;
            useProjectSettings = false;
            generateRootEmptyReport = false;
            dontClear = false;
            verbosityLevelSpecified = false;
            assemblyFiltersSpecified = false;
            pathFiltersSpecified = false;
            pathReplacingSpecified = false;
            sourcePathsSpecified = false;
            pathFiltersFromFileSpecified = false;
            assemblyFiltering = new AssemblyFiltering();
            pathFiltering = new PathFiltering();
            pathReplacing = new PathReplacing();
            runTests = false;
            batchmode = false;
            burstDisabled = false;

            m_CoverageOptionsArg = string.Empty;
            m_IncludeAssemblies = string.Empty;
            m_ExcludeAssemblies = string.Empty;
            m_IncludePaths = string.Empty;
            m_ExcludePaths = string.Empty;
            m_PathReplacePatterns = string.Empty;

            CommandLineOptionSet optionSet = new CommandLineOptionSet(
                new CommandLineOption("enableCodeCoverage", () => { runFromCommandLine = true; }),
                new CommandLineOption("coverageResultsPath", filePathArg => { SetCoverageResultsPath(filePathArg); }),
                new CommandLineOption("coverageHistoryPath", filePathArg => { SetCoverageHistoryPath(filePathArg); }),
                new CommandLineOption("coverageOptions", optionsArg => { AddCoverageOptions(optionsArg); }),
                new CommandLineOption("runTests", () => { runTests = true; }),
                new CommandLineOption("batchmode", () => { batchmode = true; }),
                new CommandLineOption("-burst-disable-compilation", () => { burstDisabled = true; })
            );
            optionSet.Parse(commandLineArgs);

            ValidateCoverageResultsPath();
            ValidateCoverageHistoryPath();

            if (runFromCommandLine)
                ParseCoverageOptions();
        }

        private void SetCoverageResultsPath(string filePathArg)
        {
            if (coverageResultsPath != string.Empty)
            {
                ResultsLogger.Log(ResultID.Warning_MultipleResultsPaths, coverageResultsPath);
            }
            else
            {
                if (filePathArg != null)
                {
                    coverageResultsPath = CoverageUtils.NormaliseFolderSeparators(filePathArg);
                }
            }
        }

        private void ValidateCoverageResultsPath()
        {
            if (!CoverageUtils.EnsureFolderExists(coverageResultsPath))
                coverageResultsPath = string.Empty;
        }

        private void SetCoverageHistoryPath(string filePathArg)
        {
            if (coverageHistoryPath != string.Empty)
            {
                ResultsLogger.Log(ResultID.Warning_MultipleHistoryPaths, coverageHistoryPath);
            }
            else
            {
                if (filePathArg != null)
                {
                    coverageHistoryPath = CoverageUtils.NormaliseFolderSeparators(filePathArg);
                }
            }
        }

        private void ValidateCoverageHistoryPath()
        {
            if (!CoverageUtils.EnsureFolderExists(coverageHistoryPath))
                coverageHistoryPath = string.Empty;
        }

        private void AddCoverageOptions(string coverageOptionsArg)
        {
            if (coverageOptionsArg != null)
            {
                coverageOptionsArg = coverageOptionsArg.Trim('\'');

                if (coverageOptionsArg != string.Empty)
                {
                    if (m_CoverageOptionsArg == string.Empty)
                    {
                        m_CoverageOptionsArg = coverageOptionsArg;
                    }
                    else
                    {
                        m_CoverageOptionsArg += ";";
                        m_CoverageOptionsArg += coverageOptionsArg;
                    }
                }
            }
        }

        private void ParseCoverageOptions()
        {
            // Make sure there is no trailing quotes at the end of the options
            m_CoverageOptionsArg = m_CoverageOptionsArg.TrimEnd('"');

            // 'sourcePaths' option is moved at the beginning to ensure it is handled first,
            // since it may be needed for other options
            var options = m_CoverageOptionsArg.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            if (options.Count > 1)
            {
                var sourcePath = options.FirstOrDefault(option => option.StartsWith("SOURCEPATHS:", StringComparison.InvariantCultureIgnoreCase));
                if (sourcePath != null)
                {
                    var sourcePathIndex = options.IndexOf(sourcePath);
                    var firstElement = options[0];
                    options[sourcePathIndex] = firstElement;
                    options[0] = sourcePath;
                }
            }

            string[] coverageOptions = options.ToArray();

            foreach (string optionArgsStr in coverageOptions)
            {
                if (optionArgsStr.Length == 0)
                    continue;

                string optionName = optionArgsStr;
                string optionArgs = string.Empty;

                int indexOfColon = optionArgsStr.IndexOf(':');
                if (indexOfColon > 0)
                {
                    optionName = optionArgsStr.Substring(0, indexOfColon);
                    optionArgs = optionArgsStr.Substring(indexOfColon+1);
                }

                switch (optionName.ToUpperInvariant())
                {
                    case "GENERATEADDITIONALMETRICS":
                        generateAdditionalMetrics = true;
                        break;

                    case "GENERATEHTMLREPORTHISTORY":
                        generateHTMLReportHistory = true;
                        break;

                    case "GENERATEHTMLREPORT":
                        generateHTMLReport = true;
                        break;

                    case "GENERATEBADGEREPORT":
                        generateBadgeReport = true;
                        break;

                    case "GENERATEADDITIONALREPORTS":
                        generateAdditionalReports = true;
                        break;

                    case "GENERATEROOTEMPTYREPORT":
                        generateRootEmptyReport = true;
                        break;

                    case "DONTCLEAR":
                        dontClear = true;
                        break;

                    case "GENERATETESTREFERENCES":
                        generateTestReferences = true;
                        break;

                    case "USEPROJECTSETTINGS":
                        if (batchmode)
                            useProjectSettings = true;
                        else
                            ResultsLogger.Log(ResultID.Warning_UseProjectSettingsNonBatchmode);
                        break;

                    case "VERBOSITY":
                        if (optionArgs.Length > 0)
                        {
                            verbosityLevelSpecified = true;

                            switch (optionArgs.ToUpperInvariant())
                            {
                                case "VERBOSE":
                                    ResultsLogger.VerbosityLevel = LogVerbosityLevel.Verbose;
                                    break;
                                case "INFO":
                                    ResultsLogger.VerbosityLevel = LogVerbosityLevel.Info;
                                    break;
                                case "WARNING":
                                    ResultsLogger.VerbosityLevel = LogVerbosityLevel.Warning;
                                    break;
                                case "ERROR":
                                    ResultsLogger.VerbosityLevel = LogVerbosityLevel.Error;
                                    break;
                                case "OFF":
                                    ResultsLogger.VerbosityLevel = LogVerbosityLevel.Off;
                                    break;
                            }
                        }
                        break;

                    case "ASSEMBLYFILTERS":
                        if (optionArgs.Length > 0)
                        {
                            assemblyFiltersSpecified = true;

                            string[] assemblyFilters = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                            ParseAssemblyFilters(assemblyFilters);
                        }
                        break;

                    case "PATHFILTERSFROMFILE":
                        if (optionArgs.Length > 0)
                        {
                            pathFiltersFromFileSpecified = true;
                            ResultsLogger.Log(ResultID.Warning_PathFiltersFromFileDeprecation);

                            if (File.Exists(optionArgs))
                            {
                                try
                                {
                                    ParsePathFilters( GetPathFiltersFromFile(optionArgs) );
                                }
                                catch (Exception e)
                                {
                                    ResultsLogger.Log(ResultID.Warning_FailedToExtractPathFiltersFromFile, e.Message, optionArgs);
                                }
                            }
                        }
                        break;

                    case "PATHFILTERS":
                        if (optionArgs.Length > 0)
                        {
                            string[] pathFilters = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                            ParsePathFilters(pathFilters);
                        }
                        break;

                    case "FILTERSFROMFILE":
                        if (optionArgs.Length > 0)
                        {
                            try
                            {
                                JsonFile jsonFile = GetFiltersFromFile(optionArgs);
                                if (jsonFile != null)
                                {
                                    string[] pathFilters = ConvertToFilterArray(jsonFile.pathsInclude, jsonFile.pathsExclude);
                                    if (pathFilters != null && pathFilters.Length > 0)
                                    {
                                        pathFiltersFromFileSpecified = true;
                                        ParsePathFilters(pathFilters);
                                    }

                                    string[] assemblyFilters = ConvertToFilterArray(jsonFile.assembliesInclude, jsonFile.assembliesExclude);
                                    if (assemblyFilters != null && assemblyFilters.Length > 0)
                                    {
                                        assemblyFiltersFromFileSpecified = true;
                                        ParseAssemblyFilters(assemblyFilters);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                ResultsLogger.Log(ResultID.Warning_FailedToExtractFiltersFromFile, e.Message, optionArgs);
                            }
                        }
                            break;
                        

                    case "PATHREPLACEPATTERNS":
                        if (optionArgs.Length > 0)
                        {
                            pathReplacingSpecified = true;
                            m_PathReplacePatterns = optionArgs;
                        }
                        break;

                    case "SOURCEPATHS":
                        if (optionArgs.Length > 0)
                        {
                            string[] rawSourcePaths = optionArgs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 0; i < rawSourcePaths.Length; ++i)
                            {
                                if (sourcePaths.Length > 0)
                                    sourcePaths += ",";
                                sourcePaths += CoverageUtils.NormaliseFolderSeparators(rawSourcePaths[i]);
                            }

                            if (sourcePaths.Length > 0)
                                sourcePathsSpecified = true;
                        }
                        break;

                    default:
                        ResultsLogger.Log(ResultID.Warning_UnknownCoverageOptionProvided, optionArgsStr);
                        break;
                }
            }

            if (m_IncludeAssemblies.Length == 0)
            {
                // If there are no inlcudedAssemblies specified but there are includedPaths specified
                // then include all project assemblies so path filtering can take precedence over assembly filtering,
                // othewise if there are no includedPaths specified neither then inlcude just the user assemblies (found under the Assets folder)

                if (m_IncludePaths.Length > 0)
                    m_IncludeAssemblies = AssemblyFiltering.GetAllProjectAssembliesString();
                else
                    m_IncludeAssemblies = AssemblyFiltering.GetUserOnlyAssembliesString();
            }

            if (m_ExcludeAssemblies.Length > 0)
                m_ExcludeAssemblies += ",";

            m_ExcludeAssemblies += AssemblyFiltering.kDefaultExcludedAssemblies;

            assemblyFiltering.Parse(m_IncludeAssemblies, m_ExcludeAssemblies);
            pathFiltering.Parse(m_IncludePaths, m_ExcludePaths);
            pathReplacing.Parse(m_PathReplacePatterns);
        }

        private void ParseAssemblyFilters(string[] assemblyFilters)
        {
            for (int i = 0; i < assemblyFilters.Length; ++i)
            {
                string filter = assemblyFilters[i];
                string filterBody = filter.Length > 1 ? filter.Substring(1) : string.Empty;

                if (filter.StartsWith("+", StringComparison.OrdinalIgnoreCase))
                {
                    if (m_IncludeAssemblies.Length > 0)
                        m_IncludeAssemblies += ",";

                    if (filterBody.StartsWith("<", StringComparison.OrdinalIgnoreCase))
                    {
                        if (string.Equals(filterBody, AssemblyFiltering.kAssetsAlias, StringComparison.OrdinalIgnoreCase))
                            m_IncludeAssemblies += AssemblyFiltering.GetUserOnlyAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kAllAlias, StringComparison.OrdinalIgnoreCase))
                            m_IncludeAssemblies += AssemblyFiltering.GetAllProjectAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kPackagesAlias, StringComparison.OrdinalIgnoreCase))
                            m_IncludeAssemblies += AssemblyFiltering.GetPackagesOnlyAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kCoreAlias, StringComparison.OrdinalIgnoreCase))
                            m_IncludeAssemblies += AssemblyFiltering.kCoreAssemblies;
                    }
                    else
                    {
                        m_IncludeAssemblies += filterBody;
                    }
                }
                else if (filter.StartsWith("-", StringComparison.OrdinalIgnoreCase))
                {
                    if (m_ExcludeAssemblies.Length > 0)
                        m_ExcludeAssemblies += ",";

                    if (filterBody.StartsWith("<", StringComparison.OrdinalIgnoreCase))
                    {
                        if (string.Equals(filterBody, AssemblyFiltering.kAssetsAlias, StringComparison.OrdinalIgnoreCase))
                            m_ExcludeAssemblies += AssemblyFiltering.GetUserOnlyAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kAllAlias, StringComparison.OrdinalIgnoreCase))
                            m_ExcludeAssemblies += AssemblyFiltering.GetAllProjectAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kPackagesAlias, StringComparison.OrdinalIgnoreCase))
                            m_ExcludeAssemblies += AssemblyFiltering.GetPackagesOnlyAssembliesString();
                        else if (string.Equals(filterBody, AssemblyFiltering.kCoreAlias, StringComparison.OrdinalIgnoreCase))
                            m_ExcludeAssemblies += AssemblyFiltering.kCoreAssemblies;
                    }
                    else
                    {
                        m_ExcludeAssemblies += filterBody;
                    }
                }
                else
                {
                    ResultsLogger.Log(ResultID.Warning_AssemblyFiltersNotPrefixed, filter);
                }
            }
        }

        private void ParsePathFilters(string[] pathFilters)
        {
            var sources = new string[0];
            if (sourcePathsSpecified)
                sources = sourcePaths.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < pathFilters.Length; ++i)
            {
                string filter = pathFilters[i];
                string filterBody = filter.Length > 1 ? filter.Substring(1) : string.Empty;

                var isRelative = !filterBody.StartsWith("*") && !filterBody.StartsWith("?") && string.IsNullOrEmpty(Path.GetPathRoot(filterBody));
                //If current path is relative - expand it to an absolute path using specified source paths
                if (isRelative && sourcePathsSpecified)
                {
                    string expandedPaths = string.Empty;
                    foreach (var source in sources)
                    {
                        if (expandedPaths.Length > 0)
                            expandedPaths += ",";
                        expandedPaths += CoverageUtils.NormaliseFolderSeparators(Path.Combine(source, filterBody));
                    }
                    filterBody = expandedPaths;
                }

                if (filter.StartsWith("+", StringComparison.OrdinalIgnoreCase))
                {
                    if (m_IncludePaths.Length > 0)
                        m_IncludePaths += ",";
                    m_IncludePaths += filterBody;
                }
                else if (filter.StartsWith("-", StringComparison.OrdinalIgnoreCase))
                {
                    if (m_ExcludePaths.Length > 0)
                        m_ExcludePaths += ",";
                    m_ExcludePaths += filterBody;
                }
                else
                {
                    ResultsLogger.Log(ResultID.Warning_PathFiltersNotPrefixed, filter);
                }
            }

            if (m_IncludePaths.Length > 0 || m_ExcludePaths.Length > 0)
                pathFiltersSpecified = true;
        }

        internal string[] GetPathFiltersFromFile(string path)
        {
            var paths = new List<string>();

            foreach (var line in File.ReadAllLines(path))
            {
                var entry = line.Trim();
                paths.Add(CoverageUtils.NormaliseFolderSeparators(entry));
            }

            return paths.ToArray();
        }

        internal JsonFile GetFiltersFromFile(string path)
        {
            string jsonString = JsonUtils.CleanJsonString(File.ReadAllText(path));
            JsonUtils.ValidateJsonKeys(jsonString);
            JsonFile jsonFile = JsonUtility.FromJson<JsonFile>(jsonString);
            return jsonFile;
        }

        internal string[] ConvertToFilterArray(string[] include, string[] exclude)
        {
            var filtersList = new List<string>();

            if (include != null && include.Length > 0)
            {
                foreach (var filter in include)
                {
                    filtersList.Add($"+{filter}");
                }
            }
            if (exclude != null && exclude.Length > 0)
            {
                foreach (var filter in exclude)
                {
                    filtersList.Add($"-{filter}");
                }
            }
            return filtersList.ToArray();
        }
    }
}