diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs index 796c60f9f31..c573c5ff4e6 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs @@ -35,7 +35,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching private void Info() { - var res = dotnetCliInvoker.RunCommand("--info"); + var res = dotnetCliInvoker.RunCommand("--info", silent: false); if (!res) { throw new Exception($"{dotnetCliInvoker.Exec} --info failed."); @@ -91,13 +91,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching return dotnetCliInvoker.RunCommand(args); } - public IList GetListedRuntimes() => GetResultList("--list-runtimes"); + public IList GetListedRuntimes() => GetResultList("--list-runtimes", null, false); - public IList GetListedSdks() => GetResultList("--list-sdks"); + public IList GetListedSdks() => GetResultList("--list-sdks", null, false); - private IList GetResultList(string args, string? workingDirectory = null) + private IList GetResultList(string args, string? workingDirectory = null, bool silent = true) { - if (dotnetCliInvoker.RunCommand(args, workingDirectory, out var results)) + if (dotnetCliInvoker.RunCommand(args, workingDirectory, out var results, silent)) { return results; } @@ -316,4 +316,4 @@ namespace Semmle.Extraction.CSharp.DependencyFetching }); } } -} \ No newline at end of file +} diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs index 737c73b635e..1802521e28d 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs @@ -40,13 +40,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching return startInfo; } - private bool RunCommandAux(string args, string? workingDirectory, out IList output) + private bool RunCommandAux(string args, string? workingDirectory, out IList output, bool silent) { var dirLog = string.IsNullOrWhiteSpace(workingDirectory) ? "" : $" in {workingDirectory}"; logger.LogInfo($"Running {Exec} {args}{dirLog}"); var pi = MakeDotnetStartInfo(args, workingDirectory); var threadId = Environment.CurrentManagedThreadId; - void onOut(string s) => logger.LogInfo(s, threadId); + void onOut(string s) => logger.Log(silent ? Severity.Debug : Severity.Info, s, threadId); void onError(string s) => logger.LogError(s, threadId); var exitCode = pi.ReadOutput(out output, onOut, onError); if (exitCode != 0) @@ -57,13 +57,13 @@ namespace Semmle.Extraction.CSharp.DependencyFetching return true; } - public bool RunCommand(string args) => - RunCommandAux(args, null, out _); + public bool RunCommand(string args, bool silent) => + RunCommandAux(args, null, out _, silent); - public bool RunCommand(string args, out IList output) => - RunCommandAux(args, null, out output); + public bool RunCommand(string args, out IList output, bool silent) => + RunCommandAux(args, null, out output, silent); - public bool RunCommand(string args, string? workingDirectory, out IList output) => - RunCommandAux(args, workingDirectory, out output); + public bool RunCommand(string args, string? workingDirectory, out IList output, bool silent) => + RunCommandAux(args, workingDirectory, out output, silent); } } diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNetCliInvoker.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNetCliInvoker.cs index 0e35c0574ae..bfc8b44ee56 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNetCliInvoker.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNetCliInvoker.cs @@ -11,19 +11,22 @@ namespace Semmle.Extraction.CSharp.DependencyFetching /// /// Execute `dotnet ` and return true if the command succeeded, otherwise false. + /// If `silent` is true the output of the command is logged as `debug` otherwise as `info`. /// - bool RunCommand(string args); + bool RunCommand(string args, bool silent = true); /// /// Execute `dotnet ` and return true if the command succeeded, otherwise false. /// The output of the command is returned in `output`. + /// If `silent` is true the output of the command is logged as `debug` otherwise as `info`. /// - bool RunCommand(string args, out IList output); + bool RunCommand(string args, out IList output, bool silent = true); /// /// Execute `dotnet ` in `` and return true if the command succeeded, otherwise false. /// The output of the command is returned in `output`. + /// If `silent` is true the output of the command is logged as `debug` otherwise as `info`. /// - bool RunCommand(string args, string? workingDirectory, out IList output); + bool RunCommand(string args, string? workingDirectory, out IList output, bool silent = true); } } diff --git a/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs b/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs index de167e14e4b..0f6683d3298 100644 --- a/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs +++ b/csharp/extractor/Semmle.Extraction.Tests/DotNet.cs @@ -20,23 +20,23 @@ namespace Semmle.Extraction.Tests public string Exec => "dotnet"; - public bool RunCommand(string args) + public bool RunCommand(string args, bool silent) { lastArgs = args; return Success; } - public bool RunCommand(string args, out IList output) + public bool RunCommand(string args, out IList output, bool silent) { lastArgs = args; output = this.output; return Success; } - public bool RunCommand(string args, string? workingDirectory, out IList output) + public bool RunCommand(string args, string? workingDirectory, out IList output, bool silent) { WorkingDirectory = workingDirectory ?? ""; - return RunCommand(args, out output); + return RunCommand(args, out output, silent); } public string GetLastArgs() => lastArgs;