public FrostingDescriptionRunner(DescriptionScriptHost host,
                                  ICakeEngine engine, IFrostingContext context, ICakeLog log,
                                  IEnumerable <IFrostingTask> tasks,
                                  IFrostingSetup setup         = null, IFrostingTeardown teardown = null,
                                  IFrostingTaskSetup taskSetup = null, IFrostingTaskTeardown taskTeardown = null)
     : base(host, engine, context, log, tasks, setup, teardown, taskSetup, taskTeardown)
 {
 }
Esempio n. 2
0
 public RunCommand(
     IFrostingContext context,
     IExecutionStrategy strategy,
     ICakeReportPrinter printer)
 {
     _context  = context;
     _strategy = strategy;
     _printer  = printer;
 }
Esempio n. 3
0
        public void Initialize(ICakeEngine engine, IFrostingContext context, IEnumerable <IFrostingTask> tasks,
                               IFrostingLifetime lifetime, IFrostingTaskLifetime taskLifetime)
        {
            if (tasks != null)
            {
                foreach (var task in tasks)
                {
                    var taskName = TaskNameHelper.GetTaskName(task);
                    _log.Debug("Registering task {0} with engine...", taskName);

                    // Get the task's context type.
                    if (!task.HasCompatibleContext(context))
                    {
                        const string format = "Task cannot be used since the context isn't convertable to {0}.";
                        _log.Warning(format, task.GetContextType().FullName);
                    }
                    else
                    {
                        // Register task with the Cake engine.
                        var cakeTask = engine.RegisterTask(taskName);
                        cakeTask.Does(task.Run);
                        cakeTask.WithCriteria(task.ShouldRun);

                        // Add dependencies
                        var attributes = task.GetType().GetTypeInfo().GetCustomAttributes <DependencyAttribute>();
                        foreach (var dependency in attributes)
                        {
                            var dependencyName = TaskNameHelper.GetTaskName(dependency);
                            if (!typeof(IFrostingTask).IsAssignableFrom(dependency.Task))
                            {
                                throw new FrostingException($"The dependency {dependencyName} does not implement IFrostingTask.");
                            }
                            cakeTask.IsDependentOn(dependencyName);
                        }
                    }
                }
            }

            if (lifetime != null)
            {
                _log.Debug("Registering lifetime {0} with engine...", lifetime.GetType().FullName);
                engine.RegisterSetupAction(info => lifetime.Setup(context));
                engine.RegisterTeardownAction(info => lifetime.Teardown(context, info));
            }

            if (taskLifetime != null)
            {
                _log.Debug("Registering task lifetime {0} with engine...", taskLifetime.GetType().Name);
                engine.RegisterTaskSetupAction(info => taskLifetime.Setup(context, info));
                engine.RegisterTaskTeardownAction(info => taskLifetime.Teardown(context, info));
            }
        }
        public static bool IsRunOverridden(this IFrostingTask task, IFrostingContext context)
        {
            if (task.IsFrostingTask())
            {
                return(task.GetType().GetMethod(nameof(FrostingTask.Run), new[] { context.GetType() }).IsOverriden());
            }

            if (task.IsAsyncFrostingTask())
            {
                return(task.GetType().GetMethod(nameof(AsyncFrostingTask.RunAsync), new[] { context.GetType() }).IsOverriden());
            }

            throw new InvalidOperationException($"This method expects all {nameof(IFrostingTask)} to be instances of {nameof(FrostingTask)} or {nameof(AsyncFrostingTask)}.");
        }
Esempio n. 5
0
 protected FrostingEngine(
     THost host,
     ICakeEngine engine, IFrostingContext context, ICakeLog log,
     IEnumerable <IFrostingTask> tasks,
     IFrostingSetup setup               = null,
     IFrostingTeardown teardown         = null,
     IFrostingTaskSetup taskSetup       = null,
     IFrostingTaskTeardown taskTeardown = null)
 {
     _host         = host;
     _engine       = engine;
     _context      = context;
     _log          = log;
     _setup        = setup;
     _teardown     = teardown;
     _taskSetup    = taskSetup;
     _taskTeardown = taskTeardown;
     _tasks        = new List <IFrostingTask>(tasks ?? Array.Empty <IFrostingTask>());
 }
Esempio n. 6
0
        public CakeHost(CakeHostOptions options, CakeHostServices services, ILifetimeScope scope,
                        IFrostingContext context,
                        IEnumerable <IFrostingTask> tasks = null, IFrostingLifetime lifetime = null, IFrostingTaskLifetime taskLifetime = null)
        {
            Guard.ArgumentNotNull(scope, nameof(scope));
            Guard.ArgumentNotNull(services, nameof(services));
            Guard.ArgumentNotNull(context, nameof(context));
            Guard.ArgumentNotNull(options, nameof(options));

            _options      = options;
            _scope        = scope; // Keep the scope alive.
            _context      = context;
            _tasks        = tasks;
            _lifetime     = lifetime;
            _taskLifetime = taskLifetime;

            _environment       = services.Environment;
            _engine            = services.Engine;
            _log               = services.Log;
            _commandFactory    = services.CommandFactory;
            _engineInitializer = services.EngineInitializer;
        }
