-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduced files array build #1191
Changes from all commits
e56f46e
24fc6be
6de4aee
c296771
9b7a6c4
b9b5a15
7ec751b
346bc1d
0c3e250
5208c43
5a29dd7
43480b0
8d505f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using Microsoft.CodeAnalysis.Sarif.Writers; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Converters | ||
{ | ||
|
@@ -85,14 +84,6 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
} | ||
} | ||
|
||
var tool = new Tool | ||
{ | ||
Name = "Fortify" | ||
}; | ||
|
||
var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert); | ||
Dictionary<string, FileData> fileDictionary = fileInfoFactory.Create(results); | ||
|
||
var run = new Run() | ||
{ | ||
Id = new RunAutomationDetails | ||
|
@@ -102,16 +93,10 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
Text = runDescription | ||
} | ||
}, | ||
Tool = tool | ||
Tool = new Tool { Name = "Fortify" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, here's a case where you can't use the format for the tool name, because there are two formats. Since you can't do it always, I think you should never do it; it's more or less an accident if the format name happens to match the tool name. Besides, the tool's preferred name might not even be a valid identifier (e.g., "Clang Analyzer"). I'll stop harping on this now. #Resolved |
||
}; | ||
|
||
output.Initialize(run); | ||
|
||
if (fileDictionary != null && fileDictionary.Count > 0) { output.WriteFiles(fileDictionary); } | ||
|
||
output.OpenResults(); | ||
output.WriteResults(results); | ||
output.CloseResults(); | ||
PersistResults(output, results, run); | ||
} | ||
|
||
/// <summary>Converts a Fortify result to a static analysis results interchange format result.</summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,8 @@ internal class FortifyFprConverter : ToolFileConverterBase | |
private string _automationId; | ||
private string _originalUriBasePath; | ||
private List<Result> _results = new List<Result>(); | ||
private List<Notification> _toolNotifications; | ||
private Dictionary<string, FileData> _fileDictionary; | ||
private Dictionary<string, IRule> _ruleDictionary; | ||
private Dictionary<string, Rule> _ruleDictionary; | ||
private Dictionary<ThreadFlowLocation, string> _tflToNodeIdDictionary; | ||
private Dictionary<ThreadFlowLocation, string> _tflToSnippetIdDictionary; | ||
private Dictionary<Location, string> _locationToSnippetIdDictionary; | ||
|
@@ -50,9 +49,8 @@ public FortifyFprConverter() | |
_strings = new FortifyFprStrings(_nameTable); | ||
|
||
_results = new List<Result>(); | ||
_toolNotifications = new List<Notification>(); | ||
_fileDictionary = new Dictionary<string, FileData>(); | ||
_ruleDictionary = new Dictionary<string, IRule>(); | ||
_ruleDictionary = new Dictionary<string, Rule>(); | ||
_tflToNodeIdDictionary = new Dictionary<ThreadFlowLocation, string>(); | ||
_tflToSnippetIdDictionary = new Dictionary<ThreadFlowLocation, string>(); | ||
_locationToSnippetIdDictionary = new Dictionary<Location, string>(); | ||
|
@@ -89,8 +87,8 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
}; | ||
|
||
_invocation = new Invocation(); | ||
_invocation.ToolNotifications = new List<Notification>(); | ||
_results.Clear(); | ||
_toolNotifications.Clear(); | ||
_fileDictionary.Clear(); | ||
_ruleDictionary.Clear(); | ||
_tflToNodeIdDictionary.Clear(); | ||
|
@@ -116,7 +114,8 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
InstanceId = _automationId + "/" | ||
}, | ||
Tool = tool, | ||
Invocations = new[] { _invocation } | ||
Invocations = new[] { _invocation }, | ||
Resources = new Resources { Rules = _ruleDictionary} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean you'll emit
if the dictionary is empty, rather than omitting the "rules" object? (In fact, rather than omitting
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our deserialization logic can elide the resources object in cases where its contained strings and rules are empty, is my thought. this keeps the initialization logic in one place. eventually, we should consider having the OM initialize core objects automatically, to make object creation more concise. will require building out the ShouldSerializeXXX helpers exhaustively. All this is one reason I built that helper that automatically hydrates the OM with all possible items. This will help comprehensively test the helpers described above. In reply to: 244521205 [](ancestors = 244521205) |
||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(_originalUriBasePath)) | ||
|
@@ -128,28 +127,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
}; | ||
} | ||
|
||
output.Initialize(run); | ||
|
||
(output as ResultLogJsonWriter).WriteInvocations(run.Invocations); | ||
|
||
if (_fileDictionary.Any()) | ||
{ | ||
output.WriteFiles(_fileDictionary); | ||
} | ||
|
||
output.OpenResults(); | ||
output.WriteResults(_results); | ||
output.CloseResults(); | ||
|
||
if (_ruleDictionary.Any()) | ||
{ | ||
output.WriteRules(_ruleDictionary); | ||
} | ||
|
||
if (_toolNotifications.Any()) | ||
{ | ||
output.WriteToolNotifications(_toolNotifications); | ||
} | ||
PersistResults(output, _results, run); | ||
} | ||
|
||
private void ParseFprFile(Stream input) | ||
|
@@ -871,7 +849,7 @@ private void ParseErrors() | |
string errorCode = _reader.GetAttribute(_strings.CodeAttribute); | ||
string message = _reader.ReadElementContentAsString(); | ||
|
||
_toolNotifications.Add(new Notification | ||
_invocation.ToolNotifications.Add(new Notification | ||
{ | ||
Id = errorCode, | ||
Level = NotificationLevel.Error, | ||
|
@@ -930,7 +908,7 @@ private void AddMessagesToResults() | |
{ | ||
foreach (Result result in _results) | ||
{ | ||
IRule rule; | ||
Rule rule; | ||
if (_ruleDictionary.TryGetValue(result.RuleId, out rule)) | ||
{ | ||
Message message = rule.ShortDescription ?? rule.FullDescription; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
using System.Reflection; | ||
using System.Xml; | ||
using System.Xml.Schema; | ||
using Microsoft.CodeAnalysis.Sarif.Writers; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Converters | ||
{ | ||
|
@@ -53,46 +52,27 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm | |
reader.ResultRead += (FxCopLogReader.Context current) => { results.Add(CreateResult(current)); }; | ||
reader.Read(context, input); | ||
|
||
Tool tool = new Tool | ||
{ | ||
Name = "FxCop" | ||
}; | ||
|
||
var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert); | ||
Dictionary<string, FileData> fileDictionary = fileInfoFactory.Create(results); | ||
|
||
var run = new Run() | ||
{ | ||
Tool = tool | ||
Tool = new Tool { Name = "FxCop"} | ||
}; | ||
|
||
output.Initialize(run); | ||
|
||
if (fileDictionary != null && fileDictionary.Any()) | ||
{ | ||
output.WriteFiles(fileDictionary); | ||
} | ||
|
||
if (LogicalLocations != null && LogicalLocations.Any()) | ||
{ | ||
output.WriteLogicalLocations(LogicalLocations); | ||
} | ||
|
||
output.OpenResults(); | ||
output.WriteResults(results); | ||
output.CloseResults(); | ||
|
||
if (rules.Count > 0) | ||
{ | ||
IDictionary<string, IRule> rulesDictionary = new Dictionary<string, IRule>(); | ||
IDictionary<string, Rule> rulesDictionary = new Dictionary<string, Rule>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes! Step by step... #ByDesign |
||
|
||
foreach (Rule rule in rules) | ||
{ | ||
rulesDictionary[rule.Id] = rule; | ||
} | ||
|
||
output.WriteRules(rulesDictionary); | ||
run.Resources = new Resources | ||
{ | ||
Rules = rulesDictionary | ||
}; | ||
} | ||
|
||
PersistResults(output, results, run); | ||
} | ||
|
||
internal Rule CreateRule(FxCopLogReader.Context context) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you also mean to remove the local variable
tool
? #ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is marked "Resolved" but the local variable
tool
on Line 67 is still there.In reply to: 244519901 [](ancestors = 244519901)