Skip to content

Commit e19c775

Browse files
committed
C#: Cleanup NugetPackages.cs.
1 parent 6e4865d commit e19c775

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,25 @@ internal class NugetPackages
1919
/// <summary>
2020
/// The list of package files.
2121
/// </summary>
22-
public FileInfo[] PackageFiles { get; }
23-
24-
/// <summary>
25-
/// The source directory used.
26-
/// </summary>
27-
public string SourceDirectory { get; }
22+
private readonly FileInfo[] packageFiles;
2823

2924
/// <summary>
3025
/// The computed packages directory.
3126
/// This will be in the Temp location
3227
/// so as to not trample the source tree.
3328
/// </summary>
34-
public TemporaryDirectory PackageDirectory { get; }
29+
private readonly TemporaryDirectory packageDirectory;
3530

3631
/// <summary>
3732
/// Create the package manager for a specified source tree.
3833
/// </summary>
3934
public NugetPackages(string sourceDir, TemporaryDirectory packageDirectory, ProgressMonitor progressMonitor)
4035
{
41-
SourceDirectory = sourceDir;
42-
PackageDirectory = packageDirectory;
36+
this.packageDirectory = packageDirectory;
4337
this.progressMonitor = progressMonitor;
4438

4539
nugetExe = ResolveNugetExe(sourceDir);
46-
PackageFiles = new DirectoryInfo(SourceDirectory)
40+
packageFiles = new DirectoryInfo(sourceDir)
4741
.EnumerateFiles("packages.config", SearchOption.AllDirectories)
4842
.ToArray();
4943
}
@@ -63,7 +57,7 @@ private string ResolveNugetExe(string sourceDir)
6357
var nuget = Path.Combine(directory, "nuget", "nuget.exe");
6458
if (File.Exists(nuget))
6559
{
66-
progressMonitor.LogInfo($"Found nuget.exe at {nuget}");
60+
progressMonitor.FoundNuGet(nuget);
6761
return nuget;
6862
}
6963
else
@@ -81,7 +75,7 @@ private string DownloadNugetExe(string sourceDir)
8175
// Nuget.exe already exists in the .nuget directory.
8276
if (File.Exists(nuget))
8377
{
84-
progressMonitor.LogInfo($"Found nuget.exe at {nuget}");
78+
progressMonitor.FoundNuGet(nuget);
8579
return nuget;
8680
}
8781

@@ -118,12 +112,12 @@ private void RestoreNugetPackage(string package)
118112
if (Util.Win32.IsWindows())
119113
{
120114
exe = nugetExe;
121-
args = string.Format("install -OutputDirectory {0} {1}", PackageDirectory, package);
115+
args = string.Format("install -OutputDirectory {0} {1}", packageDirectory, package);
122116
}
123117
else
124118
{
125119
exe = "mono";
126-
args = string.Format("{0} install -OutputDirectory {1} {2}", nugetExe, PackageDirectory, package);
120+
args = string.Format("{0} install -OutputDirectory {1} {2}", nugetExe, packageDirectory, package);
127121
}
128122

129123
var pi = new ProcessStartInfo(exe, args)
@@ -164,7 +158,7 @@ private void RestoreNugetPackage(string package)
164158
/// </summary>
165159
public void InstallPackages()
166160
{
167-
foreach (var package in PackageFiles)
161+
foreach (var package in packageFiles)
168162
{
169163
RestoreNugetPackage(package.FullName);
170164
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void CommandFailed(string exe, string arguments, int exitCode) =>
8888
public void MissingNuGet() =>
8989
LogError("Missing nuget.exe");
9090

91+
public void FoundNuGet(string path) =>
92+
LogInfo($"Found nuget.exe at {path}");
93+
9194
public void MissingDotNet() =>
9295
LogError("Missing dotnet CLI");
9396

0 commit comments

Comments
 (0)