-
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 22 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,112 @@ | ||
// 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> | ||
/// Note: This comparer may not have all properties compared. Will be replaced by comprehensive | ||
/// comparer generated 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.Comparers | ||
{ | ||
internal class ArtifactComparer : IComparer<Artifact> | ||
{ | ||
internal static readonly ArtifactComparer Instance = new ArtifactComparer(); | ||
|
||
public int Compare(Artifact left, Artifact right) | ||
{ | ||
if (ComparerHelper.CompareReference(left, right, out int compareResult)) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = MessageComparer.Instance.Compare(left.Description, right.Description); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = ArtifactLocationComparer.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 = ArtifactContentComparer.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; | ||
} | ||
|
||
compareResult = ComparerHelper.CompareDictionary(left.Hashes, right.Hashes); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = left.LastModifiedTimeUtc.CompareTo(right.LastModifiedTimeUtc); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
// Note: There may be other properties are not compared. | ||
return compareResult; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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> | ||
/// Note: This comparer may not have all properties compared. Will be replaced by comprehensive | ||
/// comparer generated 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.Comparers | ||
{ | ||
internal class ArtifactContentComparer : IComparer<ArtifactContent> | ||
{ | ||
internal static readonly ArtifactContentComparer Instance = new ArtifactContentComparer(); | ||
|
||
public int Compare(ArtifactContent left, ArtifactContent right) | ||
{ | ||
if (ComparerHelper.CompareReference(left, right, out int compareResult)) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
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 = MultiformatMessageStringComparer.Instance.Compare(left.Rendered, right.Rendered); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
// Note: There may be other properties are not compared. | ||
return compareResult; | ||
} | ||
} | ||
} |
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> | ||
/// Note: This comparer may not have all properties compared. Will be replaced by comprehensive | ||
/// comparer generated 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.Comparers | ||
{ | ||
internal class ArtifactLocationComparer : IComparer<ArtifactLocation> | ||
{ | ||
internal static readonly ArtifactLocationComparer Instance = new ArtifactLocationComparer(); | ||
|
||
public int Compare(ArtifactLocation left, ArtifactLocation right) | ||
{ | ||
if (ComparerHelper.CompareReference(left, right, out int compareResult)) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = ComparerHelper.CompareUri(left.Uri, right.Uri); | ||
|
||
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 = MessageComparer.Instance.Compare(left.Description, right.Description); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
// Note: There may be other properties are not compared. | ||
return compareResult; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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> | ||
/// Note: This comparer may not have all properties compared. Will be replaced by comprehensive | ||
/// comparer generated 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.Comparers | ||
{ | ||
internal class CodeFlowComparer : IComparer<CodeFlow> | ||
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. was following the same pattern of Sarif SDK's EqualityComparers. The EqualityComparer class is internal and have a public reference in Sarif types, e.g. |
||
{ | ||
internal static readonly CodeFlowComparer Instance = new CodeFlowComparer(); | ||
|
||
public int Compare(CodeFlow left, CodeFlow right) | ||
{ | ||
if (ComparerHelper.CompareReference(left, right, out int compareResult)) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = MessageComparer.Instance.Compare(left.Message, right.Message); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
compareResult = ComparerHelper.CompareList(left.ThreadFlows, right.ThreadFlows, ThreadFlowComparer.Instance); | ||
|
||
if (compareResult != 0) | ||
{ | ||
return compareResult; | ||
} | ||
|
||
// Note: There may be other properties are not compared. | ||
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