Skip to content

Commit

Permalink
Final updates for zip prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcfanning committed Oct 31, 2024
1 parent dc2370e commit d5f0727
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
43 changes: 31 additions & 12 deletions src/Sarif/Writers/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<LogicalLocation> 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)
Expand Down

0 comments on commit d5f0727

Please sign in to comment.