Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

GH2008: Added support for typed contexts. #2016

Merged
merged 1 commit into from
May 26, 2018
Merged

GH2008: Added support for typed contexts. #2016

merged 1 commit into from
May 26, 2018

Conversation

patriksvensson
Copy link
Member

@patriksvensson patriksvensson commented Jan 23, 2018

This would remove dependencies on global variables and shared mutable states that make larger Cake script difficult to maintain in some scenarios. Declaring a Setup<TContextData> should be required to use the context data in the script. If no Setup<TContextData> has been declared, an error should be thrown when the script compiles.

There's also some work in this PR to simplify the CakeTaskBuilder. See explaination below that summarizes why this might be a good idea.

Example of API additions:

Declare a context in your Cake script like this:

public class MyData
{
    public string MyProperty { get; set; }
    public string WaitTime { get; set; }
}

And now you can use it like this:

#load "./MyData.cake"

/////////////////////////////////////////////////////
// SETUP / TEARDOWN
/////////////////////////////////////////////////////

Setup<MyData>(context => 
{
    return new MyData {
        WaitTime = 5,
        MyProperty = "Foo"
    }
});

/////////////////////////////////////////////////////
// TASKS
/////////////////////////////////////////////////////

Task("A")
    .Does<MyData>((data, context) => 
{
    Information("MyProperty = {0}", data.MyProperty);
});

Task("B")
    .Does<MyData>(data => 
{
    Information("MyProperty = {0}", data.MyProperty);
});

Task("C")
    .Does<MyData>(async data => 
{
    await Task.Delay(data.WaitTime * 1000);
});

Task("D")
    .Does<MyData>(async (data, context) => 
{
    await Task.Delay(data.WaitTime * 1000);
});

Task("E")
    .Does(context => 
{
    // We can add an alias to make it easier to get data.
    Information("MyProperty = {0}", 
        context.Data.Get<MyData>().MyProperty);
});

/////////////////////////////////////////////////////
// EXECUTE
/////////////////////////////////////////////////////

RunTarget("Second");

Summary from internal discussion with Cake team:

patrik 22:26
I started looking at doing changes to allow typed context, and the problems I encountered didn't have anything to do with the engine or script runner (those were kind of easy to tweak), but actually how CakeTaskBuilder<T> and CakeTask work. Right now we have two separate classes, CakeTask and ActionTask and a third CakeTaskBuilder<T> that composes tasks.

I think the original thought here were to make it easy to add new kind of tasks, but we've never actually encountered a use case for this. We also return a CakeTaskBuilder<ActionTask> in the IScriptHost implementation so it's kind of just an extra layer of indirection which actually (ironically) makes it more difficult to extend the task builder itself.

My proposal is to just have a single implementation CakeTask (that merges CakeTask and ActionTask) and a single builder CakeTaskBuilder. We would kind of close the door on adding new kind of tasks (until we add new support for it), but no one has been able to add new tasks anyway with the current design. In return we would remove complexity in Cake's core.

Another proposal is to make the task itself internal and mutable (It already is since we mutate state in the associated methods) and move guard statements to the extension methods. This will make the code cleaner.

