From 1700026338f2c8b7bedc32ab4f69c7bd9534e3c9 Mon Sep 17 00:00:00 2001 From: "Michael C. Fanning" Date: Tue, 4 Dec 2018 15:48:35 -0800 Subject: [PATCH] Prep for 2018-11-28 schema update. Remove run.architecture. --- src/ReleaseHistory.md | 5 +++ .../Writers/SarifLoggerTests.cs | 3 -- src/Sarif/Autogenerated/Run.cs | 18 +++------- .../Autogenerated/RunEqualityComparer.cs | 10 ------ src/Sarif/Autogenerated/SarifLog.cs | 2 +- src/Sarif/Schemata/sarif-schema.json | 9 ++--- src/Sarif/VersionConstants.cs | 2 +- .../SarifCurrentToVersionOneVisitor.cs | 1 - .../SarifVersionOneToCurrentVisitor.cs | 1 - .../PrereleaseCompatibilityTransformer.cs | 36 ++++++++++++++++++- src/Sarif/Writers/ResultLogJsonWriter.cs | 6 ---- src/build.props | 2 +- 12 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 56c12b6df..998caae4d 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -218,3 +218,8 @@ * BREAKING: run.automationLogicalId subsumed by run.aggregateIds, an array of 'runAutomationDetails' objects. * BREAKING: Remove threadFlowLocation.step * Add result.occurrenceCount (denotes # of occurrences of an identical results within an analysisRun) + +## **v2.0.0-csd.2.beta.2018.11.28** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.0.0-csd.2.beta.2018.11.28) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.0.0-csd.2.beta.2018.11.28) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.0.0-csd.2.beta.2018.11.28)) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.0.0-csd.2.beta.2018.11.28)) +* Result matching improvements +* Fortify FPR converter improvements +* BREAKING: remove run.architecture https://github.com/oasis-tcs/sarif-spec/issues/262 \ No newline at end of file diff --git a/src/Sarif.UnitTests/Writers/SarifLoggerTests.cs b/src/Sarif.UnitTests/Writers/SarifLoggerTests.cs index ac21ccbf2..d810649d9 100644 --- a/src/Sarif.UnitTests/Writers/SarifLoggerTests.cs +++ b/src/Sarif.UnitTests/Writers/SarifLoggerTests.cs @@ -230,7 +230,6 @@ public void SarifLogger_WritesRunProperties() }; run.BaselineInstanceGuid = baselineInstanceGuid; - run.Architecture = architecture; run.Conversion = conversion; run.VersionControlProvenance = new[] { versionControlDetails }; run.OriginalUriBaseIds = originalUriBaseIds; @@ -255,9 +254,7 @@ public void SarifLogger_WritesRunProperties() run.Id.InstanceGuid.Should().Be(runInstanceGuid); run.BaselineInstanceGuid.Should().Be(baselineInstanceGuid); run.Id.InstanceId.Should().Be(runInstanceId); - run.Architecture.Should().Be(architecture); run.Conversion.Tool.Should().BeEquivalentTo(DefaultTool); - //run.VersionControlProvenance[0].Timestamp.Should().BeEquivalentTo(utcNow); run.VersionControlProvenance[0].RepositoryUri.Should().BeEquivalentTo(versionControlUri); run.OriginalUriBaseIds[originalUriBaseIdKey].Uri.Should().Be(originalUriBaseIdValue); run.DefaultFileEncoding.Should().Be(defaultFileEncoding); diff --git a/src/Sarif/Autogenerated/Run.cs b/src/Sarif/Autogenerated/Run.cs index ee09b0355..ffb501056 100644 --- a/src/Sarif/Autogenerated/Run.cs +++ b/src/Sarif/Autogenerated/Run.cs @@ -110,12 +110,6 @@ public SarifNodeKind SarifNodeKind [DataMember(Name = "baselineInstanceGuid", IsRequired = false, EmitDefaultValue = false)] public string BaselineInstanceGuid { get; set; } - /// - /// The hardware architecture for which the run was targeted. - /// - [DataMember(Name = "architecture", IsRequired = false, EmitDefaultValue = false)] - public string Architecture { get; set; } - /// /// The MIME type of all rich text message properties in the run. Default: "text/markdown;variant=GFM" /// @@ -195,9 +189,6 @@ public Run() /// /// An initialization value for the property. /// - /// - /// An initialization value for the property. - /// /// /// An initialization value for the property. /// @@ -213,9 +204,9 @@ public Run() /// /// An initialization value for the property. /// - public Run(Tool tool, IEnumerable invocations, Conversion conversion, IEnumerable versionControlProvenance, IDictionary originalUriBaseIds, IDictionary files, IDictionary logicalLocations, IDictionary graphs, IEnumerable results, Resources resources, RunAutomationDetails id, IEnumerable aggregateIds, string baselineInstanceGuid, string architecture, string richMessageMimeType, string redactionToken, string defaultFileEncoding, ColumnKind columnKind, IDictionary properties) + public Run(Tool tool, IEnumerable invocations, Conversion conversion, IEnumerable versionControlProvenance, IDictionary originalUriBaseIds, IDictionary files, IDictionary logicalLocations, IDictionary graphs, IEnumerable results, Resources resources, RunAutomationDetails id, IEnumerable aggregateIds, string baselineInstanceGuid, string richMessageMimeType, string redactionToken, string defaultFileEncoding, ColumnKind columnKind, IDictionary properties) { - Init(tool, invocations, conversion, versionControlProvenance, originalUriBaseIds, files, logicalLocations, graphs, results, resources, id, aggregateIds, baselineInstanceGuid, architecture, richMessageMimeType, redactionToken, defaultFileEncoding, columnKind, properties); + Init(tool, invocations, conversion, versionControlProvenance, originalUriBaseIds, files, logicalLocations, graphs, results, resources, id, aggregateIds, baselineInstanceGuid, richMessageMimeType, redactionToken, defaultFileEncoding, columnKind, properties); } /// @@ -234,7 +225,7 @@ public Run(Run other) throw new ArgumentNullException(nameof(other)); } - Init(other.Tool, other.Invocations, other.Conversion, other.VersionControlProvenance, other.OriginalUriBaseIds, other.Files, other.LogicalLocations, other.Graphs, other.Results, other.Resources, other.Id, other.AggregateIds, other.BaselineInstanceGuid, other.Architecture, other.RichMessageMimeType, other.RedactionToken, other.DefaultFileEncoding, other.ColumnKind, other.Properties); + Init(other.Tool, other.Invocations, other.Conversion, other.VersionControlProvenance, other.OriginalUriBaseIds, other.Files, other.LogicalLocations, other.Graphs, other.Results, other.Resources, other.Id, other.AggregateIds, other.BaselineInstanceGuid, other.RichMessageMimeType, other.RedactionToken, other.DefaultFileEncoding, other.ColumnKind, other.Properties); } ISarifNode ISarifNode.DeepClone() @@ -255,7 +246,7 @@ private ISarifNode DeepCloneCore() return new Run(this); } - private void Init(Tool tool, IEnumerable invocations, Conversion conversion, IEnumerable versionControlProvenance, IDictionary originalUriBaseIds, IDictionary files, IDictionary logicalLocations, IDictionary graphs, IEnumerable results, Resources resources, RunAutomationDetails id, IEnumerable aggregateIds, string baselineInstanceGuid, string architecture, string richMessageMimeType, string redactionToken, string defaultFileEncoding, ColumnKind columnKind, IDictionary properties) + private void Init(Tool tool, IEnumerable invocations, Conversion conversion, IEnumerable versionControlProvenance, IDictionary originalUriBaseIds, IDictionary files, IDictionary logicalLocations, IDictionary graphs, IEnumerable results, Resources resources, RunAutomationDetails id, IEnumerable aggregateIds, string baselineInstanceGuid, string richMessageMimeType, string redactionToken, string defaultFileEncoding, ColumnKind columnKind, IDictionary properties) { if (tool != null) { @@ -386,7 +377,6 @@ private void Init(Tool tool, IEnumerable invocations, Conversion con } BaselineInstanceGuid = baselineInstanceGuid; - Architecture = architecture; RichMessageMimeType = richMessageMimeType; RedactionToken = redactionToken; DefaultFileEncoding = defaultFileEncoding; diff --git a/src/Sarif/Autogenerated/RunEqualityComparer.cs b/src/Sarif/Autogenerated/RunEqualityComparer.cs index 956a77591..85e1889ab 100644 --- a/src/Sarif/Autogenerated/RunEqualityComparer.cs +++ b/src/Sarif/Autogenerated/RunEqualityComparer.cs @@ -225,11 +225,6 @@ public bool Equals(Run left, Run right) return false; } - if (left.Architecture != right.Architecture) - { - return false; - } - if (left.RichMessageMimeType != right.RichMessageMimeType) { return false; @@ -422,11 +417,6 @@ public int GetHashCode(Run obj) result = (result * 31) + obj.BaselineInstanceGuid.GetHashCode(); } - if (obj.Architecture != null) - { - result = (result * 31) + obj.Architecture.GetHashCode(); - } - if (obj.RichMessageMimeType != null) { result = (result * 31) + obj.RichMessageMimeType.GetHashCode(); diff --git a/src/Sarif/Autogenerated/SarifLog.cs b/src/Sarif/Autogenerated/SarifLog.cs index 29ccbf705..daf8d4e07 100644 --- a/src/Sarif/Autogenerated/SarifLog.cs +++ b/src/Sarif/Autogenerated/SarifLog.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Sarif { /// - /// Static Analysis Results Format (SARIF) Version 2.0.0-csd.2.beta-2018-10-10 JSON Schema: a standard format for the output of static analysis tools. + /// Static Analysis Results Format (SARIF) Version 2.0.0-csd.2.beta-2018-11-28 JSON Schema: a standard format for the output of static analysis tools. /// [DataContract] [GeneratedCode("Microsoft.Json.Schema.ToDotNet", "0.58.0.0")] diff --git a/src/Sarif/Schemata/sarif-schema.json b/src/Sarif/Schemata/sarif-schema.json index fa63f45af..b72b7adb7 100644 --- a/src/Sarif/Schemata/sarif-schema.json +++ b/src/Sarif/Schemata/sarif-schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Static Analysis Results Format (SARIF) Version 2.0.0-csd.2.beta.2018-10-10 JSON Schema", - "description": "Static Analysis Results Format (SARIF) Version 2.0.0-csd.2.beta-2018-10-10 JSON Schema: a standard format for the output of static analysis tools.", + "description": "Static Analysis Results Format (SARIF) Version 2.0.0-csd.2.beta-2018-11-28 JSON Schema: a standard format for the output of static analysis tools.", "additionalProperties": false, "type": "object", "properties": { @@ -14,7 +14,7 @@ "version": { "description": "The SARIF format version of this log file.", - "enum": [ "2.0.0-csd.2.beta.2018-10-10" ] + "enum": [ "2.0.0-csd.2.beta.2018-11-28" ] }, "runs": { @@ -1555,11 +1555,6 @@ "type": "string" }, - "architecture": { - "description": "The hardware architecture for which the run was targeted.", - "type": "string" - }, - "richMessageMimeType": { "description": "The MIME type of all rich text message properties in the run. Default: \"text/markdown;variant=GFM\"", "type": "string", diff --git a/src/Sarif/VersionConstants.cs b/src/Sarif/VersionConstants.cs index b6b665805..cb218aab0 100644 --- a/src/Sarif/VersionConstants.cs +++ b/src/Sarif/VersionConstants.cs @@ -5,7 +5,7 @@ namespace Microsoft.CodeAnalysis.Sarif { public static class VersionConstants { - public const string Prerelease = "csd.2.beta.2018-10-10"; + public const string Prerelease = "csd.2.beta.2018-11-28"; public const string AssemblyVersion = "2.0.0"; public const string FileVersion = AssemblyVersion + ".0"; } diff --git a/src/Sarif/Visitors/SarifCurrentToVersionOneVisitor.cs b/src/Sarif/Visitors/SarifCurrentToVersionOneVisitor.cs index 0f346d60c..8852377b0 100644 --- a/src/Sarif/Visitors/SarifCurrentToVersionOneVisitor.cs +++ b/src/Sarif/Visitors/SarifCurrentToVersionOneVisitor.cs @@ -860,7 +860,6 @@ internal RunVersionOne CreateRun(Run v2Run) run = new RunVersionOne(); _currentRun = run; - run.Architecture = v2Run.Architecture; run.BaselineId = v2Run.BaselineInstanceGuid; run.Files = v2Run.Files?.ToDictionary(v => v.Key, v => CreateFileData(v.Value)); diff --git a/src/Sarif/Visitors/SarifVersionOneToCurrentVisitor.cs b/src/Sarif/Visitors/SarifVersionOneToCurrentVisitor.cs index ce7f05463..f854257fb 100644 --- a/src/Sarif/Visitors/SarifVersionOneToCurrentVisitor.cs +++ b/src/Sarif/Visitors/SarifVersionOneToCurrentVisitor.cs @@ -913,7 +913,6 @@ internal Run CreateRun(RunVersionOne v1Run) run = new Run() { - Architecture = v1Run.Architecture, Id = id, AggregateIds = aggregateIds, BaselineInstanceGuid = v1Run.BaselineId, diff --git a/src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs b/src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs index fe69c5f69..76b3d1d60 100644 --- a/src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs +++ b/src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs @@ -33,16 +33,23 @@ public static string UpdateToCurrentVersion(string prereleaseSarifLog, bool forc switch (version) { + case "2.0.0-csd.2.beta.2018-11-28": + { + // SARIF TC28. Nothing to do. + break; + } case "2.0.0-csd.2.beta.2018-10-10": { - // Nothing to do, this is current + // 2.0.0-csd.2.beta.2018-10-10 == changes through SARIF TC #25 + modifiedLog |= ApplyChangesFromTC25ThroughTC28(sarifLog); break; } default: { modifiedLog |= ApplyCoreTransformations(sarifLog); + modifiedLog |= ApplyChangesFromTC25ThroughTC28(sarifLog); break; } } @@ -50,6 +57,33 @@ public static string UpdateToCurrentVersion(string prereleaseSarifLog, bool forc return modifiedLog ? sarifLog.ToString(formatting) : prereleaseSarifLog; } + private static bool ApplyChangesFromTC25ThroughTC28(JObject sarifLog) + { + bool modifiedLog = UpdateSarifLogVersion(sarifLog); + + var runs = (JArray)sarifLog["runs"]; + + if (runs != null) + { + foreach (JObject run in runs) + { + // Delete run.architecture. This data could, arguably, be transferred into the run logical + // identifier or we could drop it into a property bag, but realistically, we don't expect + // sufficient existing utilization of this property to warrant preserving it. + + // Remove run.architecture: https://github.com/oasis-tcs/sarif-spec/issues/262 + JToken architecture = run[nameof(architecture)]; + if (architecture != null) + { + run.Remove(nameof(architecture)); + modifiedLog = true; + } + } + } + + return modifiedLog; + } + private static bool ApplyCoreTransformations(JObject sarifLog) { bool modifiedLog = UpdateSarifLogVersion(sarifLog); diff --git a/src/Sarif/Writers/ResultLogJsonWriter.cs b/src/Sarif/Writers/ResultLogJsonWriter.cs index 7c88252db..11346cc37 100644 --- a/src/Sarif/Writers/ResultLogJsonWriter.cs +++ b/src/Sarif/Writers/ResultLogJsonWriter.cs @@ -96,12 +96,6 @@ public void Initialize(Run run) _serializer.Serialize(_jsonWriter, run.AggregateIds); } - if (!string.IsNullOrEmpty(run.Architecture)) - { - _jsonWriter.WritePropertyName("architecture"); - _serializer.Serialize(_jsonWriter, run.Architecture); - } - if (run.Tool != null) { _jsonWriter.WritePropertyName("tool"); diff --git a/src/build.props b/src/build.props index 6747f522f..4ad367f6c 100644 --- a/src/build.props +++ b/src/build.props @@ -10,7 +10,7 @@ Microsoft SARIF SDK © Microsoft Corporation. All rights reserved. 2.0.0 - csd.2.beta.2018-10-10 + csd.2.beta.2018-11-28