C#: Only access the DotNetCliWrapper using the IDotNet interface.

This commit is contained in:
Michael Nebel
2023-09-15 14:25:49 +02:00
parent 1fd85f4fe3
commit 31327f4f73
4 changed files with 10 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
private int conflictedReferences = 0;
private readonly IDependencyOptions options;
private readonly DirectoryInfo sourceDir;
private readonly DotNetCliWrapper dotnet;
private readonly IDotNet dotnet;
private readonly FileContent fileContent;
private readonly TemporaryDirectory packageDirectory;
private readonly TemporaryDirectory tempWorkingDirectory;
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
try
{
this.dotnet = new DotNetCliWrapper(options, progressMonitor);
this.dotnet = DotNetCliWrapper.Make(options, progressMonitor);
}
catch
{

View File

@@ -14,15 +14,18 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
private readonly IDotNetCliInvoker dotnet;
private readonly ProgressMonitor progressMonitor;
internal DotNetCliWrapper(IDotNetCliInvoker dotnet, ProgressMonitor progressMonitor)
private DotNetCliWrapper(IDotNetCliInvoker dotnet, ProgressMonitor progressMonitor)
{
this.progressMonitor = progressMonitor;
this.dotnet = dotnet;
Info();
}
public DotNetCliWrapper(IDependencyOptions options, ProgressMonitor progressMonitor) : this(new DotNetCliInvoker(progressMonitor, Path.Combine(options.DotNetPath ?? string.Empty, "dotnet")), progressMonitor) { }
private DotNetCliWrapper(IDependencyOptions options, ProgressMonitor progressMonitor) : this(new DotNetCliInvoker(progressMonitor, Path.Combine(options.DotNetPath ?? string.Empty, "dotnet")), progressMonitor) { }
internal static IDotNet Make(IDotNetCliInvoker dotnet, ProgressMonitor progressMonitor) => new DotNetCliWrapper(dotnet, progressMonitor);
public static IDotNet Make(IDependencyOptions options, ProgressMonitor progressMonitor) => new DotNetCliWrapper(options, progressMonitor);
private void Info()
{

View File

@@ -10,11 +10,11 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
{
private readonly DotnetVersion sdk;
private readonly ProgressMonitor progressMonitor;
private readonly DotNetCliWrapper dotNet;
private readonly IDotNet dotNet;
private readonly string sourceGeneratorFolder;
private readonly string cscPath;
public Razor(DotnetVersion sdk, DotNetCliWrapper dotNet, ProgressMonitor progressMonitor)
public Razor(DotnetVersion sdk, IDotNet dotNet, ProgressMonitor progressMonitor)
{
this.sdk = sdk;
this.progressMonitor = progressMonitor;

View File

@@ -38,7 +38,7 @@ namespace Semmle.Extraction.Tests
public class DotNetCliWrapperTests
{
private static IDotNet MakeDotnet(IDotNetCliInvoker dotnetCliInvoker) =>
new DotNetCliWrapper(dotnetCliInvoker, new ProgressMonitor(new LoggerStub()));
DotNetCliWrapper.Make(dotnetCliInvoker, new ProgressMonitor(new LoggerStub()));
private static IList<string> MakeDotnetRestoreOutput() =>
new List<string> {