mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Rename DotnetCommand to DotNetCliInvoker.
This commit is contained in:
@@ -11,17 +11,17 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal partial class DotNet : IDotNet
|
internal partial class DotNet : IDotNet
|
||||||
{
|
{
|
||||||
private readonly IDotnetCommand dotnet;
|
private readonly IDotNetCliInvoker dotnet;
|
||||||
private readonly ProgressMonitor progressMonitor;
|
private readonly ProgressMonitor progressMonitor;
|
||||||
|
|
||||||
internal DotNet(IDotnetCommand dotnet, ProgressMonitor progressMonitor)
|
internal DotNet(IDotNetCliInvoker dotnet, ProgressMonitor progressMonitor)
|
||||||
{
|
{
|
||||||
this.progressMonitor = progressMonitor;
|
this.progressMonitor = progressMonitor;
|
||||||
this.dotnet = dotnet;
|
this.dotnet = dotnet;
|
||||||
Info();
|
Info();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DotNet(IDependencyOptions options, ProgressMonitor progressMonitor) : this(new DotnetCommand(progressMonitor, Path.Combine(options.DotNetPath ?? string.Empty, "dotnet")), progressMonitor) { }
|
public DotNet(IDependencyOptions options, ProgressMonitor progressMonitor) : this(new DotNetCliInvoker(progressMonitor, Path.Combine(options.DotNetPath ?? string.Empty, "dotnet")), progressMonitor) { }
|
||||||
|
|
||||||
|
|
||||||
private void Info()
|
private void Info()
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low level utilities to run the "dotnet" command.
|
/// Low level utilities to run the "dotnet" command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class DotnetCommand : IDotnetCommand
|
internal sealed class DotNetCliInvoker : IDotNetCliInvoker
|
||||||
{
|
{
|
||||||
private readonly ProgressMonitor progressMonitor;
|
private readonly ProgressMonitor progressMonitor;
|
||||||
|
|
||||||
public string Exec { get; }
|
public string Exec { get; }
|
||||||
|
|
||||||
public DotnetCommand(ProgressMonitor progressMonitor, string exec)
|
public DotNetCliInvoker(ProgressMonitor progressMonitor, string exec)
|
||||||
{
|
{
|
||||||
this.progressMonitor = progressMonitor;
|
this.progressMonitor = progressMonitor;
|
||||||
this.Exec = exec;
|
this.Exec = exec;
|
||||||
@@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Semmle.Extraction.CSharp.DependencyFetching
|
namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||||
{
|
{
|
||||||
internal interface IDotnetCommand
|
internal interface IDotNetCliInvoker
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the dotnet executable.
|
/// The name of the dotnet executable.
|
||||||
@@ -6,13 +6,13 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace Semmle.Extraction.Tests
|
namespace Semmle.Extraction.Tests
|
||||||
{
|
{
|
||||||
internal class DotnetCommandStub : IDotnetCommand
|
internal class DotNetCliInvokerStub : IDotNetCliInvoker
|
||||||
{
|
{
|
||||||
private readonly IList<string> output;
|
private readonly IList<string> output;
|
||||||
private string lastArgs = "";
|
private string lastArgs = "";
|
||||||
public bool Success { get; set; } = true;
|
public bool Success { get; set; } = true;
|
||||||
|
|
||||||
public DotnetCommandStub(IList<string> output)
|
public DotNetCliInvokerStub(IList<string> output)
|
||||||
{
|
{
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
@@ -38,8 +38,8 @@ namespace Semmle.Extraction.Tests
|
|||||||
public class DotNetTests
|
public class DotNetTests
|
||||||
{
|
{
|
||||||
|
|
||||||
private static IDotNet MakeDotnet(IDotnetCommand dotnetCommand) =>
|
private static IDotNet MakeDotnet(IDotNetCliInvoker dotnetCliInvoker) =>
|
||||||
new DotNet(dotnetCommand, new ProgressMonitor(new LoggerStub()));
|
new DotNet(dotnetCliInvoker, new ProgressMonitor(new LoggerStub()));
|
||||||
|
|
||||||
private static IList<string> MakeDotnetRestoreOutput() =>
|
private static IList<string> MakeDotnetRestoreOutput() =>
|
||||||
new List<string> {
|
new List<string> {
|
||||||
@@ -61,13 +61,13 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetInfo()
|
public void TestDotnetInfo()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
var _ = MakeDotnet(dotnetCommand);
|
var _ = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("--info", lastArgs);
|
Assert.Equal("--info", lastArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,12 +75,12 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetInfoFailure()
|
public void TestDotnetInfoFailure()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>()) { Success = false };
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>()) { Success = false };
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var _ = MakeDotnet(dotnetCommand);
|
var _ = MakeDotnet(dotnetCliInvoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
@@ -96,14 +96,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetRestoreProjectToDirectory1()
|
public void TestDotnetRestoreProjectToDirectory1()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.RestoreProjectToDirectory("myproject.csproj", "mypackages", out var _);
|
dotnet.RestoreProjectToDirectory("myproject.csproj", "mypackages", out var _);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("restore --no-dependencies \"myproject.csproj\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true", lastArgs);
|
Assert.Equal("restore --no-dependencies \"myproject.csproj\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true", lastArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +111,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetRestoreProjectToDirectory2()
|
public void TestDotnetRestoreProjectToDirectory2()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.RestoreProjectToDirectory("myproject.csproj", "mypackages", out var _, "myconfig.config");
|
dotnet.RestoreProjectToDirectory("myproject.csproj", "mypackages", out var _, "myconfig.config");
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("restore --no-dependencies \"myproject.csproj\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --configfile \"myconfig.config\"", lastArgs);
|
Assert.Equal("restore --no-dependencies \"myproject.csproj\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --configfile \"myconfig.config\"", lastArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,14 +126,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetRestoreSolutionToDirectory1()
|
public void TestDotnetRestoreSolutionToDirectory1()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(MakeDotnetRestoreOutput());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(MakeDotnetRestoreOutput());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.RestoreSolutionToDirectory("mysolution.sln", "mypackages", out var projects);
|
dotnet.RestoreSolutionToDirectory("mysolution.sln", "mypackages", out var projects);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("restore --no-dependencies \"mysolution.sln\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
|
Assert.Equal("restore --no-dependencies \"mysolution.sln\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
|
||||||
Assert.Equal(2, projects.Count());
|
Assert.Equal(2, projects.Count());
|
||||||
Assert.Contains("/path/to/project.csproj", projects);
|
Assert.Contains("/path/to/project.csproj", projects);
|
||||||
@@ -144,15 +144,15 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetRestoreSolutionToDirectory2()
|
public void TestDotnetRestoreSolutionToDirectory2()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(MakeDotnetRestoreOutput());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(MakeDotnetRestoreOutput());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
dotnetCommand.Success = false;
|
dotnetCliInvoker.Success = false;
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.RestoreSolutionToDirectory("mysolution.sln", "mypackages", out var projects);
|
dotnet.RestoreSolutionToDirectory("mysolution.sln", "mypackages", out var projects);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("restore --no-dependencies \"mysolution.sln\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
|
Assert.Equal("restore --no-dependencies \"mysolution.sln\" --packages \"mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
|
||||||
Assert.Empty(projects);
|
Assert.Empty(projects);
|
||||||
}
|
}
|
||||||
@@ -161,14 +161,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetNew()
|
public void TestDotnetNew()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.New("myfolder");
|
dotnet.New("myfolder");
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("new console --no-restore --output \"myfolder\"", lastArgs);
|
Assert.Equal("new console --no-restore --output \"myfolder\"", lastArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,14 +176,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetAddPackage()
|
public void TestDotnetAddPackage()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.AddPackage("myfolder", "mypackage");
|
dotnet.AddPackage("myfolder", "mypackage");
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("add \"myfolder\" package \"mypackage\" --no-restore", lastArgs);
|
Assert.Equal("add \"myfolder\" package \"mypackage\" --no-restore", lastArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,14 +191,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetGetListedRuntimes1()
|
public void TestDotnetGetListedRuntimes1()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(MakeDotnetListRuntimesOutput());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(MakeDotnetListRuntimesOutput());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
var runtimes = dotnet.GetListedRuntimes();
|
var runtimes = dotnet.GetListedRuntimes();
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("--list-runtimes", lastArgs);
|
Assert.Equal("--list-runtimes", lastArgs);
|
||||||
Assert.Equal(2, runtimes.Count);
|
Assert.Equal(2, runtimes.Count);
|
||||||
Assert.Contains("Microsoft.AspNetCore.App 7.0.2 [/path/dotnet/shared/Microsoft.AspNetCore.App]", runtimes);
|
Assert.Contains("Microsoft.AspNetCore.App 7.0.2 [/path/dotnet/shared/Microsoft.AspNetCore.App]", runtimes);
|
||||||
@@ -209,15 +209,15 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetGetListedRuntimes2()
|
public void TestDotnetGetListedRuntimes2()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(MakeDotnetListRuntimesOutput());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(MakeDotnetListRuntimesOutput());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
dotnetCommand.Success = false;
|
dotnetCliInvoker.Success = false;
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
var runtimes = dotnet.GetListedRuntimes();
|
var runtimes = dotnet.GetListedRuntimes();
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("--list-runtimes", lastArgs);
|
Assert.Equal("--list-runtimes", lastArgs);
|
||||||
Assert.Empty(runtimes);
|
Assert.Empty(runtimes);
|
||||||
}
|
}
|
||||||
@@ -226,14 +226,14 @@ namespace Semmle.Extraction.Tests
|
|||||||
public void TestDotnetExec()
|
public void TestDotnetExec()
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var dotnetCommand = new DotnetCommandStub(new List<string>());
|
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>());
|
||||||
var dotnet = MakeDotnet(dotnetCommand);
|
var dotnet = MakeDotnet(dotnetCliInvoker);
|
||||||
|
|
||||||
// Execute
|
// Execute
|
||||||
dotnet.Exec("myarg1 myarg2");
|
dotnet.Exec("myarg1 myarg2");
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
var lastArgs = dotnetCommand.GetLastArgs();
|
var lastArgs = dotnetCliInvoker.GetLastArgs();
|
||||||
Assert.Equal("exec myarg1 myarg2", lastArgs);
|
Assert.Equal("exec myarg1 myarg2", lastArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user