forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGendarmeValidationRule.cs
More file actions
95 lines (88 loc) · 3.26 KB
/
GendarmeValidationRule.cs
File metadata and controls
95 lines (88 loc) · 3.26 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEditor.Scripting;
using UnityEditor.Scripting.Compilers;
using UnityEditor.Utils;
internal abstract class GendarmeValidationRule : IValidationRule
{
private readonly string _gendarmeExePath;
[CompilerGenerated]
private static Func<string, string, string> <>f__am$cache0;
protected GendarmeValidationRule(string gendarmeExePath)
{
this._gendarmeExePath = gendarmeExePath;
}
protected string BuildGendarmeCommandLineArguments(IEnumerable<string> userAssemblies)
{
GendarmeOptions options = this.ConfigureGendarme(userAssemblies);
if ((options.UserAssemblies == null) || (options.UserAssemblies.Length == 0))
{
return null;
}
List<string> list = new List<string> {
"--config " + options.ConfigFilePath,
"--set " + options.RuleSet
};
list.AddRange(options.UserAssemblies);
if (<>f__am$cache0 == null)
{
<>f__am$cache0 = (agg, i) => agg + " " + i;
}
return Enumerable.Aggregate<string>(list, <>f__am$cache0);
}
protected abstract GendarmeOptions ConfigureGendarme(IEnumerable<string> userAssemblies);
private static ManagedProgram ManagedProgramFor(string exe, string arguments) =>
new ManagedProgram(MonoInstallationFinder.GetMonoInstallation("MonoBleedingEdge"), null, exe, arguments, false, null);
private static bool StartManagedProgram(string exe, string arguments, CompilerOutputParserBase parser, ref IEnumerable<CompilerMessage> compilerMessages)
{
using (ManagedProgram program = ManagedProgramFor(exe, arguments))
{
program.LogProcessStartInfo();
try
{
program.Start();
}
catch
{
throw new Exception("Could not start " + exe);
}
program.WaitForExit();
if (program.ExitCode == 0)
{
return true;
}
compilerMessages = parser.Parse(program.GetErrorOutput(), program.GetStandardOutput(), true);
}
return false;
}
public ValidationResult Validate(IEnumerable<string> userAssemblies, params object[] options)
{
string arguments = this.BuildGendarmeCommandLineArguments(userAssemblies);
ValidationResult result = new ValidationResult {
Success = true,
Rule = this,
CompilerMessages = null
};
try
{
result.Success = StartManagedProgram(this._gendarmeExePath, arguments, new GendarmeOutputParser(), ref result.CompilerMessages);
}
catch (Exception exception)
{
result.Success = false;
CompilerMessage[] messageArray1 = new CompilerMessage[1];
CompilerMessage message = new CompilerMessage {
file = "Exception",
message = exception.Message,
line = 0,
column = 0,
type = CompilerMessageType.Error
};
messageArray1[0] = message;
result.CompilerMessages = messageArray1;
}
return result;
}
}