Skip to content

Commit eea9bb9

Browse files
committed
Adding throw if non-excpted issues occur
1 parent 1ddca9c commit eea9bb9

14 files changed

+517
-51
lines changed

tools/StaticAnalysis/AnalysisLogger.cs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,30 @@ namespace StaticAnalysis
2626
public abstract class AnalysisLogger
2727
{
2828
string _baseDirectory;
29+
string _exceptionsDirectory;
2930

3031
/// <summary>
3132
/// Create an analysis logger that will write reports to the given directory
3233
/// </summary>
33-
/// <param name="baseDirectory"></param>
34+
/// <param name="baseDirectory">The base directory for reports</param>
35+
/// <param name="exceptionsDirectory">The directory containing exceptions form static analysis rules.</param>
36+
public AnalysisLogger(string baseDirectory, string exceptionsDirectory)
37+
{
38+
_baseDirectory = baseDirectory;
39+
_exceptionsDirectory = exceptionsDirectory;
40+
}
41+
42+
/// <summary>
43+
/// Create an analysis logger without exceptions
44+
/// </summary>
45+
/// <param name="baseDirectory">The base directory for reports</param>
3446
public AnalysisLogger(string baseDirectory)
3547
{
3648
_baseDirectory = baseDirectory;
49+
_exceptionsDirectory = null;
3750
}
3851

39-
IList<ReportLogger> _loggers = new List<ReportLogger>();
52+
IList<ReportLogger> _loggers = new List<ReportLogger>();
4053
protected virtual IList<ReportLogger> Loggers { get { return _loggers; } }
4154

4255
/// <summary>
@@ -94,7 +107,19 @@ public virtual void WriteWarning(string format, params object[] args)
94107
}
95108

96109
var filePath = Path.Combine(_baseDirectory, fileName);
97-
var logger = new ReportLogger<T>(filePath, this);
110+
ReportLogger<T> logger;
111+
if (_exceptionsDirectory != null && Directory.Exists(_exceptionsDirectory))
112+
{
113+
var exceptionsPath = Path.Combine(_exceptionsDirectory, fileName);
114+
WriteWarning("Using exceptions file {0}", exceptionsPath);
115+
logger = new ReportLogger<T>(filePath, exceptionsPath, this);
116+
}
117+
else
118+
{
119+
WriteWarning("Using no exceptions file.");
120+
logger = new ReportLogger<T>(filePath, this);
121+
}
122+
98123
Loggers.Add(logger);
99124
return logger;
100125
}
@@ -116,5 +141,31 @@ public void WriteReports()
116141
WriteReport(logger.FileName, reportText.ToString());
117142
}
118143
}
144+
145+
public void CheckForIssues(int maxSeverity)
146+
{
147+
var hasErrors = false;
148+
foreach (var logger in Loggers.Where(l => l.Records.Any( r => r.Severity < maxSeverity)))
149+
{
150+
hasErrors = true;
151+
StringBuilder errorText = new StringBuilder();
152+
errorText.AppendLine(logger.Records.First().PrintHeaders());
153+
foreach (var reportRecord in logger.Records)
154+
{
155+
errorText.AppendLine(reportRecord.FormatRecord());
156+
}
157+
158+
WriteError("{0} Errors", logger.FileName);
159+
WriteError(errorText.ToString());
160+
WriteError("");
161+
}
162+
163+
if (hasErrors)
164+
{
165+
throw new InvalidOperationException(string.Format("One or more errors occurred in validation. " +
166+
"See the analysis repots at {0} for details",
167+
_baseDirectory));
168+
}
169+
}
119170
}
120171
}

