Skip to content

Commit 508c780

Browse files
committed
C#: Add some more documentation in the FeedManager.
1 parent 5273118 commit 508c780

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ internal sealed partial class FeedManager : IDisposable
2626
private readonly DependencyDirectory emptyPackageDirectory;
2727
private readonly ImmutableHashSet<string> privateRegistryFeeds;
2828

29+
/// <summary>
30+
/// Gets whether there are private package registries configured for C#.
31+
/// </summary>
2932
public bool HasPrivateRegistryFeeds { get; }
33+
34+
/// <summary>
35+
/// Gets whether the reachability of the NuGet feeds should be checked before using them for restore.
36+
/// </summary>
3037
public bool CheckNugetFeedResponsiveness { get; } = EnvironmentVariables.GetBooleanOptOut(EnvironmentVariableNames.CheckNugetFeedResponsiveness);
3138

3239
private readonly Lazy<ImmutableHashSet<string>> lazyExplicitFeeds;
@@ -145,6 +152,13 @@ private IEnumerable<string> GetFeedsFromFolder(string folderPath) =>
145152
private IEnumerable<string> GetFeedsFromNugetConfig(string nugetConfigPath) =>
146153
GetFeeds(() => dotnet.GetNugetFeeds(nugetConfigPath));
147154

155+
/// <summary>
156+
/// Constructs the NuGet sources argument for the restore command based on the given feeds.
157+
/// If there are no feeds, a dummy source argument is added to override any default feeds that `restore` would use.
158+
/// </summary>
159+
/// <param name="feeds">The list of feeds to use for the restore command.</param>
160+
/// <param name="sourceArgumentPrefix">The prefix to use for each source argument (e.g., "-s").</param>
161+
/// <returns>The constructed NuGet sources argument for the restore command.</returns>
148162
public string FeedsToRestoreArgument(IEnumerable<string> feeds, string sourceArgumentPrefix)
149163
{
150164
// If there are no feeds, we want to override any default feeds that `restore` would use by passing a dummy source argument.
@@ -194,13 +208,25 @@ public IEnumerable<string> FeedsToUse(string path)
194208
return FeedsToUseAux(feedsToConsider);
195209
}
196210

211+
/// <summary>
212+
/// Constructs the list of NuGet sources to use for this restore.
213+
/// (1) Use the feeds we get from `dotnet nuget list source --configfile`
214+
/// (2) Use private registries, if they are configured
215+
/// </summary>
216+
/// <param name="config">Path to the NuGet configuration file.</param>
217+
/// <returns>The list of NuGet feeds to use for this restore.</returns>
197218
public IEnumerable<string> FeedsToUseFromConfig(string config)
198219
{
199220
var feedsToConsider = GetFeedsFromNugetConfig(config).ToHashSet();
200221

201222
return FeedsToUseAux(feedsToConsider);
202223
}
203224

225+
/// <summary>
226+
/// Constructs the NuGet sources argument for the `dotnet restore` command based on the given feeds.
227+
/// </summary>
228+
/// <param name="feeds">The list of NuGet feeds to use for the restore command.</param>
229+
/// <returns>A string representing the NuGet sources argument for the `dotnet restore` command.</returns>
204230
public string FeedsToDotnetRestoreArgument(IEnumerable<string> feeds)
205231
{
206232
return FeedsToRestoreArgument(feeds, "-s");
@@ -212,7 +238,7 @@ public string FeedsToDotnetRestoreArgument(IEnumerable<string> feeds)
212238
/// (2) Use private registries, if they are configured
213239
/// </summary>
214240
/// <param name="path">Path to project/solution</param>
215-
/// <returns>A string representing the NuGet sources argument for the restore command.</returns>
241+
/// <returns>A string representing the NuGet sources argument for the `dotnet restore` command.</returns>
216242
public string? MakeDotnetRestoreSourcesArgument(string path)
217243
{
218244
// Do not construct a set of explicit NuGet sources to use for restore.
@@ -367,6 +393,11 @@ private bool CheckSpecifiedFeeds(ImmutableHashSet<string> feeds, out ImmutableHa
367393
return isTimeout;
368394
}
369395

396+
/// <summary>
397+
/// Return true if the default NuGet feed is reachable, false otherwise.
398+
/// If the reachability check is disabled, this method will always return true.
399+
/// </summary>
400+
/// <returns>True if the default NuGet feed is reachable, false otherwise.</returns>
370401
public bool IsDefaultFeedReachable()
371402
{
372403
if (CheckNugetFeedResponsiveness)

0 commit comments

Comments
 (0)