Example #1
0
        public ScriptRunnerFixture(string fileName = "./build.cake")
        {
            Source = "Hello World";

            Options           = new CakeOptions();
            Options.Verbosity = Verbosity.Diagnostic;
            Options.Script    = fileName;

            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            FileSystem = new FakeFileSystem(true);
            FileSystem.GetCreatedFile(Options.Script.MakeAbsolute(Environment), Source);

            Session        = Substitute.For <IScriptSession>();
            SessionFactory = Substitute.For <IScriptSessionFactory>();
            SessionFactory.CreateSession(Arg.Any <IScriptHost>()).Returns(Session);

            Arguments      = new CakeArguments();
            AliasGenerator = Substitute.For <IScriptAliasGenerator>();
            Host           = Substitute.For <IScriptHost>();
            Log            = Substitute.For <ICakeLog>();

            ScriptProcessor = new ScriptProcessor(FileSystem, Environment, Log);
        }
Example #2
0
        static CakeAPI()
        {
            var env        = new CakeEnvironment(new CakePlatform(), new CakeRuntime());
            var fileSystem = new FileSystem();

            var verbosity = Verbosity.Normal;

            if (Startup.HasArgument("cake-verbosity"))
            {
                verbosity = Enum.Parse <Verbosity>(Startup.Argument("cake-verbosity"));
            }
            var cakeLog = new CakeBuildLog(new CakeConsole(env), verbosity);

            var cakeConfiguration = new CakeConfiguration(new Dictionary <string, string>());
            var toolRepos         = new ToolRepository(env);

            Globber = new Globber(fileSystem, env);
            var cakeDataService = new CakeDataService();
            var registry        = new WindowsRegistry();
            var toolLocator     = new ToolLocator(env, toolRepos, new ToolResolutionStrategy(fileSystem, env, Globber, cakeConfiguration, cakeLog));
            var cakeArgs        = new CakeArguments(new List <string>().ToLookup(x => x));
            var procRunner      = new ProcessRunner(fileSystem, env, cakeLog, toolLocator, cakeConfiguration);

            Context = new CakeContext(fileSystem, env, Globber, cakeLog, cakeArgs, procRunner, registry, toolLocator, cakeDataService, cakeConfiguration);
        }
Example #3
0
        public override int Execute(CommandContext context, DefaultCommandSettings settings)
        {
            // Register arguments
            var arguments = new CakeArguments(context.Remaining.Parsed);

            _services.AddSingleton <ICakeArguments>(arguments);
            _services.AddSingleton(context.Remaining);

            var provider = _services.BuildServiceProvider();

            try
            {
                if (settings.Version)
                {
                    // Show version
                    var console = provider.GetRequiredService <IConsole>();
                    provider.GetRequiredService <VersionFeature>().Run(console);
                    return(0);
                }
                else if (settings.Info)
                {
                    // Show information
                    var console = provider.GetRequiredService <IConsole>();
                    provider.GetRequiredService <InfoFeature>().Run(console);
                    return(0);
                }

                // Set the log verbosity
                var log = provider.GetRequiredService <ICakeLog>();
                log.Verbosity = settings.Verbosity;

                // Run
                var runner = GetFrostingEngine(provider, settings);

                // Install tools
                InstallTools(provider);

                // Set the working directory
                SetWorkingDirectory(provider, settings);

                if (settings.Exclusive)
                {
                    runner.Settings.UseExclusiveTarget();
                }

                runner.Run(settings.Target);
            }
            catch (Exception ex)
            {
                LogException(provider.GetService <ICakeLog>(), ex);
                return(-1);
            }

            return(0);
        }
