From d5f07275308f8c56ede0da86cf4f5caca9abf394 Mon Sep 17 00:00:00 2001 From: "Michael C. Fanning" Date: Wed, 30 Oct 2024 17:12:38 -0700 Subject: [PATCH] Final updates for zip prototype. --- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 17 ++++++++ src/Sarif/Writers/ConsoleLogger.cs | 43 +++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index e35807162..792b57bd6 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -584,6 +584,23 @@ private static void LogCachingLogger(TContext globalContext, CachingLogger cachi currentResult = clonedResult; } + + if (globalContext.CurrentTarget.BaseUri != null) + { + currentResult.Locations[0].LogicalLocations = new[] { + new LogicalLocation + { + FullyQualifiedName = globalContext.CurrentTarget.BaseUri.OriginalString, + Kind = LogicalLocationKind.Package, + }, + new LogicalLocation + { + FullyQualifiedName = globalContext.CurrentTarget.Uri.OriginalString, + ParentIndex = 0, + }, + }; + } + globalContext.Logger.FileRegionsCache = cachingLogger.FileRegionsCache; globalContext.Logger.Log(kv.Key, currentResult, tuple.Item2); } diff --git a/src/Sarif/Writers/ConsoleLogger.cs b/src/Sarif/Writers/ConsoleLogger.cs index 3dfb343d3..39dfa072c 100644 --- a/src/Sarif/Writers/ConsoleLogger.cs +++ b/src/Sarif/Writers/ConsoleLogger.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; @@ -117,22 +118,40 @@ public void Log(ReportingDescriptor rule, Result result, int? extensionIndex = n // TODO we need better retrieval for locations than these defaults. // Note that we can potentially emit many messages from a single result. - PhysicalLocation physicalLocation = result.Locations?.First().PhysicalLocation; - - WriteLineToConsole(GetMessageText(_toolName, physicalLocation?.ArtifactLocation?.Uri, physicalLocation?.Region, result.RuleId, message, result.Kind, result.Level)); + Location location = result.Locations?.First(); + PhysicalLocation physicalLocation = location?.PhysicalLocation; + + string path = location.LogicalLocations == null + ? ConstructPathFromUri(physicalLocation?.ArtifactLocation?.Uri) + : ConstructPackagePath(location.LogicalLocations); + + message = GetMessageText(_toolName, + path, + physicalLocation?.Region, + result.RuleId, + message, + result.Kind, + result.Level); + + WriteLineToConsole(message); } - public static string GetMessageText( - string toolName, - Uri uri, - Region region, - string ruleId, - string message, - ResultKind kind, - FailureLevel level) + private string ConstructPackagePath(IList logicalLocations) { - string path = ConstructPathFromUri(uri); + string packageUri = logicalLocations[0].FullyQualifiedName; + string entryUri = logicalLocations[1].FullyQualifiedName; + + return $"[{packageUri}] {entryUri}"; + } + public static string GetMessageText(string toolName, + string path, + Region region, + string ruleId, + string message, + ResultKind kind, + FailureLevel level) + { string issueType = null; switch (level)