Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/Cake.Frosting/AsyncFrostingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Cake.Core;

Expand All @@ -24,6 +25,9 @@ public abstract class AsyncFrostingTask : AsyncFrostingTask<ICakeContext>
public abstract class AsyncFrostingTask<T> : IFrostingTask
where T : ICakeContext
{
/// <inheritdoc/>
public virtual List<CakeTaskCriteria> ShouldRunCriteria => new List<CakeTaskCriteria>();

/// <summary>
/// Runs the task using the specified context.
/// </summary>
Expand All @@ -41,6 +45,7 @@ public virtual Task RunAsync(T context)
/// <returns>
/// <c>true</c> if the task should run; otherwise <c>false</c>.
/// </returns>
[Obsolete("ShouldRun method will be removed in a future version")]
public virtual bool ShouldRun(T context)
{
return true;
Expand Down Expand Up @@ -79,6 +84,7 @@ Task IFrostingTask.RunAsync(ICakeContext context)
}

/// <inheritdoc/>
[Obsolete("ShouldRun method will be removed in a future version")]
bool IFrostingTask.ShouldRun(ICakeContext context)
{
if (context is null)
Expand Down
4 changes: 4 additions & 0 deletions src/Cake.Frosting/FrostingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Cake.Core;

Expand All @@ -24,6 +25,9 @@ public abstract class FrostingTask : FrostingTask<ICakeContext>
public abstract class FrostingTask<T> : IFrostingTask
where T : ICakeContext
{
/// <inheritdoc/>
public virtual List<CakeTaskCriteria> ShouldRunCriteria => new List<CakeTaskCriteria>();

/// <summary>
/// Runs the task using the specified context.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Cake.Frosting/IFrostingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Cake.Core;

Expand All @@ -13,6 +14,11 @@ namespace Cake.Frosting
/// </summary>
public interface IFrostingTask
{
/// <summary>
/// Gets ShouldRunCriteria for this task.
/// </summary>
List<CakeTaskCriteria> ShouldRunCriteria { get; }

/// <summary>
/// Runs the task using the specified context.
/// </summary>
Expand All @@ -27,6 +33,7 @@ public interface IFrostingTask
/// <returns>
/// <c>true</c> if the task should run; otherwise <c>false</c>.
/// </returns>
[Obsolete("ShouldRun method will be removed in a future version")]
bool ShouldRun(ICakeContext context);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static bool IsRunOverridden(this IFrostingTask task, IFrostingContext con
throw new InvalidOperationException($"This method expects all {nameof(IFrostingTask)} to be instances of {nameof(FrostingTask)} or {nameof(AsyncFrostingTask)}.");
}

[Obsolete("ShouldRun method will be removed in a future version")]
public static bool IsShouldRunOverridden(this IFrostingTask task, IFrostingContext context)
{
return task.GetType().GetMethod(nameof(IFrostingTask.ShouldRun), new[] { context.GetType() }).IsOverriden();
Expand Down
15 changes: 13 additions & 2 deletions src/Cake.Frosting/Internal/FrostingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;
Expand Down Expand Up @@ -125,11 +126,21 @@ private void ConfigureTasks()
cakeTask.Does(task.RunAsync);
}

// Is the criteria method overridden?
if (task.IsShouldRunOverridden(_context))
// Check if and criteria added to ShouldRunCriteria?
if (task.ShouldRunCriteria.Any())
{
foreach (var criteria in task.ShouldRunCriteria)
{
cakeTask.WithCriteria(criteria.Predicate, criteria.Message);
}
}
// Check to see if obsoleted ShouldRun is overridden? Done to not break old projects.
#pragma warning disable CS0618 // Type or member is obsolete
else if (task.IsShouldRunOverridden(_context))
{
cakeTask.WithCriteria(task.ShouldRun, task.SkippedMessage);
}
#pragma warning restore CS0618 // Type or member is obsolete

// Continue on error?
if (task.IsContinueOnError())
Expand Down
Loading