From 0a4b77b7abf1773ac8aeba2731de7201b4b78a9a Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Thu, 6 Jan 2022 23:03:58 -0800 Subject: [PATCH 1/9] Fix empty AutomationDetails node --- src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs | 11 +++++++---- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 13 +++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs index dae21f7d5..280c35f5c 100644 --- a/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs @@ -363,14 +363,17 @@ private void InitializeOutputFile(TOptions analyzeOptions, TContext context, ISe SarifLogger sarifLogger; - _run = new Run() + _run = new Run(); + + if (!string.IsNullOrWhiteSpace(analyzeOptions.AutomationId) + || !string.IsNullOrWhiteSpace(analyzeOptions.AutomationGuid)) { - AutomationDetails = new RunAutomationDetails + _run.AutomationDetails = new RunAutomationDetails { Id = analyzeOptions.AutomationId, Guid = analyzeOptions.AutomationGuid - } - }; + }; + } if (analyzeOptions.SarifOutputVersion != SarifVersion.OneZeroZero) { diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index db8b0384d..dbe7564ca 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -7,9 +7,7 @@ using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.InteropServices; -using System.Security; using System.Threading.Channels; using System.Threading.Tasks; @@ -660,14 +658,17 @@ private void InitializeOutputFile(TOptions analyzeOptions, TContext context) SarifLogger sarifLogger; - _run = new Run() + _run = new Run(); + + if (!string.IsNullOrWhiteSpace(analyzeOptions.AutomationId) + || !string.IsNullOrWhiteSpace(analyzeOptions.AutomationGuid)) { - AutomationDetails = new RunAutomationDetails + _run.AutomationDetails = new RunAutomationDetails { Id = analyzeOptions.AutomationId, Guid = analyzeOptions.AutomationGuid - } - }; + }; + } if (analyzeOptions.SarifOutputVersion != SarifVersion.OneZeroZero) { From f3540a3cecf4f6de034554e27ec5c0abec940645 Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Thu, 6 Jan 2022 23:51:09 -0800 Subject: [PATCH 2/9] set the order to the exact order before issue happened --- src/Sarif/Autogenerated/ReportingDescriptor.cs | 15 ++++++++++++++- .../NotYetAutoGenerated/ReportingDescriptor.cs | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Sarif/Autogenerated/ReportingDescriptor.cs b/src/Sarif/Autogenerated/ReportingDescriptor.cs index 3957c2c93..8cf310470 100644 --- a/src/Sarif/Autogenerated/ReportingDescriptor.cs +++ b/src/Sarif/Autogenerated/ReportingDescriptor.cs @@ -41,66 +41,77 @@ public SarifNodeKind SarifNodeKind /// /// A stable, opaque identifier for the report. /// + [JsonProperty(Order = 1)] [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)] public virtual string Id { get; set; } /// /// An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 8)] [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedIds { get; set; } /// /// A unique identifer for the reporting descriptor in the form of a GUID. /// + [JsonProperty(Order = 9)] [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false)] public virtual string Guid { get; set; } /// /// An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 10)] [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedGuids { get; set; } /// /// A report identifier that is understandable to an end user. /// + [JsonProperty(Order = 7)] [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false)] public virtual string Name { get; set; } /// /// An array of readable identifiers by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 11)] [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedNames { get; set; } /// /// A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text. /// + [JsonProperty(Order = 6)] [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString ShortDescription { get; set; } /// /// A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result. /// + [JsonProperty(Order = 2)] [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString FullDescription { get; set; } /// /// A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. /// + [JsonProperty(Order = 5)] [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false)] public virtual IDictionary MessageStrings { get; set; } /// /// Default reporting configuration information. /// + [JsonProperty(Order = 12)] [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false)] public virtual ReportingConfiguration DefaultConfiguration { get; set; } /// /// A URI where the primary documentation for the report can be found. /// + [JsonProperty(Order = 3)] [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false)] [JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))] public virtual Uri HelpUri { get; set; } @@ -108,6 +119,7 @@ public SarifNodeKind SarifNodeKind /// /// Provides the primary documentation for the report, useful when there is no online documentation. /// + [JsonProperty(Order = 4)] [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString Help { get; set; } @@ -115,12 +127,13 @@ public SarifNodeKind SarifNodeKind /// An array of objects that describe relationships between this reporting descriptor and others. /// [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [JsonProperty(Order = 13, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] public virtual IList Relationships { get; set; } /// /// Key/value pairs that provide additional information about the report. /// + [JsonProperty(Order = 14)] [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)] internal override IDictionary Properties { get; set; } diff --git a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs index 3957c2c93..8cf310470 100644 --- a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs +++ b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs @@ -41,66 +41,77 @@ public SarifNodeKind SarifNodeKind /// /// A stable, opaque identifier for the report. /// + [JsonProperty(Order = 1)] [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)] public virtual string Id { get; set; } /// /// An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 8)] [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedIds { get; set; } /// /// A unique identifer for the reporting descriptor in the form of a GUID. /// + [JsonProperty(Order = 9)] [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false)] public virtual string Guid { get; set; } /// /// An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 10)] [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedGuids { get; set; } /// /// A report identifier that is understandable to an end user. /// + [JsonProperty(Order = 7)] [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false)] public virtual string Name { get; set; } /// /// An array of readable identifiers by which this report was known in some previous version of the analysis tool. /// + [JsonProperty(Order = 11)] [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false)] public virtual IList DeprecatedNames { get; set; } /// /// A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text. /// + [JsonProperty(Order = 6)] [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString ShortDescription { get; set; } /// /// A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result. /// + [JsonProperty(Order = 2)] [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString FullDescription { get; set; } /// /// A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. /// + [JsonProperty(Order = 5)] [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false)] public virtual IDictionary MessageStrings { get; set; } /// /// Default reporting configuration information. /// + [JsonProperty(Order = 12)] [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false)] public virtual ReportingConfiguration DefaultConfiguration { get; set; } /// /// A URI where the primary documentation for the report can be found. /// + [JsonProperty(Order = 3)] [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false)] [JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))] public virtual Uri HelpUri { get; set; } @@ -108,6 +119,7 @@ public SarifNodeKind SarifNodeKind /// /// Provides the primary documentation for the report, useful when there is no online documentation. /// + [JsonProperty(Order = 4)] [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false)] public virtual MultiformatMessageString Help { get; set; } @@ -115,12 +127,13 @@ public SarifNodeKind SarifNodeKind /// An array of objects that describe relationships between this reporting descriptor and others. /// [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false)] - [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [JsonProperty(Order = 13, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] public virtual IList Relationships { get; set; } /// /// Key/value pairs that provide additional information about the report. /// + [JsonProperty(Order = 14)] [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)] internal override IDictionary Properties { get; set; } From fd89033271d76d3416b014856881b9a4a5cc5e7b Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 01:34:56 -0800 Subject: [PATCH 3/9] use DataMember.Order property to set json node order --- .../Autogenerated/ReportingDescriptor.cs | 42 +++++++------------ .../ReportingDescriptor.cs | 42 +++++++------------ 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/src/Sarif/Autogenerated/ReportingDescriptor.cs b/src/Sarif/Autogenerated/ReportingDescriptor.cs index 8cf310470..5f98528fd 100644 --- a/src/Sarif/Autogenerated/ReportingDescriptor.cs +++ b/src/Sarif/Autogenerated/ReportingDescriptor.cs @@ -41,100 +41,88 @@ public SarifNodeKind SarifNodeKind /// /// A stable, opaque identifier for the report. /// - [JsonProperty(Order = 1)] - [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false, Order = 1)] public virtual string Id { get; set; } /// /// An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 8)] - [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false, Order = 8)] public virtual IList DeprecatedIds { get; set; } /// /// A unique identifer for the reporting descriptor in the form of a GUID. /// - [JsonProperty(Order = 9)] - [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false, Order = 9)] public virtual string Guid { get; set; } /// /// An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 10)] - [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false, Order = 10)] public virtual IList DeprecatedGuids { get; set; } /// /// A report identifier that is understandable to an end user. /// - [JsonProperty(Order = 7)] - [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false, Order = 7)] public virtual string Name { get; set; } /// /// An array of readable identifiers by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 11)] - [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false, Order = 11)] public virtual IList DeprecatedNames { get; set; } /// /// A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text. /// - [JsonProperty(Order = 6)] - [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false, Order = 6)] public virtual MultiformatMessageString ShortDescription { get; set; } /// /// A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result. /// - [JsonProperty(Order = 2)] - [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false, Order = 2)] public virtual MultiformatMessageString FullDescription { get; set; } /// /// A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. /// - [JsonProperty(Order = 5)] - [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false, Order = 5)] public virtual IDictionary MessageStrings { get; set; } /// /// Default reporting configuration information. /// - [JsonProperty(Order = 12)] - [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false, Order = 12)] public virtual ReportingConfiguration DefaultConfiguration { get; set; } /// /// A URI where the primary documentation for the report can be found. /// - [JsonProperty(Order = 3)] - [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false, Order = 3)] [JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))] public virtual Uri HelpUri { get; set; } /// /// Provides the primary documentation for the report, useful when there is no online documentation. /// - [JsonProperty(Order = 4)] - [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false, Order = 4)] public virtual MultiformatMessageString Help { get; set; } /// /// An array of objects that describe relationships between this reporting descriptor and others. /// - [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false)] - [JsonProperty(Order = 13, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false, Order = 13)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, Order = 13)] public virtual IList Relationships { get; set; } /// /// Key/value pairs that provide additional information about the report. /// [JsonProperty(Order = 14)] - [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false, Order = 14)] internal override IDictionary Properties { get; set; } /// diff --git a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs index 8cf310470..5f98528fd 100644 --- a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs +++ b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs @@ -41,100 +41,88 @@ public SarifNodeKind SarifNodeKind /// /// A stable, opaque identifier for the report. /// - [JsonProperty(Order = 1)] - [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false, Order = 1)] public virtual string Id { get; set; } /// /// An array of stable, opaque identifiers by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 8)] - [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedIds", IsRequired = false, EmitDefaultValue = false, Order = 8)] public virtual IList DeprecatedIds { get; set; } /// /// A unique identifer for the reporting descriptor in the form of a GUID. /// - [JsonProperty(Order = 9)] - [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "guid", IsRequired = false, EmitDefaultValue = false, Order = 9)] public virtual string Guid { get; set; } /// /// An array of unique identifies in the form of a GUID by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 10)] - [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedGuids", IsRequired = false, EmitDefaultValue = false, Order = 10)] public virtual IList DeprecatedGuids { get; set; } /// /// A report identifier that is understandable to an end user. /// - [JsonProperty(Order = 7)] - [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "name", IsRequired = false, EmitDefaultValue = false, Order = 7)] public virtual string Name { get; set; } /// /// An array of readable identifiers by which this report was known in some previous version of the analysis tool. /// - [JsonProperty(Order = 11)] - [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "deprecatedNames", IsRequired = false, EmitDefaultValue = false, Order = 11)] public virtual IList DeprecatedNames { get; set; } /// /// A concise description of the report. Should be a single sentence that is understandable when visible space is limited to a single line of text. /// - [JsonProperty(Order = 6)] - [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "shortDescription", IsRequired = false, EmitDefaultValue = false, Order = 6)] public virtual MultiformatMessageString ShortDescription { get; set; } /// /// A description of the report. Should, as far as possible, provide details sufficient to enable resolution of any problem indicated by the result. /// - [JsonProperty(Order = 2)] - [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "fullDescription", IsRequired = false, EmitDefaultValue = false, Order = 2)] public virtual MultiformatMessageString FullDescription { get; set; } /// /// A set of name/value pairs with arbitrary names. Each value is a multiformatMessageString object, which holds message strings in plain text and (optionally) Markdown format. The strings can include placeholders, which can be used to construct a message in combination with an arbitrary number of additional string arguments. /// - [JsonProperty(Order = 5)] - [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "messageStrings", IsRequired = false, EmitDefaultValue = false, Order = 5)] public virtual IDictionary MessageStrings { get; set; } /// /// Default reporting configuration information. /// - [JsonProperty(Order = 12)] - [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "defaultConfiguration", IsRequired = false, EmitDefaultValue = false, Order = 12)] public virtual ReportingConfiguration DefaultConfiguration { get; set; } /// /// A URI where the primary documentation for the report can be found. /// - [JsonProperty(Order = 3)] - [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "helpUri", IsRequired = false, EmitDefaultValue = false, Order = 3)] [JsonConverter(typeof(Microsoft.CodeAnalysis.Sarif.Readers.UriConverter))] public virtual Uri HelpUri { get; set; } /// /// Provides the primary documentation for the report, useful when there is no online documentation. /// - [JsonProperty(Order = 4)] - [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "help", IsRequired = false, EmitDefaultValue = false, Order = 4)] public virtual MultiformatMessageString Help { get; set; } /// /// An array of objects that describe relationships between this reporting descriptor and others. /// - [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false)] - [JsonProperty(Order = 13, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] + [DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false, Order = 13)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, Order = 13)] public virtual IList Relationships { get; set; } /// /// Key/value pairs that provide additional information about the report. /// [JsonProperty(Order = 14)] - [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)] + [DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false, Order = 14)] internal override IDictionary Properties { get; set; } /// From f101a04cba0091bf03ca2169f25fc95cdaebfb7e Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 11:10:54 -0800 Subject: [PATCH 4/9] test remove SerializeIfNotNull(_run.RunAggregates, "runAggregates"); --- src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs | 11 ++++------- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 11 ++++------- src/Sarif/Writers/ResultLogJsonWriter.cs | 1 - 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs index 280c35f5c..dae21f7d5 100644 --- a/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/AnalyzeCommandBase.cs @@ -363,17 +363,14 @@ private void InitializeOutputFile(TOptions analyzeOptions, TContext context, ISe SarifLogger sarifLogger; - _run = new Run(); - - if (!string.IsNullOrWhiteSpace(analyzeOptions.AutomationId) - || !string.IsNullOrWhiteSpace(analyzeOptions.AutomationGuid)) + _run = new Run() { - _run.AutomationDetails = new RunAutomationDetails + AutomationDetails = new RunAutomationDetails { Id = analyzeOptions.AutomationId, Guid = analyzeOptions.AutomationGuid - }; - } + } + }; if (analyzeOptions.SarifOutputVersion != SarifVersion.OneZeroZero) { diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index dbe7564ca..db658d171 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -658,17 +658,14 @@ private void InitializeOutputFile(TOptions analyzeOptions, TContext context) SarifLogger sarifLogger; - _run = new Run(); - - if (!string.IsNullOrWhiteSpace(analyzeOptions.AutomationId) - || !string.IsNullOrWhiteSpace(analyzeOptions.AutomationGuid)) + _run = new Run() { - _run.AutomationDetails = new RunAutomationDetails + AutomationDetails = new RunAutomationDetails { Id = analyzeOptions.AutomationId, Guid = analyzeOptions.AutomationGuid - }; - } + } + }; if (analyzeOptions.SarifOutputVersion != SarifVersion.OneZeroZero) { diff --git a/src/Sarif/Writers/ResultLogJsonWriter.cs b/src/Sarif/Writers/ResultLogJsonWriter.cs index 49c63bc3d..faa2a9ec2 100644 --- a/src/Sarif/Writers/ResultLogJsonWriter.cs +++ b/src/Sarif/Writers/ResultLogJsonWriter.cs @@ -322,7 +322,6 @@ public void CompleteRun() // Results go here in schema order - SerializeIfNotNull(_run.AutomationDetails, "automationDetails"); SerializeIfNotNull(_run.RunAggregates, "runAggregates"); SerializeIfNotNull(_run.BaselineGuid, "baselineGuid"); SerializeIfNotNull(_run.RedactionTokens, "redactionTokens"); From d7cc31eb255126e0de7d134f9160d44f132fd6b4 Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 14:44:10 -0800 Subject: [PATCH 5/9] trigger the same check when manual write json nodes one by one --- src/Sarif/Writers/ResultLogJsonWriter.cs | 22 +++++++-- .../Sdk/AnalyzeCommandBaseTests.cs | 46 ++++++++++++++++++- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/Sarif/Writers/ResultLogJsonWriter.cs b/src/Sarif/Writers/ResultLogJsonWriter.cs index faa2a9ec2..43721eaa3 100644 --- a/src/Sarif/Writers/ResultLogJsonWriter.cs +++ b/src/Sarif/Writers/ResultLogJsonWriter.cs @@ -318,17 +318,31 @@ public void CompleteRun() WriteLogicalLocations(_run.LogicalLocations); } - SerializeIfNotNull(_run.Graphs, "graphs"); + // All ShouldSerialize() will not be triggered automatically when manually write node by node. + // To make sure the same logic applied we should call the same method here, if it is defined. + if (_run.ShouldSerializeGraphs()) + { + Serialize(_run.Graphs, "graphs"); + } // Results go here in schema order - + if (_run.ShouldSerializeAutomationDetails()) + { + Serialize(_run.AutomationDetails, "automationDetails"); + } SerializeIfNotNull(_run.RunAggregates, "runAggregates"); SerializeIfNotNull(_run.BaselineGuid, "baselineGuid"); SerializeIfNotNull(_run.RedactionTokens, "redactionTokens"); SerializeIfNotNull(_run.DefaultEncoding, "defaultEncoding"); SerializeIfNotNull(_run.DefaultSourceLanguage, "defaultSourceLanguage"); - SerializeIfNotNull(_run.NewlineSequences, "newlineSequences"); - SerializeIfNotNull(_run.ColumnKind == ColumnKind.UnicodeCodePoints ? "unicodeCodePoints" : "utf16CodeUnits", "columnKind"); + if (_run.ShouldSerializeNewlineSequences()) + { + Serialize(_run.NewlineSequences, "newlineSequences"); + } + if (_run.ShouldSerializeColumnKind()) + { + Serialize(_run.ColumnKind == ColumnKind.UnicodeCodePoints ? "unicodeCodePoints" : "utf16CodeUnits", "columnKind"); + } SerializeIfNotNull(_run.ExternalPropertyFileReferences, "externalPropertyFileReferences"); SerializeIfNotNull(_run.ThreadFlowLocations, "threadFlowLocations"); SerializeIfNotNull(_run.Taxonomies, "taxonomies"); diff --git a/src/Test.UnitTests.Sarif.Driver/Sdk/AnalyzeCommandBaseTests.cs b/src/Test.UnitTests.Sarif.Driver/Sdk/AnalyzeCommandBaseTests.cs index 5bd830a43..39b5fd0cb 100644 --- a/src/Test.UnitTests.Sarif.Driver/Sdk/AnalyzeCommandBaseTests.cs +++ b/src/Test.UnitTests.Sarif.Driver/Sdk/AnalyzeCommandBaseTests.cs @@ -1078,8 +1078,9 @@ public void AnalyzeCommandBase_CachesResultsWhenPersistingToLogFile() } [Fact] - public void AnalyzeCommandBase_ShouldEmitAutomationDetailsWhenIdOrGuidExists() + public void AnalyzeCommandBase_AutomationDetailsTests() { + const string whiteSpace = " "; const string automationId = "automation-id"; const string automationGuid = "automation-guid"; @@ -1097,7 +1098,43 @@ public void AnalyzeCommandBase_ShouldEmitAutomationDetailsWhenIdOrGuidExists() { AutomationId = automationId, AutomationGuid = automationGuid - } + }, + new TestAnalyzeOptions + { + }, + new TestAnalyzeOptions + { + AutomationId = string.Empty, + AutomationGuid = string.Empty + }, + new TestAnalyzeOptions + { + AutomationId = null, + AutomationGuid = null + }, + new TestAnalyzeOptions + { + AutomationId = whiteSpace, + AutomationGuid = whiteSpace + }, + new TestAnalyzeOptions + { + AutomationId = string.Empty, + AutomationGuid = null + }, + new TestAnalyzeOptions + { + AutomationId = null, + AutomationGuid = whiteSpace + }, + new TestAnalyzeOptions + { + AutomationGuid = string.Empty + }, + new TestAnalyzeOptions + { + AutomationId = null + }, }; foreach (TestAnalyzeOptions enhancedOption in enhancedOptions) @@ -1344,6 +1381,11 @@ private static void RunResultsCachingTestCase(ResultsCachingTestCase testCase, { runWithCaching.Artifacts.Should().NotBeEmpty(); + if (string.IsNullOrWhiteSpace(options.AutomationId) && string.IsNullOrWhiteSpace(options.AutomationGuid)) + { + runWithCaching.AutomationDetails.Should().Be(null); + } + if (!string.IsNullOrWhiteSpace(options.AutomationId)) { runWithCaching.AutomationDetails.Id.Should().Be(options.AutomationId); From d2b47a4139660d1024c5a2b1d64aba01db2db5c2 Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:02:31 -0800 Subject: [PATCH 6/9] fix baseline according to the new Order --- .../SARIF2012.ProvideRuleProperties_Invalid.sarif | 2 +- .../SARIF2014.ProvideDynamicMessageContent_Invalid.sarif | 2 +- .../SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif | 2 +- .../Inputs/SARIF2012.ProvideRuleProperties_Invalid.sarif | 4 ++-- .../SARIF2014.ProvideDynamicMessageContent_Invalid.sarif | 4 ++-- .../SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2012.ProvideRuleProperties_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2012.ProvideRuleProperties_Invalid.sarif index 8a42d72bd..dcae9d60f 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2012.ProvideRuleProperties_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2012.ProvideRuleProperties_Invalid.sarif @@ -120,7 +120,7 @@ "index": 0 }, "region": { - "startLine": 21, + "startLine": 22, "startColumn": 46 } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif index 522ae4812..1b22d4ad9 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif @@ -60,7 +60,7 @@ "index": 0 }, "region": { - "startLine": 18, + "startLine": 19, "startColumn": 74 } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif index cde713017..35a7e14c7 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/ExpectedOutputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif @@ -59,7 +59,7 @@ "index": 0 }, "region": { - "startLine": 18, + "startLine": 19, "startColumn": 91 } } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2012.ProvideRuleProperties_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2012.ProvideRuleProperties_Invalid.sarif index 5eb41915b..5bceadf8c 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2012.ProvideRuleProperties_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2012.ProvideRuleProperties_Invalid.sarif @@ -18,8 +18,8 @@ }, { "id": "TEST0002", - "name": "This isn't pascal case", - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" + "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html", + "name": "This isn't pascal case" } ] } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif index 21fac9840..e00955600 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2014.ProvideDynamicMessageContent_Invalid.sarif @@ -13,12 +13,12 @@ "fullDescription": { "text": "This is a test." }, + "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html", "messageStrings": { "NoPlaceholders": { "text": "This message does not contain dynamic content." } - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" + } } ] } diff --git a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif index 2fa22b71b..41ed4712d 100644 --- a/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif +++ b/src/Test.FunctionalTests.Sarif/TestData/Multitool/ValidateCommand/Inputs/SARIF2015.EnquoteDynamicMessageContent_Invalid.sarif @@ -13,12 +13,12 @@ "fullDescription": { "text": "This is a test." }, + "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html", "messageStrings": { "NotEnquoted": { "text": "This message contains dynamic content {0} that is not enquoted." } - }, - "helpUri": "http://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html" + } } ] } From 9f45c86516c569aedcee6dc1dd110bbce06bce67 Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 17:10:41 -0800 Subject: [PATCH 7/9] update ReleaseHistory.md --- src/ReleaseHistory.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 077ed1ba4..bda9987b9 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -2,6 +2,7 @@ ## Unreleased +* BUGFIX: Revert Json Serialization field order change and skip emit empty AutomationDetails node. [#2420](https://github.com/microsoft/sarif-sdk/pull/2420) * BREAKING: Fix `InvalidOperationException` when using PropertiesDictionary in a multithreaded application, and remove `[Serializable]` from it. Now use of BinaryFormatter on it will result in `SerializationException`: Type `PropertiesDictionary` is not marked as serializable. [#2415](https://github.com/microsoft/sarif-sdk/pull/2415) ## **v2.4.12** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.12) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.12) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.12) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.12) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.12) From 6e6b2e5f6bdc158a4563ec9a53bd6768132e1a26 Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Fri, 7 Jan 2022 18:20:27 -0800 Subject: [PATCH 8/9] update change description --- src/ReleaseHistory.md | 2 +- src/Sarif/Autogenerated/ReportingDescriptor.cs | 2 ++ src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index bda9987b9..4e0b2a1e6 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -2,7 +2,7 @@ ## Unreleased -* BUGFIX: Revert Json Serialization field order change and skip emit empty AutomationDetails node. [#2420](https://github.com/microsoft/sarif-sdk/pull/2420) +* BUGFIX: Adjust Json Serialization field order for ReportingDescriptor and skip emit empty AutomationDetails node. [#2420](https://github.com/microsoft/sarif-sdk/pull/2420) * BREAKING: Fix `InvalidOperationException` when using PropertiesDictionary in a multithreaded application, and remove `[Serializable]` from it. Now use of BinaryFormatter on it will result in `SerializationException`: Type `PropertiesDictionary` is not marked as serializable. [#2415](https://github.com/microsoft/sarif-sdk/pull/2415) ## **v2.4.12** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.12) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.12) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.12) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.12) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.12) diff --git a/src/Sarif/Autogenerated/ReportingDescriptor.cs b/src/Sarif/Autogenerated/ReportingDescriptor.cs index 5f98528fd..286b5e050 100644 --- a/src/Sarif/Autogenerated/ReportingDescriptor.cs +++ b/src/Sarif/Autogenerated/ReportingDescriptor.cs @@ -37,6 +37,8 @@ public SarifNodeKind SarifNodeKind // NOTYETAUTOGENERATED: Jschema needs a mechanism to emit all public methods as virtual // https://github.com/Microsoft/jschema/issues/97 + // NOTYETAUTOGENERATED: Order attribute + // https://github.com/microsoft/jschema/issues/140 // /// /// A stable, opaque identifier for the report. diff --git a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs index 5f98528fd..286b5e050 100644 --- a/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs +++ b/src/Sarif/NotYetAutoGenerated/ReportingDescriptor.cs @@ -37,6 +37,8 @@ public SarifNodeKind SarifNodeKind // NOTYETAUTOGENERATED: Jschema needs a mechanism to emit all public methods as virtual // https://github.com/Microsoft/jschema/issues/97 + // NOTYETAUTOGENERATED: Order attribute + // https://github.com/microsoft/jschema/issues/140 // /// /// A stable, opaque identifier for the report. From 125f31e257dd9294fc2ad44a76e7e606b430afcb Mon Sep 17 00:00:00 2001 From: Shaopeng <81775155+shaopeng-gh@users.noreply.github.com> Date: Sat, 8 Jan 2022 20:33:05 -0800 Subject: [PATCH 9/9] check all other run properties are using the shouldSerialize pattern, add the same logic as this. --- src/Sarif/Writers/ResultLogJsonWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sarif/Writers/ResultLogJsonWriter.cs b/src/Sarif/Writers/ResultLogJsonWriter.cs index 43721eaa3..9e26fdac9 100644 --- a/src/Sarif/Writers/ResultLogJsonWriter.cs +++ b/src/Sarif/Writers/ResultLogJsonWriter.cs @@ -295,7 +295,7 @@ public void CompleteRun() } if ((_writeConditions & Conditions.InvocationsWritten) != Conditions.InvocationsWritten && - _run.Invocations?.Count > 0) + _run.ShouldSerializeInvocations()) { WriteInvocations(_run.Invocations); } @@ -307,13 +307,13 @@ public void CompleteRun() SerializeIfNotNull(_run.OriginalUriBaseIds, "originalUriBaseIds"); if ((_writeConditions & Conditions.FilesWritten) != Conditions.FilesWritten && - _run.Artifacts != null) + _run.ShouldSerializeArtifacts()) { WriteArtifacts(_run.Artifacts); } if ((_writeConditions & Conditions.LogicalLocationsWritten) != Conditions.LogicalLocationsWritten && - _run.LogicalLocations != null) + _run.ShouldSerializeLogicalLocations()) { WriteLogicalLocations(_run.LogicalLocations); }