-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2018 Maintainers of NUKE. | ||
// Distributed under the MIT License. | ||
// https://github.com/nuke-build/nuke/blob/master/LICENSE | ||
|
||
using System; | ||
using System.Linq; | ||
using Nuke.Common.Execution; | ||
|
||
namespace Nuke.Common.Tooling | ||
{ | ||
/// <inheritdoc/> | ||
/// <summary> | ||
/// Injects a delegate for process execution. The path to the executable is resolved in the following order: | ||
/// <ul> | ||
/// <li>From environment variables (e.g., <c>[MEMBER_NAME]_EXE=path</c>)</li> | ||
/// <li> | ||
/// From the <c>.csproj</c> or <c>packages.config</c> file using <c>packageId</c> and | ||
/// <c>packageExecutable</c> to look up the NuGet package cache | ||
/// </li> | ||
/// </ul> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
/// <example> | ||
/// <code> | ||
/// [PackageExecutable("NuGet.CommandLine", "nuget.exe")] readonly Tool NuGet; | ||
/// Target FooBar => _ => _ | ||
/// .Executes(() => | ||
/// { | ||
/// var process = NuGet($"pack {ProjectFile}"); | ||
/// process.AssertZeroExitCode(); | ||
/// }); | ||
/// </code> | ||
/// </example> | ||
public class PackageExecutableAttribute : InjectionAttributeBase | ||
{ | ||
private readonly string _packageId; | ||
private readonly string _packageExecutable; | ||
private readonly string _framework; | ||
|
||
public PackageExecutableAttribute(string packageId, string packageExecutable, string framework = null) | ||
{ | ||
_packageId = packageId; | ||
_packageExecutable = packageExecutable; | ||
_framework = framework; | ||
} | ||
|
||
public override object GetValue(string memberName, Type memberType) | ||
{ | ||
var toolPath = | ||
ToolPathResolver.TryGetEnvironmentExecutable($"{memberName.ToUpperInvariant()}_EXE") ?? | ||
ToolPathResolver.GetPackageExecutable(_packageId, _packageExecutable, _framework); | ||
return new Tool(new ToolExecutor(toolPath).Execute); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2018 Maintainers of NUKE. | ||
// Distributed under the MIT License. | ||
// https://github.com/nuke-build/nuke/blob/master/LICENSE | ||
|
||
using System; | ||
using System.Linq; | ||
using Nuke.Common.Execution; | ||
|
||
namespace Nuke.Common.Tooling | ||
{ | ||
/// <inheritdoc/> | ||
/// <summary> | ||
/// Injects a delegate for process execution. The executable name is derived from the member name or can be | ||
/// passed as constructor argument. The path to the executable is resolved in the following order: | ||
/// <ul> | ||
/// <li>From environment variables (e.g., <c>[NAME]_EXE=path</c>)</li> | ||
/// <li>From the PATH variable using <c>which</c> or <c>where</c></li> | ||
/// </ul> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
/// <example> | ||
/// <code> | ||
/// [PathExecutable] readonly Tool Echo; | ||
/// Target FooBar => _ => _ | ||
/// .Executes(() => | ||
/// { | ||
/// var process = Echo("test"); | ||
/// process.AssertZeroExitCode(); | ||
/// }); | ||
/// </code> | ||
/// </example> | ||
public class PathExecutableAttribute : InjectionAttributeBase | ||
{ | ||
private readonly string _name; | ||
|
||
public PathExecutableAttribute(string name = null) | ||
{ | ||
_name = name; | ||
} | ||
|
||
public override object GetValue(string memberName, Type memberType) | ||
{ | ||
var name = _name ?? memberName; | ||
var toolPath = | ||
ToolPathResolver.TryGetEnvironmentExecutable($"{name.ToUpperInvariant()}_EXE") ?? | ||
ToolPathResolver.GetPathExecutable(name); | ||
return new Tool(new ToolExecutor(toolPath).Execute); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 Maintainers of NUKE. | ||
// Distributed under the MIT License. | ||
// https://github.com/nuke-build/nuke/blob/master/LICENSE | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Nuke.Common.Tooling | ||
{ | ||
public delegate IProcess Tool( | ||
string arguments = null, | ||
string workingDirectory = null, | ||
IReadOnlyDictionary<string, string> environmentVariables = null, | ||
int? timeout = null, | ||
bool logOutput = true, | ||
Func<string, LogLevel> logLevelParser = null, | ||
Func<string, string> outputFilter = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 Maintainers of NUKE. | ||
// Distributed under the MIT License. | ||
// https://github.com/nuke-build/nuke/blob/master/LICENSE | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Nuke.Common.Tooling | ||
{ | ||
internal class ToolExecutor | ||
{ | ||
private readonly string _toolPath; | ||
|
||
public ToolExecutor(string toolPath) | ||
{ | ||
_toolPath = toolPath; | ||
} | ||
|
||
public IProcess Execute( | ||
string arguments = null, | ||
string workingDirectory = null, | ||
IReadOnlyDictionary<string, string> environmentVariables = null, | ||
int? timeout = null, | ||
bool logOutput = true, | ||
Func<string, LogLevel> logLevelParser = null, | ||
Func<string, string> outputFilter = null) | ||
{ | ||
return ProcessTasks.StartProcess( | ||
_toolPath, | ||
arguments, | ||
workingDirectory, | ||
environmentVariables, | ||
timeout, | ||
logOutput, | ||
logLevelParser, | ||
outputFilter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters