Skip to content

Commit

Permalink
Log sources used
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigusu-Allehu committed Jan 24, 2025
1 parent 841674d commit 8d2c6eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private async Task GetProjectMetadataAsync(
if (listPackageArgs.ReportType == ReportType.Vulnerable && auditSources.Count > 0)
{
// AuditSources being used. Get vulnerabilities data from the AuditSources VulnerabilityInfoResource.
var vulnerabilities = await GetVulnerabilityData(projectModel, auditSources, listPackageArgs.Logger, listPackageArgs.CancellationToken);
var vulnerabilities = await GetVulnerabilityData(projectModel, listPackageReportModel, auditSources, listPackageArgs.Logger, listPackageArgs.CancellationToken);

foreach (var frameworkPackages in frameworks)
{
Expand Down Expand Up @@ -227,6 +227,7 @@ private async Task GetProjectMetadataAsync(

private static async Task<List<IReadOnlyDictionary<string, IReadOnlyList<PackageVulnerabilityInfo>>>> GetVulnerabilityData(
ListPackageProjectModel projectModel,
ListPackageReportModel reportModel,
IReadOnlyList<PackageSource> sources,
ILogger logger,
CancellationToken cancellationToken)
Expand All @@ -235,7 +236,7 @@ private static async Task<List<IReadOnlyDictionary<string, IReadOnlyList<Package

foreach (var source in sources)
{
if (!await TryAddSourceVulnerabilityInfo(source, projectModel, logger, cancellationToken, vulnerabilityInfo))
if (!await TryAddSourceVulnerabilityInfo(source, reportModel, logger, cancellationToken, vulnerabilityInfo))
{
projectModel.AddProjectInformation(
ProblemType.Warning,
Expand All @@ -249,7 +250,7 @@ private static async Task<List<IReadOnlyDictionary<string, IReadOnlyList<Package

private static async Task<bool> TryAddSourceVulnerabilityInfo(
PackageSource source,
ListPackageProjectModel projectModel,
ListPackageReportModel reportModel,
ILogger logger,
CancellationToken cancellationToken,
List<IReadOnlyDictionary<string, IReadOnlyList<PackageVulnerabilityInfo>>> vulnerabilityInfo)
Expand All @@ -263,7 +264,7 @@ private static async Task<bool> TryAddSourceVulnerabilityInfo(
return false;
}

projectModel.PackageSourcesUsed.Add(source);
reportModel.SourcesUsed.Add(source);

var vulnerabilityInfoResult = await vulnerabilityResource.GetVulnerabilityInfoAsync(
new SourceCacheContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ private void WriteToConsole(ListPackageReportModel listPackageReportModel)
return;
}

WriteSources(_consoleOut, listPackageReportModel.ListPackageArgs);
if (listPackageReportModel.ListPackageArgs.ReportType != ReportType.Vulnerable && listPackageReportModel.SourcesUsed.Count > 0)
{
_consoleOut.WriteLine();
_consoleOut.WriteLine(Strings.ListPkg_SourcesUsedDescription);
PrintSources(_consoleOut, listPackageReportModel.SourcesUsed);
_consoleOut.WriteLine();
}
else
{
WriteSources(_consoleOut, listPackageReportModel.ListPackageArgs);
}

WriteProjects(_consoleOut, _consoleError, listPackageReportModel.Projects, listPackageReportModel.ListPackageArgs);

// Print a legend message for auto-reference markers used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using NuGet.Configuration;

namespace NuGet.CommandLine.XPlat.ListPackage
{
Expand All @@ -17,7 +16,6 @@ internal class ListPackageProjectModel
internal List<ListPackageReportFrameworkPackage> TargetFrameworkPackages { get; set; }
internal string ProjectName { get; private set; }
internal bool AutoReferenceFound { get; set; }
internal List<PackageSource> PackageSourcesUsed { get; set; } = new List<PackageSource>();

public ListPackageProjectModel(string projectPath, string projectName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using NuGet.Configuration;

namespace NuGet.CommandLine.XPlat.ListPackage
{
Expand All @@ -13,6 +14,7 @@ internal class ListPackageReportModel
internal ListPackageArgs ListPackageArgs { get; }
internal List<ListPackageProjectModel> Projects { get; } = new();
internal MSBuildAPIUtility MSBuildAPIUtility { get; }
internal HashSet<PackageSource> SourcesUsed { get; set; } = new HashSet<PackageSource>();

private ListPackageReportModel()
{ }
Expand Down

0 comments on commit 8d2c6eb

Please sign in to comment.