Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

GH2228: Fix CakeTaskExtensions accessibility #2231

Merged
merged 2 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cake.Core.Tests/Unit/CakeTaskExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Should_Throw_If_Criteria_Is_Null()
var result = Record.Exception(() => task.AddCriteria(null));

// Then
AssertEx.IsArgumentNullException(result, "criteria");
AssertEx.IsArgumentNullException(result, "predicate");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Core.Tests/Unit/CakeTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void Should_Throw_If_Criteria_Is_Null()
var result = Record.Exception(() => task.AddCriteria(null));

// Then
AssertEx.IsArgumentNullException(result, "criteria");
AssertEx.IsArgumentNullException(result, "predicate");
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/Cake.Core/CakeTaskCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class CakeTaskCriteria
/// </summary>
/// <param name="predicate">The criteria's predicate.</param>
/// <param name="message">The criteria's message if skipped.</param>
/// <exception cref="ArgumentNullException"><paramref name="predicate"/> is null.</exception>
public CakeTaskCriteria(Func<ICakeContext, bool> predicate, string message = null)
{
Predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));
Expand Down
1 change: 1 addition & 0 deletions src/Cake.Core/CakeTaskDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class CakeTaskDependency
/// </summary>
/// <param name="name">The name of the task.</param>
/// <param name="required">Whether or not the dependency is required.</param>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
public CakeTaskDependency(string name, bool required)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Expand Down
71 changes: 64 additions & 7 deletions src/Cake.Core/CakeTaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@

namespace Cake.Core
{
internal static class CakeTaskExtensions
/// <summary>
/// Contains extension methods for <see cref="CakeTask"/>.
/// </summary>
public static class CakeTaskExtensions
{
/// <summary>
/// Adds the dependency to the task's dependencies.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="name">The name of the dependency .</param>
/// <param name="required">Whether or not the dependency is required.</param>
/// <exception cref="CakeException">The task already has the dependency.</exception>
public static void AddDependency(this CakeTask task, string name, bool required = true)
{
if (task.Dependencies.Any(x => x.Name == name))
Expand All @@ -18,6 +28,13 @@ public static void AddDependency(this CakeTask task, string name, bool required
task.Dependencies.Add(new CakeTaskDependency(name, required));
}

/// <summary>
/// Adds the dependee to the task's dependees.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="name">The name of the dependee.</param>
/// <param name="required">Whether or not the dependee is required.</param>
/// <exception cref="CakeException">The task already is a dependee.</exception>
public static void AddDependee(this CakeTask task, string name, bool required = true)
{
if (task.Dependees.Any(x => x.Name == name))
Expand All @@ -29,15 +46,24 @@ public static void AddDependee(this CakeTask task, string name, bool required =
task.Dependees.Add(new CakeTaskDependency(name, required));
}

public static void AddCriteria(this CakeTask task, Func<ICakeContext, bool> criteria, string message = null)
/// <summary>
/// Adds the criteria to the task's criterias.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="predicate">The criteria's predicate.</param>
/// <param name="message">The criteria's message if skipped.</param>
public static void AddCriteria(this CakeTask task, Func<ICakeContext, bool> predicate, string message = null)
{
if (criteria == null)
{
throw new ArgumentNullException(nameof(criteria));
}
task.Criterias.Add(new CakeTaskCriteria(criteria, message));
task.Criterias.Add(new CakeTaskCriteria(predicate, message));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:

  • I renamed the parameter from criteria to predicate to match the parameter name in the CakeTaskCriteria ctor
  • I removed the check for null here because the CakeTaskCriteria ctor already does that

}

/// <summary>
/// Sets the task's error handler.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="errorHandler">The error handler.</param>
/// <exception cref="CakeException">There can only be one error handler per task.</exception>
/// <exception cref="ArgumentNullException"><paramref name="errorHandler"/> is null.</exception>
public static void SetErrorHandler(this CakeTask task, Action<Exception> errorHandler)
{
if (task.ErrorHandler != null)
Expand All @@ -47,6 +73,13 @@ public static void SetErrorHandler(this CakeTask task, Action<Exception> errorHa
task.ErrorHandler = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
}

/// <summary>
/// Sets the task's error reporter.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="errorReporter">The error reporter.</param>
/// <exception cref="CakeException">There can only be one error reporter per task.</exception>
/// <exception cref="ArgumentNullException"><paramref name="errorReporter"/> is null.</exception>
public static void SetErrorReporter(this CakeTask task, Action<Exception> errorReporter)
{
if (task.ErrorReporter != null)
Expand All @@ -56,6 +89,13 @@ public static void SetErrorReporter(this CakeTask task, Action<Exception> errorR
task.ErrorReporter = errorReporter ?? throw new ArgumentNullException(nameof(errorReporter));
}

/// <summary>
/// Sets the task's finally handler.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="finallyHandler">The finally handler.</param>
/// <exception cref="CakeException">There can only be one finally handler per task.</exception>
/// <exception cref="ArgumentNullException"><paramref name="finallyHandler"/> is null.</exception>
public static void SetFinallyHandler(this CakeTask task, Action finallyHandler)
{
if (task.FinallyHandler != null)
Expand All @@ -65,6 +105,12 @@ public static void SetFinallyHandler(this CakeTask task, Action finallyHandler)
task.FinallyHandler = finallyHandler ?? throw new ArgumentNullException(nameof(finallyHandler));
}

/// <summary>
/// Adds the action to the task's actions.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="action">The action.</param>
/// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
public static void AddAction(this CakeTask task, Func<ICakeContext, Task> action)
{
if (action == null)
Expand All @@ -74,6 +120,12 @@ public static void AddAction(this CakeTask task, Func<ICakeContext, Task> action
task.Actions.Add(action);
}

/// <summary>
/// Adds the action to the task's delayed actions.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="action">The action.</param>
/// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
public static void AddDelayedAction(this CakeTask task, Action action)
{
if (action == null)
Expand All @@ -83,6 +135,11 @@ public static void AddDelayedAction(this CakeTask task, Action action)
task.DelayedActions.Enqueue(action);
}

/// <summary>
/// Sets the task's defer exceptions state.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="value">The defer exceptions state.</param>
public static void SetDeferExceptions(this CakeTask task, bool value)
{
task.DeferExceptions = value;
Expand Down