Example #4
0
            public void Should_Set_Arguments()
            {
                // Given
                var arguments = new CakeArguments();

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // Then
                Assert.Equal(1, arguments.Arguments.Count);
            }
            public void Should_Be_Case_Insensitive(string key, string expected)
            {
                // Given
                var options = new CakeOptions();

                options.Arguments.Add("A", "B");
                var arguments = new CakeArguments(options);

                // When
                var result = arguments.GetArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
            public void Should_Return_Whether_Or_Not_An_Argument_Exist(string key, bool expected)
            {
                // Given
                var options = new CakeOptions();

                options.Arguments.Add("A", "B");
                var arguments = new CakeArguments(options);

                // When
                var result = arguments.HasArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
Example #7
0
            public void Should_Return_Argument_Exist(string key, string expected)
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                var result = arguments.GetArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
Example #8
0
            public void Should_Be_Case_Insensitive(string key, bool expected)
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                var result = arguments.HasArgument(key);

                // Then
                Assert.Equal(expected, result);
            }
Example #9
0
        public void Should_Return_The_Last_Argument_If_Multiple_Ones_With_The_Same_Name_Exist()
        {
            // Given
            var arguments = new CakeArguments(new List <Tuple <string, string> >
            {
                Tuple.Create("FOO", "BAR"),
                Tuple.Create("FOO", "BAZ"),
            }.ToLookup(x => x.Item1, x => x.Item2));

            // When
            var result = arguments.GetArgument("FOO");

            // Then
            Assert.Equal("BAZ", result);
        }
Example #10
0
        public void Should_Return_Null_If_Argument_Is_Missing()
        {
            // Given
            var arguments = new CakeArguments(new List <Tuple <string, string> >
            {
                Tuple.Create("FOO", "BAR"),
                Tuple.Create("BAZ", "CORGI"),
            }.ToLookup(x => x.Item1, x => x.Item2));

            // When
            var result = arguments.GetArgument("WALDO");

            // Then
            Assert.Null(result);
        }
Example #11
0
            public void Should_Replace_Arguments_If_New_Ones_Are_Set()
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "C", "D" }, { "D", "E" }
                });

                // Then
                Assert.Equal(2, arguments.Arguments.Count);
            }
Example #12
0
            public void Should_Only_Set_Arguments_If_Argument_Collection_Is_Empty()
            {
                // Given
                var arguments = new CakeArguments();

                arguments.SetArguments(new Dictionary <string, string> {
                    { "A", "B" }
                });

                // When
                arguments.SetArguments(new Dictionary <string, string> {
                    { "C", "D" }, { "D", "E" }
                });

                // Then
                Assert.Equal(1, arguments.Arguments.Count);
            }
    public static IScriptHost GetScriptHost()
    {
        IFileSystem      fileSystem  = new FileSystem();
        ICakeDataService data        = new CakeDataService();
        ICakeEnvironment environment = new CakeEnvironment(
            new CakePlatform(),
            new CakeRuntime()
            );
        var                console       = new CakeConsole(environment);
        ICakeLog           log           = new CakeBuildLog(console);
        IGlobber           globber       = new Globber(fileSystem, environment);
        ICakeArguments     arguments     = new CakeArguments(BridgeArgumentParser.GetParsedCommandLine());
        ICakeConfiguration configuration = new CakeConfiguration(new Dictionary <string, string>());
        IToolLocator       tools         = new ToolLocator(
            environment,
            new ToolRepository(environment),
            new ToolResolutionStrategy(
                fileSystem,
                environment,
                globber,
                configuration,
                log
                )
            );
        ICakeContext context = new CakeContext(
            fileSystem,
            environment,
            globber,
            log,
            arguments,
            new ProcessRunner(fileSystem, environment, log, tools, configuration),
            new WindowsRegistry(),
            tools,
            data,
            configuration
            );

        return(new BridgeScriptHost(
                   new CakeEngine(data, log),
                   context,
                   new DefaultExecutionStrategy(log),
                   new CakeReportPrinter(console, context),
                   arguments
                   ));
    }
Example #14
0
 public ScriptRunner(IFileSystem fileSystem, ICakeEnvironment environment, CakeArguments arguments,
                     IScriptSessionFactory sessionFactory, IScriptAliasGenerator aliasGenerator,
                     IScriptProcessor processor, IScriptHost host)
 {
     if (fileSystem == null)
     {
         throw new ArgumentNullException("fileSystem");
     }
     if (environment == null)
     {
         throw new ArgumentNullException("environment");
     }
     if (arguments == null)
     {
         throw new ArgumentNullException("arguments");
     }
     if (sessionFactory == null)
     {
         throw new ArgumentNullException("sessionFactory");
     }
     if (aliasGenerator == null)
     {
         throw new ArgumentNullException("aliasGenerator");
     }
     if (host == null)
     {
         throw new ArgumentNullException("host");
     }
     _fileSystem     = fileSystem;
     _environment    = environment;
     _arguments      = arguments;
     _sessionFactory = sessionFactory;
     _aliasGenerator = aliasGenerator;
     _processor      = processor;
     _host           = host;
 }