-
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
Add new visitor to get deterministic SARIF log by sorting results #2422
Changes from 6 commits
22ec32b
44a9f46
3c597ff
ca5c356
043079f
ea82e82
3961924
d568f85
07e1b4c
cfebb85
351ef43
9f140e4
0727702
6306faf
f192c36
bb3ce50
196cc0a
9fa0ca7
9d1ce42
305570e
4747ec1
9281b44
314bd53
d37dd18
eb150f7
7c77019
966b7f8
f07f4af
f18e005
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// All Comparer implementations should be replaced by auto-generated codes by JSchema as | ||
/// part of EqualityComparer in a planned comprehensive solution. | ||
/// Tracking by issue: https://github.com/microsoft/jschema/issues/141 | ||
/// </summary> | ||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
internal class ArtifactContentSortingComparer : IComparer<ArtifactContent> | ||
{ | ||
internal static readonly ArtifactContentSortingComparer Instance = new ArtifactContentSortingComparer(); | ||
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. 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. it's a public (internal) member. It should match naming convention: "All visible static member names are pascal cased." |
||
|
||
public int Compare(ArtifactContent left, ArtifactContent right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (left == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
int compareResult = 0; | ||
compareResult = string.Compare(left.Text, right.Text); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.Binary, right.Binary); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = MultiformatMessageStringSortingComparer.Instance.Compare(left.Rendered, right.Rendered); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
return compareResult; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// All Comparer implementations should be replaced by auto-generated codes by JSchema as | ||
/// part of EqualityComparer in a planned comprehensive solution. | ||
/// Tracking by issue: https://github.com/microsoft/jschema/issues/141 | ||
/// </summary> | ||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
internal class ArtifactLocationSortingComparer : IComparer<ArtifactLocation> | ||
{ | ||
internal static readonly ArtifactLocationSortingComparer Instance = new ArtifactLocationSortingComparer(); | ||
|
||
public int Compare(ArtifactLocation left, ArtifactLocation right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (left == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
int compareResult = 0; | ||
if (ReferenceEquals(left.Uri, right.Uri)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (left.Uri == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right.Uri == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
compareResult = string.Compare(left.Uri.OriginalString, right.Uri.OriginalString); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.UriBaseId, right.UriBaseId); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.Index.CompareTo(right.Index); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = MessageSortingComparer.Instance.Compare(left.Description, right.Description); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
return compareResult; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
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. I see several instances where using System.Linq is greyed out in VS, can you double check where this is actually needed and remove any unnecessary? #Resolved 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. It is required in this file, checked other files and removed the unnecessary using. |
||
|
||
/// <summary> | ||
/// All Comparer implementations should be replaced by auto-generated codes by JSchema as | ||
/// part of EqualityComparer in a planned comprehensive solution. | ||
/// Tracking by issue: https://github.com/microsoft/jschema/issues/141 | ||
/// </summary> | ||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
internal class ArtifactSortingComparer : IComparer<Artifact> | ||
{ | ||
internal static readonly ArtifactSortingComparer Instance = new ArtifactSortingComparer(); | ||
|
||
public int Compare(Artifact left, Artifact right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (left == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
int compareResult = 0; | ||
compareResult = MessageSortingComparer.Instance.Compare(left.Description, right.Description); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = ArtifactLocationSortingComparer.Instance.Compare(left.Location, right.Location); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.ParentIndex.CompareTo(right.ParentIndex); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.Offset.CompareTo(right.Offset); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.Length.CompareTo(right.Length); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.Roles.CompareTo(right.Roles); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.MimeType, right.MimeType); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = ArtifactContentSortingComparer.Instance.Compare(left.Contents, right.Contents); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.Encoding, right.Encoding); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.SourceLanguage, right.SourceLanguage); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
if (!object.ReferenceEquals(left.Hashes, right.Hashes)) | ||
{ | ||
if (left.Hashes == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right.Hashes == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
compareResult = left.Hashes.Count.CompareTo(right.Hashes.Count); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
for (int i = 0; i < left.Hashes.Count; i++) | ||
{ | ||
compareResult = string.Compare(left.Hashes.ElementAt(i).Key, right.Hashes.ElementAt(i).Key); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = string.Compare(left.Hashes.ElementAt(i).Value, right.Hashes.ElementAt(i).Value); | ||
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. 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. fixed. new implementation in ComparerHelper.CompareDictionary(...) |
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
} | ||
} | ||
|
||
compareResult = left.LastModifiedTimeUtc.CompareTo(right.LastModifiedTimeUtc); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
return compareResult; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// All Comparer implementations should be replaced by auto-generated codes by JSchema as | ||
/// part of EqualityComparer in a planned comprehensive solution. | ||
/// Tracking by issue: https://github.com/microsoft/jschema/issues/141 | ||
/// </summary> | ||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
internal class CodeFlowSortingComparer : IComparer<CodeFlow> | ||
{ | ||
internal static readonly CodeFlowSortingComparer Instance = new CodeFlowSortingComparer(); | ||
|
||
public int Compare(CodeFlow left, CodeFlow right) | ||
{ | ||
if (ReferenceEquals(left, right)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (left == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
int compareResult = 0; | ||
|
||
compareResult = MessageSortingComparer.Instance.Compare(left.Message, right.Message); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
if (!object.ReferenceEquals(left.ThreadFlows, right.ThreadFlows)) | ||
{ | ||
|
||
if (left.ThreadFlows == null) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (right.ThreadFlows == null) | ||
{ | ||
return 1; | ||
} | ||
|
||
compareResult = left.ThreadFlows.Count.CompareTo(right.ThreadFlows.Count); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
for (int index_1 = 0; index_1 < left.ThreadFlows.Count; ++index_1) | ||
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. |
||
{ | ||
compareResult = ThreadFlowSortingComparer.Instance.Compare(left.ThreadFlows[index_1], right.ThreadFlows[index_1]); | ||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
} | ||
} | ||
|
||
return compareResult; | ||
} | ||
} | ||
} |
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.
Why isn't this in a base class? #Pending
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.
Future work?
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.
open issue #2443 for tracking