Esempio n. 7
0
        public CakeHost(IFrostingContext context, Container container, CakeHostOptions options,
                        IFileSystem fileSystem, ICakeEnvironment environment, ICakeEngine engine, ICakeLog log,
                        IToolInstaller installer, IEnumerable <PackageReference> tools,
                        EngineInitializer engineInitializer, CommandFactory commandFactory,
                        WorkingDirectory workingDirectory = null, IEnumerable <IFrostingTask> tasks  = null,
                        IFrostingLifetime lifetime        = null, IFrostingTaskLifetime taskLifetime = null)
        {
            Guard.ArgumentNotNull(context, nameof(context));
            Guard.ArgumentNotNull(container, nameof(container));
            Guard.ArgumentNotNull(options, nameof(options));
            Guard.ArgumentNotNull(fileSystem, nameof(fileSystem));
            Guard.ArgumentNotNull(environment, nameof(environment));
            Guard.ArgumentNotNull(engine, nameof(engine));
            Guard.ArgumentNotNull(log, nameof(log));
            Guard.ArgumentNotNull(engineInitializer, nameof(engineInitializer));
            Guard.ArgumentNotNull(commandFactory, nameof(commandFactory));

            // Mandatory arguments.
            _context           = context;
            _container         = container;
            _options           = options;
            _fileSystem        = fileSystem;
            _environment       = environment;
            _engine            = engine;
            _log               = log;
            _installer         = installer;
            _tools             = new List <PackageReference>(tools ?? Enumerable.Empty <PackageReference>());
            _engineInitializer = engineInitializer;
            _commandFactory    = commandFactory;

            // Optional arguments.
            _workingDirectory = workingDirectory;
            _tasks            = tasks;
            _lifetime         = lifetime;
            _taskLifetime     = taskLifetime;
        }
 public static bool IsFinallyOverridden(this IFrostingTask task, IFrostingContext context)
 {
     return(task.GetType().GetMethod(nameof(IFrostingTask.Finally), new[] { context.GetType() }).IsOverriden());
 }
 public static bool IsOnErrorOverridden(this IFrostingTask task, IFrostingContext context)
 {
     return(task.GetType().GetMethod(nameof(IFrostingTask.OnError), new[] { typeof(Exception), context.GetType() }).IsOverriden());
 }
 public static bool HasCompatibleContext(this IFrostingTask task, IFrostingContext context)
 {
     return(context.GetType().IsConvertableTo(task.GetContextType()));
 }
Esempio n. 11
0
        public void Initialize(ICakeEngine engine, IFrostingContext context, IEnumerable <IFrostingTask> tasks,
                               IFrostingLifetime lifetime, IFrostingTaskLifetime taskLifetime)
        {
            if (tasks != null)
            {
                foreach (var task in tasks)
                {
                    var taskName = TaskNameHelper.GetTaskName(task);
                    _log.Debug("Registering task: {0}", taskName);

                    // Get the task's context type.
                    if (!task.HasCompatibleContext(context))
                    {
                        const string format = "Task cannot be used since the context isn't convertible to {0}.";
                        _log.Warning(format, task.GetContextType().FullName);
                    }
                    else
                    {
                        // Register task with the Cake engine.
                        var cakeTask = engine.RegisterTask(taskName);

                        // Is the run method overridden?
                        if (task.IsRunOverridden(context))
                        {
                            cakeTask.Does(c => task.Run(c));
                        }

                        // Is the criteria method overridden?
                        if (task.IsShouldRunOverridden(context))
                        {
                            cakeTask.WithCriteria(task.ShouldRun);
                        }

                        // Continue on error?
                        if (task.IsContinueOnError())
                        {
                            cakeTask.ContinueOnError();
                        }

                        // Is the on error method overridden?
                        if (task.IsOnErrorOverridden(context))
                        {
                            cakeTask.OnError(exception => task.OnError(exception, context));
                        }

                        // Is the finally method overridden?
                        if (task.IsFinallyOverridden(context))
                        {
                            cakeTask.Finally(() => task.Finally(context));
                        }

                        // Add dependencies
                        var attributes = task.GetType().GetTypeInfo().GetCustomAttributes <DependencyAttribute>();
                        foreach (var dependency in attributes)
                        {
                            var dependencyName = TaskNameHelper.GetTaskName(dependency);
                            if (!typeof(IFrostingTask).IsAssignableFrom(dependency.Task))
                            {
                                throw new FrostingException($"The dependency '{dependencyName}' is not a valid task.");
                            }
                            cakeTask.IsDependentOn(dependencyName);
                        }
                    }
                }
            }

            if (lifetime != null)
            {
                _log.Debug("Registering lifetime: {0}", lifetime.GetType().Name);

                if (lifetime.IsSetupOverridden(context))
                {
                    engine.RegisterSetupAction(info => lifetime.Setup(context));
                }
                if (lifetime.IsTeardownOverridden(context))
                {
                    engine.RegisterTeardownAction(info => lifetime.Teardown(context, info));
                }
            }

            if (taskLifetime != null)
            {
                _log.Debug("Registering task lifetime: {0}", taskLifetime.GetType().Name);

                if (taskLifetime.IsSetupOverridden(context))
                {
                    engine.RegisterTaskSetupAction(info => taskLifetime.Setup(context, info));
                }

                if (taskLifetime.IsTeardownOverridden(context))
                {
                    engine.RegisterTaskTeardownAction(info => taskLifetime.Teardown(context, info));
                }
            }
        }
Esempio n. 12
0
 public DryRunCommand(IFrostingContext context, ICakeLog log)
 {
     _context           = context;
     _log               = log;
     _executionSettings = new ExecutionSettings();
 }
Esempio n. 13
0
 public static bool IsTeardownOverridden(this IFrostingLifetime lifetime, IFrostingContext context)
 {
     return(lifetime.GetType().GetMethod("Teardown", new[] { context.GetType(), typeof(ITeardownContext) }).IsOverriden());
 }
Esempio n. 14
0
 public static bool IsSetupOverridden(this IFrostingLifetime lifetime, IFrostingContext context)
 {
     return(lifetime.GetType().GetMethod("Setup", new[] { context.GetType() }).IsOverriden());
 }
Esempio n. 15
0
 public DryRunCommand(IFrostingContext context, ICakeLog log)
 {
     _context = context;
     _log     = log;
 }