-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathApplyPolicyCommand.cs
More file actions
61 lines (45 loc) · 1.85 KB
/
Copy pathApplyPolicyCommand.cs
File metadata and controls
61 lines (45 loc) · 1.85 KB
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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Sarif.Driver;
namespace Microsoft.CodeAnalysis.Sarif.Multitool
{
public class ApplyPolicyCommand : CommandBase
{
private readonly IFileSystem _fileSystem;
public ApplyPolicyCommand(IFileSystem fileSystem = null)
{
_fileSystem = fileSystem ?? Sarif.FileSystem.Instance;
}
public int Run(ApplyPolicyOptions options)
{
try
{
Console.WriteLine($"Applying policy '{options.InputFilePath}' => '{options.OutputFilePath}'...");
var w = Stopwatch.StartNew();
bool valid = ValidateOptions(options);
if (!valid) { return FAILURE; }
SarifLog actualLog = ReadSarifFile<SarifLog>(_fileSystem, options.InputFilePath);
actualLog.ApplyPolicies();
string fileName = CommandUtilities.GetTransformedOutputFileName(FileSystem, options);
WriteSarifFile(_fileSystem, actualLog, fileName, options.Minify);
w.Stop();
Console.WriteLine($"Rewrite completed in {w.Elapsed}.");
}
catch (Exception ex)
{
Console.WriteLine(ex);
return FAILURE;
}
return SUCCESS;
}
private bool ValidateOptions(ApplyPolicyOptions applyPolicyOptions)
{
bool valid = true;
valid &= applyPolicyOptions.Validate();
valid &= DriverUtilities.ReportWhetherOutputFileCanBeCreated(applyPolicyOptions.OutputFilePath, applyPolicyOptions.ForceOverwrite, _fileSystem);
return valid;
}
}
}