{
internal sealed class CakeDataContextRepository : ICakeDataContextRepository
{
private object _data;
Copy link
Member Author

Choose a reason for hiding this comment

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

Allow more than one data context?

/// <summary>
/// Represent a data context.
/// </summary>
public interface ICakeDataContext
Copy link
Member Author

Choose a reason for hiding this comment

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

Marker interface

/// <summary>
/// Represents a data context repository.
/// </summary>
public interface ICakeDataContextRepository : ICakeDataContextResolver
Copy link
Member Author

Choose a reason for hiding this comment

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

I really hate this name.

@gep13 gep13 changed the title [PROOF OF CONCEPT] GH-2008: Added support for typed contexts (DO NOT MERGE) [PROOF OF CONCEPT] GH2008: Added support for typed contexts (DO NOT MERGE) Feb 22, 2018
@patriksvensson
Copy link
Member Author

Ping @cake-build/cake-team

@patriksvensson patriksvensson changed the title [PROOF OF CONCEPT] GH2008: Added support for typed contexts (DO NOT MERGE) [WIP] GH2008: Added support for typed contexts. Mar 14, 2018
@patriksvensson patriksvensson added this to the v0.27.0 milestone Mar 21, 2018
@patriksvensson patriksvensson changed the title [WIP] GH2008: Added support for typed contexts. GH2008: Added support for typed contexts. Mar 21, 2018
@patriksvensson
Copy link
Member Author

@cake-build/cake-team This is ready for review.

@gep13
Copy link
Member

gep13 commented Mar 23, 2018

Relates to #2008

@gep13 gep13 removed this from the v0.27.0 milestone Mar 23, 2018
Copy link
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 Would be great if an integration test was added too.

@devlead
Copy link
Member

devlead commented Mar 29, 2018

Tested with a Cake.Recipe project, looks like this causes serious issues there

/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(3,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(3,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(4,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(4,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(5,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(5,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(6,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(6,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(7,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(7,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(8,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(8,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(9,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(9,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(10,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(10,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(11,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(11,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(12,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(12,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(13,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(13,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(14,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(14,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(15,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(15,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(16,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(16,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(17,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(17,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(18,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(18,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(19,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(19,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(20,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(20,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(21,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(21,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(22,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(22,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(23,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(23,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(24,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(24,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(25,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(25,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(26,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(26,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(27,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(27,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(28,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(28,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(29,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(29,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(30,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(30,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(31,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(31,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(32,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(32,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(33,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(33,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(34,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(34,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(35,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(35,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(36,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(36,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(37,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(37,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(38,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(38,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(39,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(39,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(40,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(40,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(41,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(41,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(42,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(42,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(43,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(43,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(44,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(44,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(45,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(45,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(46,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(46,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(47,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(47,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(48,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(48,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(49,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(49,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(50,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(50,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(51,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(51,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(52,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(52,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(53,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(53,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(54,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(54,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(55,12): error CS0308: The non-generic type 'CakeTaskBuilder' cannot be used with type arguments
/Cake.Kudu.Client/tools/Cake.Recipe.0.3.0-unstable0369/Content/tasks.cake(55,28): error CS0246: The type or namespace name 'ActionTask' could not be found (are you missing a using directive or an assembly reference?)

Tested a few internal advanced Cake scripts and had a few similar issues.

@patriksvensson
Copy link
Member Author

@devlead Yeah, Cake.Recipe will probably need to be updated to not rely on ActionTask anymore.

@gep13
Copy link
Member

gep13 commented Mar 29, 2018

@patriksvensson what would the alternative be? Cake.Recipe uses ActionTask extensively to allow the manipulation of the Task Graph.

@patriksvensson
Copy link
Member Author

@gep13 ActionTask have been removed and merged with CakeTask. The previous separation made it impossible to do any bigger changes to the code base and really did not contribute anything.

@gep13
Copy link
Member

gep13 commented Mar 29, 2018

@patriksvensson so is it just a case of replacing ActionTask with CakeTask?

@patriksvensson
Copy link
Member Author

@gep13 Correct. I will add back ActionTask, inherit it from CakeTask and mark it as obsolete.

@patriksvensson
Copy link
Member Author

@cake-build/cake-team This is ready for review.

Been fixing some other minor issues as well in this PR (#1772, #1594) since I was touching the code these were related to and both of these were breaking changes (like the one I'm fixing).

Copy link
Member

@bjorkstromm bjorkstromm left a comment

Choose a reason for hiding this comment

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

Some minor changes and some questions.

Looks really good! Need to take it for a spin to. Great work! 👍

@@ -19,6 +19,7 @@ public sealed class CakeContextFixture
public IProcessRunner ProcessRunner { get; set; }
public IRegistry Registry { get; set; }
public IToolLocator Tools { get; set; }
public ICakeDataService DataContext { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Rename to DataService

@@ -72,6 +74,7 @@ public sealed class CakeContext : ICakeContext
ProcessRunner = processRunner;
Registry = registry;
Tools = tools;
Data = data;
Copy link
Member

Choose a reason for hiding this comment

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

Guard against null

_tasks = new List<CakeTask>();
_actions = new CakeEngineActions(dataService);
Copy link
Member

Choose a reason for hiding this comment

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

Guard against null?


public CakeEngineActions(ICakeDataService dataService)
{
_dataService = dataService;
Copy link
Member

Choose a reason for hiding this comment

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

Guard against null?

@@ -35,165 +30,114 @@ public abstract class CakeTask : ICakeTaskInfo
/// Gets the task's dependencies.
/// </summary>
/// <value>The task's dependencies.</value>
public IReadOnlyList<CakeTaskDependency> Dependencies => _dependencies;
public List<CakeTaskDependency> Dependencies { get; }
Copy link
Member

Choose a reason for hiding this comment

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

IList... Or is ISet or ICollection sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could probably change this to an ICollection.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed my mind here, would probably be best to keep compatibility here and use an IList.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, let's keep this a List. No reason to expose any other type here since it can't be replaced.


/// <summary>
/// Gets the tasks that the task want to be a dependency of.
/// </summary>
/// <value>The tasks that the task want to be a dependency of.</value>
public IReadOnlyList<CakeTaskDependency> Dependees => _reverseDependencies;
public List<CakeTaskDependency> Dependees { get; }
Copy link
Member

Choose a reason for hiding this comment

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

IList... Or is ISet or ICollection sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could probably change this to an ICollection.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed my mind here, would probably be best to keep compatibility here and use an IList.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, let's keep this a List. No reason to expose any other type here since it can't be replaced.


/// <summary>
/// Gets the task's criterias.
/// </summary>
/// <value>The task's criterias.</value>
public IReadOnlyList<Func<ICakeContext, bool>> Criterias => _criterias;
public List<CakeTaskCriteria> Criterias { get; }
Copy link
Member

Choose a reason for hiding this comment

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

IList... Or is ISet or ICollection sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could change this to an ICollection since criterias are inclusive (AND based).

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed my mind here, would probably be best to keep compatibility here and use an IList.

Name = name;
}
/// <value>The task's actions.</value>
public List<Func<ICakeContext, Task>> Actions { get; }
Copy link
Member

Choose a reason for hiding this comment

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

IList... Or is ISet or ICollection sufficient?

Copy link
Member Author

@patriksvensson patriksvensson May 23, 2018

Choose a reason for hiding this comment

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

We could change this to IList, but the collection should keep the order items were added and expose them by index to ensure backwards compatibility. There might be scripts that rely on the order actions are executed (even if that would be an implementation detail).

_criterias.Add(criteria);
}
IReadOnlyList<CakeTaskDependency> ICakeTaskInfo.Dependencies => Dependencies;
IReadOnlyList<CakeTaskDependency> ICakeTaskInfo.Dependees => Dependees;
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, so the interface exposes IReadOnlyList<T> but the class exposes List<T>. What was the reason for this? Should we instead change the type in the interface? (While we are breaking things 😄 )

Copy link
Member Author

Choose a reason for hiding this comment

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

@mholo65 The interface exposes a readonly view of the task and shouldn't be changed for backwards compatibility.

/// <param name="message">The criteria's message if skipped.</param>
public CakeTaskCriteria(Func<ICakeContext, bool> predicate, string message = null)
{
Predicate = predicate;
Copy link
Member

Choose a reason for hiding this comment

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

Guard against null predicate.

/// <param name="criteria">The criteria.</param>
/// <param name="message">The message to display if the task was skipped due to the provided criteria.</param>
/// <returns>The same <see cref="CakeTaskBuilder"/> instance so that multiple calls can be chained.</returns>
public static CakeTaskBuilder WithCriteria(this CakeTaskBuilder builder, Func<bool> criteria, string message)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we change order of criteria and message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Voting says we keep it.

/// <param name="criteria">The criteria.</param>
/// <param name="message">The message to display if the task was skipped due to the provided criteria.</param>
/// <returns>The same <see cref="CakeTaskBuilder"/> instance so that multiple calls can be chained.</returns>
public static CakeTaskBuilder WithCriteria(this CakeTaskBuilder builder, bool criteria, string message)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we change order of criteria and message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Voting says we keep it.

/// <param name="criteria">The criteria.</param>
/// <param name="message">The message to display if the task was skipped due to the provided criteria.</param>
/// <returns>The same <see cref="CakeTaskBuilder"/> instance so that multiple calls can be chained.</returns>
public static CakeTaskBuilder WithCriteria(this CakeTaskBuilder builder, Func<ICakeContext, bool> criteria, string message)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we change order of criteria and message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Voting says we keep it.

@devlead
Copy link
Member

devlead commented May 26, 2018

Initial and integration tests run fine for me.

Cake recipe fails, BUT! It's a very simple fix

diff --git a/Cake.Recipe/Content/tasks.cake b/Cake.Recipe/Content/tasks.cake
index d90626f..31d88a3 100644
--- a/Cake.Recipe/Content/tasks.cake
+++ b/Cake.Recipe/Content/tasks.cake
@@ -1,56 +1,56 @@
 public class BuildTasks
 {
-    public CakeTaskBuilder<ActionTask> DupFinderTask { get; set; }
-    public CakeTaskBuilder<ActionTask> InspectCodeTask { get; set; }
-    public CakeTaskBuilder<ActionTask> AnalyzeTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PrintAppVeyorEnvironmentVariablesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> UploadAppVeyorArtifactsTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ClearAppVeyorCacheTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ShowInfoTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CleanTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DotNetCoreCleanTask { get; set; }
-    public CakeTaskBuilder<ActionTask> RestoreTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DotNetCoreRestoreTask { get; set; }
-    public CakeTaskBuilder<ActionTask> BuildTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DotNetCoreBuildTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PackageTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DefaultTask { get; set; }
-    public CakeTaskBuilder<ActionTask> AppVeyorTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ReleaseNotesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ClearCacheTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PreviewTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PublishDocsTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CreateChocolateyPackagesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PublishChocolateyPackagesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> UploadCodecovReportTask { get; set; }
-    public CakeTaskBuilder<ActionTask> UploadCoverallsReportTask { get; set; }
-    public CakeTaskBuilder<ActionTask> UploadCoverageReportTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CreateReleaseNotesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ExportReleaseNotesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PublishGitHubReleaseTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DotNetCorePackTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CreateNuGetPackageTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CreateNuGetPackagesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PublishMyGetPackagesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PublishNuGetPackagesTask { get; set; }
-    public CakeTaskBuilder<ActionTask> InstallReportGeneratorTask { get; set; }
-    public CakeTaskBuilder<ActionTask> InstallReportUnitTask { get; set; }
-    public CakeTaskBuilder<ActionTask> InstallOpenCoverTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TestNUnitTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TestxUnitTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TestMSTestTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TestVSTestTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TestFixieTask { get; set; }
-    public CakeTaskBuilder<ActionTask> TransifexPullTranslations { get; set; }
-    public CakeTaskBuilder<ActionTask> TransifexPushSourceResource { get; set; }
-    public CakeTaskBuilder<ActionTask> TransifexPushTranslations { get; set; }
-    public CakeTaskBuilder<ActionTask> TransifexSetupTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DotNetCoreTestTask { get; set; }
-    public CakeTaskBuilder<ActionTask> IntegrationTestTask { get;set; }
-    public CakeTaskBuilder<ActionTask> TestTask { get; set; }
-    public CakeTaskBuilder<ActionTask> CleanDocumentationTask { get; set; }
-    public CakeTaskBuilder<ActionTask> DeployGraphDocumentation {get; set;}
-    public CakeTaskBuilder<ActionTask> PublishDocumentationTask { get; set; }
-    public CakeTaskBuilder<ActionTask> PreviewDocumentationTask { get; set; }
-    public CakeTaskBuilder<ActionTask> ForcePublishDocumentationTask { get; set; }
+    public CakeTaskBuilder DupFinderTask { get; set; }
+    public CakeTaskBuilder InspectCodeTask { get; set; }
+    public CakeTaskBuilder AnalyzeTask { get; set; }
+    public CakeTaskBuilder PrintAppVeyorEnvironmentVariablesTask { get; set; }
+    public CakeTaskBuilder UploadAppVeyorArtifactsTask { get; set; }
+    public CakeTaskBuilder ClearAppVeyorCacheTask { get; set; }
+    public CakeTaskBuilder ShowInfoTask { get; set; }
+    public CakeTaskBuilder CleanTask { get; set; }
+    public CakeTaskBuilder DotNetCoreCleanTask { get; set; }
+    public CakeTaskBuilder RestoreTask { get; set; }
+    public CakeTaskBuilder DotNetCoreRestoreTask { get; set; }
+    public CakeTaskBuilder BuildTask { get; set; }
+    public CakeTaskBuilder DotNetCoreBuildTask { get; set; }
+    public CakeTaskBuilder PackageTask { get; set; }
+    public CakeTaskBuilder DefaultTask { get; set; }
+    public CakeTaskBuilder AppVeyorTask { get; set; }
+    public CakeTaskBuilder ReleaseNotesTask { get; set; }
+    public CakeTaskBuilder ClearCacheTask { get; set; }
+    public CakeTaskBuilder PreviewTask { get; set; }
+    public CakeTaskBuilder PublishDocsTask { get; set; }
+    public CakeTaskBuilder CreateChocolateyPackagesTask { get; set; }
+    public CakeTaskBuilder PublishChocolateyPackagesTask { get; set; }
+    public CakeTaskBuilder UploadCodecovReportTask { get; set; }
+    public CakeTaskBuilder UploadCoverallsReportTask { get; set; }
+    public CakeTaskBuilder UploadCoverageReportTask { get; set; }
+    public CakeTaskBuilder CreateReleaseNotesTask { get; set; }
+    public CakeTaskBuilder ExportReleaseNotesTask { get; set; }
+    public CakeTaskBuilder PublishGitHubReleaseTask { get; set; }
+    public CakeTaskBuilder DotNetCorePackTask { get; set; }
+    public CakeTaskBuilder CreateNuGetPackageTask { get; set; }
+    public CakeTaskBuilder CreateNuGetPackagesTask { get; set; }
+    public CakeTaskBuilder PublishMyGetPackagesTask { get; set; }
+    public CakeTaskBuilder PublishNuGetPackagesTask { get; set; }
+    public CakeTaskBuilder InstallReportGeneratorTask { get; set; }
+    public CakeTaskBuilder InstallReportUnitTask { get; set; }
+    public CakeTaskBuilder InstallOpenCoverTask { get; set; }
+    public CakeTaskBuilder TestNUnitTask { get; set; }
+    public CakeTaskBuilder TestxUnitTask { get; set; }
+    public CakeTaskBuilder TestMSTestTask { get; set; }
+    public CakeTaskBuilder TestVSTestTask { get; set; }
+    public CakeTaskBuilder TestFixieTask { get; set; }
+    public CakeTaskBuilder TransifexPullTranslations { get; set; }
+    public CakeTaskBuilder TransifexPushSourceResource { get; set; }
+    public CakeTaskBuilder TransifexPushTranslations { get; set; }
+    public CakeTaskBuilder TransifexSetupTask { get; set; }
+    public CakeTaskBuilder DotNetCoreTestTask { get; set; }
+    public CakeTaskBuilder IntegrationTestTask { get;set; }
+    public CakeTaskBuilder TestTask { get; set; }
+    public CakeTaskBuilder CleanDocumentationTask { get; set; }
+    public CakeTaskBuilder DeployGraphDocumentation {get; set;}
+    public CakeTaskBuilder PublishDocumentationTask { get; set; }
+    public CakeTaskBuilder PreviewDocumentationTask { get; set; }
+    public CakeTaskBuilder ForcePublishDocumentationTask { get; set; }
 }

After that adjustment recipes execute fine, this should be well documented in the blog post though as it'll break things for sure.

Copy link
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@devlead devlead merged commit 105eb54 into cake-build:develop May 26, 2018
@devlead
Copy link
Member

devlead commented May 26, 2018

@patriksvensson your changes have been merged, thanks for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants