Skip to content

Commit

Permalink
Refactor DotNetAliases: Extract methods into a separate partial class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marusyk committed Nov 16, 2024
1 parent 8ca6cc3 commit ebbfd8e
Show file tree
Hide file tree
Showing 19 changed files with 3,441 additions and 3,054 deletions.
77 changes: 77 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.Common.Tools.DotNet.Build;
using Cake.Core;
using Cake.Core.Annotations;

namespace Cake.Common.Tools.DotNet
{
/// <summary>
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
/// <para>
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
/// on how to install.
/// </para>
/// </summary>
public static partial class DotNetAliases
{
/// <summary>
/// Build all projects.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The projects path.</param>
/// <example>
/// <code>
/// DotNetBuild("./src/*");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Build")]
public static void DotNetBuild(this ICakeContext context, string project)
{
context.DotNetBuild(project, null);
}

/// <summary>
/// Build all projects.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The projects path.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetBuildSettings
/// {
/// Framework = "netcoreapp2.0",
/// Configuration = "Debug",
/// OutputDirectory = "./artifacts/"
/// };
///
/// DotNetBuild("./src/*", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Build")]
public static void DotNetBuild(this ICakeContext context, string project, DotNetBuildSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (settings is null)
{
settings = new DotNetBuildSettings();
}

var builder = new DotNetBuilder(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
builder.Build(project, settings);
}
}
}
69 changes: 69 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.BuildServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.Common.Tools.DotNet.BuildServer;
using Cake.Core;
using Cake.Core.Annotations;

namespace Cake.Common.Tools.DotNet
{
/// <summary>
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
/// <para>
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
/// on how to install.
/// </para>
/// </summary>
public static partial class DotNetAliases
{
/// <summary>
/// Shuts down build servers that are started from dotnet.
/// </summary>
/// <param name="context">The context.</param>
/// <example>
/// <code>
/// DotNetBuildServerShutdown();
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build Server")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.BuildServer")]
public static void DotNetBuildServerShutdown(this ICakeContext context)
{
context.DotNetBuildServerShutdown(null);
}

/// <summary>
/// Shuts down build servers that are started from dotnet.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetBuildServerShutdownSettings
/// {
/// MSBuild = true
/// };
///
/// DotNetBuildServerShutdown(settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build Server")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.BuildServer")]
public static void DotNetBuildServerShutdown(this ICakeContext context, DotNetBuildServerShutdownSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

var buildServer = new DotNetBuildServer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);

buildServer.Shutdown(settings ?? new DotNetBuildServerShutdownSettings());
}
}
}
77 changes: 77 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.Clean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.Common.Tools.DotNet.Clean;
using Cake.Core;
using Cake.Core.Annotations;

namespace Cake.Common.Tools.DotNet
{
/// <summary>
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
/// <para>
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
/// on how to install.
/// </para>
/// </summary>
public static partial class DotNetAliases
{
/// <summary>
/// Cleans a project's output.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The project's path.</param>
/// <example>
/// <code>
/// DotNetClean("./src/project");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Clean")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Clean")]
public static void DotNetClean(this ICakeContext context, string project)
{
context.DotNetClean(project, null);
}

/// <summary>
/// Cleans a project's output.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="project">The projects path.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetCleanSettings
/// {
/// Framework = "netcoreapp2.0",
/// Configuration = "Debug",
/// OutputDirectory = "./artifacts/"
/// };
///
/// DotNetClean("./src/project", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Clean")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Clean")]
public static void DotNetClean(this ICakeContext context, string project, DotNetCleanSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (settings is null)
{
settings = new DotNetCleanSettings();
}

var cleaner = new DotNetCleaner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
cleaner.Clean(project, settings);
}
}
}
101 changes: 101 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.Execute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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.Common.Tools.DotNet.Execute;
using Cake.Core;
using Cake.Core.Annotations;
using Cake.Core.IO;

namespace Cake.Common.Tools.DotNet
{
/// <summary>
/// <para>Contains functionality related to <see href="https://github.com/dotnet/cli">.NET CLI</see>.</para>
/// <para>
/// In order to use the commands for this alias, the .NET CLI tools will need to be installed on the machine where
/// the Cake script is being executed. See this <see href="https://www.microsoft.com/net/core">page</see> for information
/// on how to install.
/// </para>
/// </summary>
public static partial class DotNetAliases
{
/// <summary>
/// Execute an assembly.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="assemblyPath">The assembly path.</param>
/// <example>
/// <code>
/// DotNetExecute("./bin/Debug/app.dll");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Execute")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath)
{
context.DotNetExecute(assemblyPath, null);
}

/// <summary>
/// Execute an assembly with arguments in the specific path.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="assemblyPath">The assembly path.</param>
/// <param name="arguments">The arguments.</param>
/// <example>
/// <code>
/// DotNetExecute("./bin/Debug/app.dll", "--arg");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Execute")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath, ProcessArgumentBuilder arguments)
{
context.DotNetExecute(assemblyPath, arguments, null);
}

/// <summary>
/// Execute an assembly with arguments in the specific path with settings.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="assemblyPath">The assembly path.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="settings">The settings.</param>
/// <example>
/// <code>
/// var settings = new DotNetExecuteSettings
/// {
/// FrameworkVersion = "1.0.3"
/// };
///
/// DotNetExecute("./bin/Debug/app.dll", "--arg", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Execute")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.Execute")]
public static void DotNetExecute(this ICakeContext context, FilePath assemblyPath, ProcessArgumentBuilder arguments, DotNetExecuteSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (assemblyPath is null)
{
throw new ArgumentNullException(nameof(assemblyPath));
}

if (settings is null)
{
settings = new DotNetExecuteSettings();
}

var executor = new DotNetExecutor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
executor.Execute(assemblyPath, arguments, settings);
}
}
}
Loading

0 comments on commit ebbfd8e

Please sign in to comment.