Skip to content

Commit 124704e

Browse files
authored
Merge pull request #4398 from Marusyk/marusyk/dotnetalias-partial
Refactor DotNetAliases: Extract methods into a separate partial class
2 parents 1ea4871 + dee2ff3 commit 124704e

19 files changed

+3515
-3128
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Cake.Common.Tools.DotNet.Build;
7+
using Cake.Core;
8+
using Cake.Core.Annotations;
9+
10+
namespace Cake.Common.Tools.DotNet
11+
{
12+
/// <summary>
13+
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
14+
/// <para>
15+
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
16+
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
17+
/// on how to install.
18+
/// </para>
19+
/// </summary>
20+
public static partial class DotNetAliases
21+
{
22+
/// <summary>
23+
/// Build all projects.
24+
/// </summary>
25+
/// <param name="context">The context.</param>
26+
/// <param name="project">The projects path.</param>
27+
/// <example>
28+
/// <code>
29+
/// DotNetBuild("./src/*");
30+
/// </code>
31+
/// </example>
32+
[CakeMethodAlias]
33+
[CakeAliasCategory("Build")]
34+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Build")]
35+
public static void DotNetBuild(this ICakeContext context, string project)
36+
{
37+
context.DotNetBuild(project, null);
38+
}
39+
40+
/// <summary>
41+
/// Build all projects.
42+
/// </summary>
43+
/// <param name="context">The context.</param>
44+
/// <param name="project">The projects path.</param>
45+
/// <param name="settings">The settings.</param>
46+
/// <example>
47+
/// <code>
48+
/// var settings = new DotNetBuildSettings
49+
/// {
50+
/// Framework = "netcoreapp2.0",
51+
/// Configuration = "Debug",
52+
/// OutputDirectory = "./artifacts/"
53+
/// };
54+
///
55+
/// DotNetBuild("./src/*", settings);
56+
/// </code>
57+
/// </example>
58+
[CakeMethodAlias]
59+
[CakeAliasCategory("Build")]
60+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Build")]
61+
public static void DotNetBuild(this ICakeContext context, string project, DotNetBuildSettings settings)
62+
{
63+
if (context is null)
64+
{
65+
throw new ArgumentNullException(nameof(context));
66+
}
67+
68+
if (settings is null)
69+
{
70+
settings = new DotNetBuildSettings();
71+
}
72+
73+
var builder = new DotNetBuilder(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
74+
builder.Build(project, settings);
75+
}
76+
}
77+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Cake.Common.Tools.DotNet.BuildServer;
7+
using Cake.Core;
8+
using Cake.Core.Annotations;
9+
10+
namespace Cake.Common.Tools.DotNet
11+
{
12+
/// <summary>
13+
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
14+
/// <para>
15+
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
16+
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
17+
/// on how to install.
18+
/// </para>
19+
/// </summary>
20+
public static partial class DotNetAliases
21+
{
22+
/// <summary>
23+
/// Shuts down build servers that are started from dotnet.
24+
/// </summary>
25+
/// <param name="context">The context.</param>
26+
/// <example>
27+
/// <code>
28+
/// DotNetBuildServerShutdown();
29+
/// </code>
30+
/// </example>
31+
[CakeMethodAlias]
32+
[CakeAliasCategory("Build Server")]
33+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.BuildServer")]
34+
public static void DotNetBuildServerShutdown(this ICakeContext context)
35+
{
36+
context.DotNetBuildServerShutdown(null);
37+
}
38+
39+
/// <summary>
40+
/// Shuts down build servers that are started from dotnet.
41+
/// </summary>
42+
/// <param name="context">The context.</param>
43+
/// <param name="settings">The settings.</param>
44+
/// <example>
45+
/// <code>
46+
/// var settings = new DotNetBuildServerShutdownSettings
47+
/// {
48+
/// MSBuild = true
49+
/// };
50+
///
51+
/// DotNetBuildServerShutdown(settings);
52+
/// </code>
53+
/// </example>
54+
[CakeMethodAlias]
55+
[CakeAliasCategory("Build Server")]
56+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.BuildServer")]
57+
public static void DotNetBuildServerShutdown(this ICakeContext context, DotNetBuildServerShutdownSettings settings)
58+
{
59+
if (context is null)
60+
{
61+
throw new ArgumentNullException(nameof(context));
62+
}
63+
64+
var buildServer = new DotNetBuildServer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
65+
66+
buildServer.Shutdown(settings ?? new DotNetBuildServerShutdownSettings());
67+
}
68+
}
69+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Cake.Common.Tools.DotNet.Clean;
7+
using Cake.Core;
8+
using Cake.Core.Annotations;
9+
10+
namespace Cake.Common.Tools.DotNet
11+
{
12+
/// <summary>
13+
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
14+
/// <para>
15+
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
16+
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
17+
/// on how to install.
18+
/// </para>
19+
/// </summary>
20+
public static partial class DotNetAliases
21+
{
22+
/// <summary>
23+
/// Cleans a project's output.
24+
/// </summary>
25+
/// <param name="context">The context.</param>
26+
/// <param name="project">The project's path.</param>
27+
/// <example>
28+
/// <code>
29+
/// DotNetClean("./src/project");
30+
/// </code>
31+
/// </example>
32+
[CakeMethodAlias]
33+
[CakeAliasCategory("Clean")]
34+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Clean")]
35+
public static void DotNetClean(this ICakeContext context, string project)
36+
{
37+
context.DotNetClean(project, null);
38+
}
39+
40+
/// <summary>
41+
/// Cleans a project's output.
42+
/// </summary>
43+
/// <param name="context">The context.</param>
44+
/// <param name="project">The projects path.</param>
45+
/// <param name="settings">The settings.</param>
46+
/// <example>
47+
/// <code>
48+
/// var settings = new DotNetCleanSettings
49+
/// {
50+
/// Framework = "netcoreapp2.0",
51+
/// Configuration = "Debug",
52+
/// OutputDirectory = "./artifacts/"
53+
/// };
54+
///
55+
/// DotNetClean("./src/project", settings);
56+
/// </code>
57+
/// </example>
58+
[CakeMethodAlias]
59+
[CakeAliasCategory("Clean")]
60+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Clean")]
61+
public static void DotNetClean(this ICakeContext context, string project, DotNetCleanSettings settings)
62+
{
63+
if (context is null)
64+
{
65+
throw new ArgumentNullException(nameof(context));
66+
}
67+
68+
if (settings is null)
69+
{
70+
settings = new DotNetCleanSettings();
71+
}
72+
73+
var cleaner = new DotNetCleaner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
74+
cleaner.Clean(project, settings);
75+
}
76+
}
77+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Cake.Common.Tools.DotNet.Execute;
7+
using Cake.Core;
8+
using Cake.Core.Annotations;
9+
using Cake.Core.IO;
10+
11+
namespace Cake.Common.Tools.DotNet
12+
{
13+
/// <summary>
14+
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
15+
/// <para>
16+
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
17+
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
18+
/// on how to install.
19+
/// </para>
20+
/// </summary>
21+
public static partial class DotNetAliases
22+
{
23+
/// <summary>
24+
/// Execute an assembly.
25+
/// </summary>
26+
/// <param name="context">The context.</param>
27+
/// <param name="assemblyPath">The assembly path.</param>
28+
/// <example>
29+
/// <code>
30+
/// DotNetExecute("./bin/Debug/app.dll");
31+
/// </code>
32+
/// </example>
33+
[CakeMethodAlias]
34+
[CakeAliasCategory("Execute")]
35+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
36+
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath)
37+
{
38+
context.DotNetExecute(assemblyPath, null);
39+
}
40+
41+
/// <summary>
42+
/// Execute an assembly with arguments in the specific path.
43+
/// </summary>
44+
/// <param name="context">The context.</param>
45+
/// <param name="assemblyPath">The assembly path.</param>
46+
/// <param name="arguments">The arguments.</param>
47+
/// <example>
48+
/// <code>
49+
/// DotNetExecute("./bin/Debug/app.dll", "--arg");
50+
/// </code>
51+
/// </example>
52+
[CakeMethodAlias]
53+
[CakeAliasCategory("Execute")]
54+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
55+
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath, ProcessArgumentBuilder arguments)
56+
{
57+
context.DotNetExecute(assemblyPath, arguments, null);
58+
}
59+
60+
/// <summary>
61+
/// Execute an assembly with arguments in the specific path with settings.
62+
/// </summary>
63+
/// <param name="context">The context.</param>
64+
/// <param name="assemblyPath">The assembly path.</param>
65+
/// <param name="arguments">The arguments.</param>
66+
/// <param name="settings">The settings.</param>
67+
/// <example>
68+
/// <code>
69+
/// var settings = new DotNetExecuteSettings
70+
/// {
71+
/// FrameworkVersion = "1.0.3"
72+
/// };
73+
///
74+
/// DotNetExecute("./bin/Debug/app.dll", "--arg", settings);
75+
/// </code>
76+
/// </example>
77+
[CakeMethodAlias]
78+
[CakeAliasCategory("Execute")]
79+
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
80+
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath, ProcessArgumentBuilder arguments, DotNetExecuteSettings settings)
81+
{
82+
if (context is null)
83+
{
84+
throw new ArgumentNullException(nameof(context));
85+
}
86+
87+
if (assemblyPath is null)
88+
{
89+
throw new ArgumentNullException(nameof(assemblyPath));
90+
}
91+
92+
if (settings is null)
93+
{
94+
settings = new DotNetExecuteSettings();
95+
}
96+
97+
var executor = new DotNetExecutor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
98+
executor.Execute(assemblyPath, arguments, settings);
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)