forked from cake-build/cake
/
DotCoverCoverer.cs
97 lines (84 loc) · 3.25 KB
/
DotCoverCoverer.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.DotCover.Cover
{
/// <summary>
/// DotCover Coverer builder.
/// </summary>
public sealed class DotCoverCoverer : DotCoverCoverageTool<DotCoverCoverSettings>
{
private readonly ICakeEnvironment _environment;
/// <summary>
/// Initializes a new instance of the <see cref="DotCoverCoverer" /> 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 DotCoverCoverer(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools) : base(fileSystem, environment, processRunner, tools)
{
_environment = environment;
}
/// <summary>
/// Runs DotCover Cover with the specified settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="action">The action.</param>
/// <param name="outputPath">The output file path.</param>
/// <param name="settings">The settings.</param>
public void Cover(ICakeContext context,
Action<ICakeContext> action,
FilePath outputPath,
DotCoverCoverSettings settings)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
if (outputPath == null)
{
throw new ArgumentNullException(nameof(outputPath));
}
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
// Run the tool.
Run(settings, GetArguments(context, action, settings, outputPath));
}
private ProcessArgumentBuilder GetArguments(
ICakeContext context,
Action<ICakeContext> action,
DotCoverCoverSettings settings,
FilePath outputPath)
{
var builder = new ProcessArgumentBuilder();
builder.Append("Cover");
// Set configuration file if exists.
GetConfigurationFileArgument(settings).CopyTo(builder);
// Get Target executable arguments
GetTargetArguments(context, action).CopyTo(builder);
// Set the output file.
outputPath = outputPath.MakeAbsolute(_environment);
builder.AppendSwitch("/Output", "=", outputPath.FullPath.Quote());
// Get Coverage arguments
GetCoverageArguments(settings).CopyTo(builder);
// Get base arguments
GetArguments(settings).CopyTo(builder);
return builder;
}
}
}