-
-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathDotNetToolRunner.cs
More file actions
73 lines (63 loc) · 2.66 KB
/
DotNetToolRunner.cs
File metadata and controls
73 lines (63 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Tooling;
namespace Cake.Common.Tools.DotNet.Tool
{
/// <summary>
/// .NET Extensibility Commands Runner.
/// </summary>
public sealed class DotNetToolRunner : DotNetTool<DotNetSettings>
{
/// <summary>
/// Initializes a new instance of the <see cref="DotNetToolRunner" /> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="environment">The environment.</param>
/// <param name="processRunner">The process runner.</param>
/// <param name="tools">The tool locator.</param>
public DotNetToolRunner(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools) : base(fileSystem, environment, processRunner, tools)
{
}
/// <summary>
/// Execute an assembly using arguments and settings.
/// </summary>
/// <param name="projectPath">The target project path.</param>
/// <param name="command">The command to execute.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="settings">The settings.</param>
public void Execute(FilePath projectPath, string command, ProcessArgumentBuilder arguments, DotNetToolSettings settings)
{
if (string.IsNullOrWhiteSpace(command))
{
throw new ArgumentNullException(nameof(command));
}
ArgumentNullException.ThrowIfNull(settings);
var processSettings = new ProcessSettings
{
WorkingDirectory = settings.WorkingDirectory ?? projectPath?.GetDirectory()
};
RunCommand(settings, GetArguments(command, arguments, settings), processSettings);
}
private ProcessArgumentBuilder GetArguments(string command, ProcessArgumentBuilder arguments, DotNetToolSettings settings)
{
var builder = CreateArgumentBuilder(settings);
// Appending quoted to cater for scenarios where the command passed is not a .NET CLI command,
// but the path of an application to run that contains whitespace
builder.AppendQuoted(command);
// Arguments
if (!arguments.IsNullOrEmpty())
{
arguments.CopyTo(builder);
}
return builder;
}
}
}