tools/StaticAnalysis/ConsoleLogger.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ namespace StaticAnalysis
2323
public class ConsoleLogger : AnalysisLogger
2424
{
2525

26+
public ConsoleLogger(string baseDirectory, string exceptionsDirectory)
27+
: base(baseDirectory, exceptionsDirectory)
28+
{
29+
}
30+
2631
public ConsoleLogger(string baseDirectory)
2732
: base(baseDirectory)
2833
{
2934
}
30-
3135
public override void WriteError(string error)
3236
{
3337
Console.WriteLine("### ERROR {0}", error);

tools/StaticAnalysis/DependencyAnalyzer/AssemblyVersionConflict.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ public IReportRecord Parse(string line)
100100
{
101101
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\"";
102102
var match = Regex.Match(line, matcher);
103-
if (!match.Success || match.Groups.Count < 9)
103+
if (!match.Success || match.Groups.Count < 10)
104104
{
105105
throw new InvalidOperationException(string.Format("Could not parse '{0}' as AssemblyVersionConflict record", line));
106106
}
107107

108-
Directory = match.Groups[0].Value;
109-
AssemblyName = match.Groups[1].Value;
110-
ExpectedVersion = Version.Parse(match.Groups[2].Value);
111-
ActualVersion = Version.Parse(match.Groups[3].Value);
112-
ParentAssembly = match.Groups[4].Value;
113-
Severity = int.Parse(match.Groups[5].Value);
114-
ProblemId = int.Parse(match.Groups[6].Value);
115-
Description = match.Groups[7].Value;
116-
Remediation = match.Groups[8].Value;
108+
Directory = match.Groups[1].Value;
109+
AssemblyName = match.Groups[2].Value;
110+
ExpectedVersion = Version.Parse(match.Groups[3].Value);
111+
ActualVersion = Version.Parse(match.Groups[4].Value);
112+
ParentAssembly = match.Groups[5].Value;
113+
Severity = int.Parse(match.Groups[6].Value);
114+
ProblemId = int.Parse(match.Groups[7].Value);
115+
Description = match.Groups[8].Value;
116+
Remediation = match.Groups[9].Value;
117117
return this;
118118
}
119119

tools/StaticAnalysis/DependencyAnalyzer/ExtraAssembly.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ public IReportRecord Parse(string line)
7171
{
7272
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\"";
7373
var match = Regex.Match(line, matcher);
74-
if (!match.Success || match.Groups.Count < 6)
74+
if (!match.Success || match.Groups.Count < 7)
7575
{
7676
throw new InvalidOperationException(string.Format("Could not parse '{0}' as ExtraAssembly record", line));
7777
}
7878

79-
Directory = match.Groups[0].Value;
80-
AssemblyName = match.Groups[1].Value;
81-
Severity = int.Parse(match.Groups[2].Value);
82-
ProblemId = int.Parse(match.Groups[3].Value);
83-
Description = match.Groups[4].Value;
84-
Remediation = match.Groups[5].Value;
79+
Directory = match.Groups[1].Value;
80+
AssemblyName = match.Groups[2].Value;
81+
Severity = int.Parse(match.Groups[3].Value);
82+
ProblemId = int.Parse(match.Groups[4].Value);
83+
Description = match.Groups[5].Value;
84+
Remediation = match.Groups[6].Value;
8585
return this;
8686
}
8787
}

tools/StaticAnalysis/DependencyAnalyzer/MissingAssembly.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ public IReportRecord Parse(string line)
6565
{
6666
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\"";
6767
var match = Regex.Match(line, matcher);
68-
if (!match.Success || match.Groups.Count < 8)
68+
if (!match.Success || match.Groups.Count < 9)
6969
{
7070
throw new InvalidOperationException(string.Format("Could not parse '{0}' as MissingAssembly record", line));
7171
}
7272

73-
Directory = match.Groups[0].Value;
74-
AssemblyName = match.Groups[1].Value;
75-
AssemblyVersion = match.Groups[2].Value;
76-
ReferencingAssembly = match.Groups[3].Value;
77-
Severity = int.Parse(match.Groups[4].Value);
78-
ProblemId = int.Parse(match.Groups[5].Value);
79-
Description = match.Groups[6].Value;
80-
Remediation = match.Groups[7].Value;
73+
Directory = match.Groups[1].Value;
74+
AssemblyName = match.Groups[2].Value;
75+
AssemblyVersion = match.Groups[3].Value;
76+
ReferencingAssembly = match.Groups[4].Value;
77+
Severity = int.Parse(match.Groups[5].Value);
78+
ProblemId = int.Parse(match.Groups[6].Value);
79+
Description = match.Groups[7].Value;
80+
Remediation = match.Groups[8].Value;
8181
return this;
8282
}
8383

tools/StaticAnalysis/DependencyAnalyzer/SharedAssemblyConflict.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ public IReportRecord Parse(string line)
6666
{
6767
var matcher = "\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\",\"([^\"]+)\"";
6868
var match = Regex.Match(line, matcher);
69-
if (!match.Success || match.Groups.Count < 7)
69+
if (!match.Success || match.Groups.Count < 8)
7070
{
7171
throw new InvalidOperationException(string.Format("Could not parse '{0}' as SharedAssemblyConflict record", line));
7272
}
7373

74-
AssemblyName = match.Groups[1].Value;
75-
AssemblyVersion = Version.Parse(match.Groups[2].Value);
76-
Severity = int.Parse(match.Groups[3].Value);
77-
ProblemId = int.Parse(match.Groups[4].Value);
78-
Description = match.Groups[5].Value;
79-
Remediation = match.Groups[6].Value;
74+
AssemblyName = match.Groups[2].Value;
75+
AssemblyVersion = Version.Parse(match.Groups[3].Value);
76+
Severity = int.Parse(match.Groups[4].Value);
77+
ProblemId = int.Parse(match.Groups[5].Value);
78+
Description = match.Groups[6].Value;
79+
Remediation = match.Groups[7].Value;
8080
return this;
8181
}
8282

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Directory","AssemblyName","Expected Version","Actual Version","Parent Assembly","Severity","ProblemId","Description","Remediation"
2+
"src\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Batch","Microsoft.Data.OData","5.6.2.0","5.6.4.0","Microsoft.Azure.Batch","1","1010","Assembly Microsoft.Data.OData version 5.6.2.0 referenced from Microsoft.Azure.Batch.dll does not match assembly version on disk: 5.6.4.0","Update any references to version 5.6.2.0 of assembly Microsoft.Data.OData"
3+
"src\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Batch","Microsoft.WindowsAzure.Storage","4.3.0.0","6.1.0.0","Microsoft.Azure.Batch","1","1010","Assembly Microsoft.WindowsAzure.Storage version 4.3.0.0 referenced from Microsoft.Azure.Batch.dll does not match assembly version on disk: 6.1.0.0","Update any references to version 4.3.0.0 of assembly Microsoft.WindowsAzure.Storage"
4+
"src\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.RedisCache","Microsoft.WindowsAzure.Storage","6.0.0.0","6.1.0.0","Microsoft.Azure.Insights","1","1010","Assembly Microsoft.WindowsAzure.Storage version 6.0.0.0 referenced from Microsoft.Azure.Insights.dll does not match assembly version on disk: 6.1.0.0","Update any references to version 6.0.0.0 of assembly Microsoft.WindowsAzure.Storage"
5+
"src\Package\Debug\ServiceManagement\Azure\HDInsight","Microsoft.WindowsAzure.Storage","3.0.3.0","6.0.0.0","Microsoft.Hadoop.Client","1","1010","Assembly Microsoft.WindowsAzure.Storage version 3.0.3.0 referenced from Microsoft.Hadoop.Client.dll does not match assembly version on disk: 6.0.0.0","Update any references to version 3.0.3.0 of assembly Microsoft.WindowsAzure.Storage"

0 commit comments

Comments
 (0)