Skip to content

Commit c004f92

Browse files
committed
Apply code review findings
1 parent da91cea commit c004f92

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.Nuget.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private List<string> GetReachableFallbackNugetFeeds()
9696
if (fallbackFeeds.Count == 0)
9797
{
9898
fallbackFeeds.Add(PublicNugetFeed);
99+
logger.LogInfo($"No fallback Nuget feeds specified. Using default feed: {PublicNugetFeed}");
99100
}
100101

101102
logger.LogInfo($"Checking fallback Nuget feed reachability on feeds: {string.Join(", ", fallbackFeeds.OrderBy(f => f))}");
@@ -188,15 +189,15 @@ private void DownloadMissingPackagesFromSpecificFeeds(List<FileInfo> allNonBinar
188189
var reachableFallbackFeeds = GetReachableFallbackNugetFeeds();
189190
if (reachableFallbackFeeds.Count > 0)
190191
{
191-
DownloadMissingPackages(allNonBinaryFiles, dllLocations, withNugetConfigFromSrc: false, fallbackNugetFeeds: reachableFallbackFeeds);
192+
DownloadMissingPackages(allNonBinaryFiles, dllLocations, fallbackNugetFeeds: reachableFallbackFeeds);
192193
}
193194
else
194195
{
195196
logger.LogWarning("Skipping download of missing packages from specific feeds as no fallback Nuget feeds are reachable.");
196197
}
197198
}
198199

199-
private void DownloadMissingPackages(List<FileInfo> allFiles, HashSet<AssemblyLookupLocation> dllLocations, bool withNugetConfigFromSrc = true, IEnumerable<string>? fallbackNugetFeeds = null)
200+
private void DownloadMissingPackages(List<FileInfo> allFiles, HashSet<AssemblyLookupLocation> dllLocations, IEnumerable<string>? fallbackNugetFeeds = null)
200201
{
201202
var alreadyDownloadedPackages = GetRestoredPackageDirectoryNames(packageDirectory.DirInfo);
202203
var alreadyDownloadedLegacyPackages = GetRestoredLegacyPackageNames();
@@ -230,7 +231,7 @@ private void DownloadMissingPackages(List<FileInfo> allFiles, HashSet<AssemblyLo
230231

231232
logger.LogInfo($"Found {notYetDownloadedPackages.Count} packages that are not yet restored");
232233
using var tempDir = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "nugetconfig"));
233-
var nugetConfig = withNugetConfigFromSrc
234+
var nugetConfig = fallbackNugetFeeds is null
234235
? GetNugetConfig(allFiles)
235236
: CreateFallbackNugetConfig(fallbackNugetFeeds, tempDir.DirInfo.FullName);
236237

@@ -241,7 +242,7 @@ private void DownloadMissingPackages(List<FileInfo> allFiles, HashSet<AssemblyLo
241242

242243
Parallel.ForEach(notYetDownloadedPackages, new ParallelOptions { MaxDegreeOfParallelism = threads }, package =>
243244
{
244-
var success = TryRestorePackageManually(package.Name, nugetConfig, package.PackageReferenceSource, tryWithoutNugetConfig: withNugetConfigFromSrc);
245+
var success = TryRestorePackageManually(package.Name, nugetConfig, package.PackageReferenceSource, tryWithoutNugetConfig: fallbackNugetFeeds is null);
245246
if (!success)
246247
{
247248
return;
@@ -258,15 +259,8 @@ private void DownloadMissingPackages(List<FileInfo> allFiles, HashSet<AssemblyLo
258259
dllLocations.Add(missingPackageDirectory.DirInfo.FullName);
259260
}
260261

261-
private string? CreateFallbackNugetConfig(IEnumerable<string>? fallbackNugetFeeds, string folderPath)
262+
private string? CreateFallbackNugetConfig(IEnumerable<string> fallbackNugetFeeds, string folderPath)
262263
{
263-
if (fallbackNugetFeeds is null)
264-
{
265-
// We're not overriding the inherited Nuget feeds
266-
logger.LogInfo("No fallback Nuget feeds provided. Not creating a fallback nuget.config file.");
267-
return null;
268-
}
269-
270264
var sb = new StringBuilder();
271265
fallbackNugetFeeds.ForEach((feed, index) => sb.AppendLine($"<add key=\"feed{index}\" value=\"{feed}\" />"));
272266

@@ -587,19 +581,11 @@ private IEnumerable<string> GetFeeds(Func<IList<string>> getNugetFeeds)
587581
}
588582
}
589583

590-
private (HashSet<string>, HashSet<string>) GetAllFeeds(List<FileInfo> allFiles)
584+
private (HashSet<string> explicitFeeds, HashSet<string> allFeeds) GetAllFeeds(List<FileInfo> allFiles)
591585
{
592-
IList<string> GetNugetFeeds(string nugetConfig)
593-
{
594-
logger.LogInfo($"Getting Nuget feeds from '{nugetConfig}'...");
595-
return dotnet.GetNugetFeeds(nugetConfig);
596-
}
586+
IList<string> GetNugetFeeds(string nugetConfig) => dotnet.GetNugetFeeds(nugetConfig);
597587

598-
IList<string> GetNugetFeedsFromFolder(string folderPath)
599-
{
600-
logger.LogInfo($"Getting Nuget feeds in folder '{folderPath}'...");
601-
return dotnet.GetNugetFeedsFromFolder(folderPath);
602-
}
588+
IList<string> GetNugetFeedsFromFolder(string folderPath) => dotnet.GetNugetFeedsFromFolder(folderPath);
603589

604590
var nugetConfigs = GetAllNugetConfigs(allFiles);
605591
var explicitFeeds = nugetConfigs

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,17 @@ public bool Exec(string execArgs)
113113

114114
private const string nugetListSourceCommand = "nuget list source --format Short";
115115

116-
public IList<string> GetNugetFeeds(string nugetConfig) => GetResultList($"{nugetListSourceCommand} --configfile \"{nugetConfig}\"");
116+
public IList<string> GetNugetFeeds(string nugetConfig)
117+
{
118+
logger.LogInfo($"Getting Nuget feeds from '{nugetConfig}'...");
119+
return GetResultList($"{nugetListSourceCommand} --configfile \"{nugetConfig}\"");
120+
}
117121

118-
public IList<string> GetNugetFeedsFromFolder(string folderPath) => GetResultList(nugetListSourceCommand, folderPath);
122+
public IList<string> GetNugetFeedsFromFolder(string folderPath)
123+
{
124+
logger.LogInfo($"Getting Nuget feeds in folder '{folderPath}'...");
125+
return GetResultList(nugetListSourceCommand, folderPath);
126+
}
119127

120128
// The version number should be kept in sync with the version .NET version used for building the application.
121129
public const string LatestDotNetSdkVersion = "8.0.101";

0 commit comments

Comments
 (0)