Esempio n. 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);
        }
Esempio n. 2
0
        public bool Execute(CakeOptions options)
        {
            _console.WriteLine();
            _console.WriteLine("Usage: Cake.exe [build-script] [-verbosity=value]");
            _console.WriteLine("                [-showdescription] [-dryrun] [..]");
            _console.WriteLine();
            _console.WriteLine("Example: Cake.exe");
            _console.WriteLine("Example: Cake.exe build.cake -verbosity=quiet");
            _console.WriteLine("Example: Cake.exe build.cake -showdescription");
            _console.WriteLine();
            _console.WriteLine("Options:");
            _console.WriteLine("    -verbosity=value    Specifies the amount of information to be displayed.");
            _console.WriteLine("                        ({0})",
                               string.Join(", ", Enum.GetNames(typeof(Verbosity))));
            _console.WriteLine("    -showdescription    Shows description about tasks.");
            _console.WriteLine("    -dryrun             Performs a dry run.");
            _console.WriteLine("    -version            Displays version information.");
            _console.WriteLine("    -help               Displays usage information.");

            if (!_environment.IsUnix())
            {
                _console.WriteLine("    -mono               Uses the Mono Compiler, rather than Roslyn script engine.");
            }

            _console.WriteLine("    -experimental       Uses the nightly builds of Roslyn script engine.");
            _console.WriteLine();

            return(true);
        }
Esempio n. 3
0
        private bool ParseOption(string arg, CakeOptions options)
        {
            string name, value;

            var separatorIndex = arg.IndexOfAny(new[] { '=' });

            if (separatorIndex < 0)
            {
                name  = arg.Substring(1);
                value = string.Empty;
            }
            else
            {
                name  = arg.Substring(1, separatorIndex - 1);
                value = arg.Substring(separatorIndex + 1);
            }

            if (value.Length > 2)
            {
                if (value[0] == '\"' && value[value.Length - 1] == '\"')
                {
                    value = value.Substring(1, value.Length - 2);
                }
            }

            return(ParseOption(name, value, options));
        }
Esempio n. 4
0
 public bool Execute(CakeOptions options)
 {
     if (options.HasError)
     {
         _console.WriteLine("For usage, use parameter --help");
     }
     else
     {
         _console.WriteLine();
         _console.WriteLine("Usage: Cake.exe [script] [--verbosity=value]");
         _console.WriteLine("                [--showdescription] [--dryrun] [..]");
         _console.WriteLine();
         _console.WriteLine("Example: Cake.exe");
         _console.WriteLine("Example: Cake.exe build.cake --verbosity=quiet");
         _console.WriteLine("Example: Cake.exe build.cake --showdescription");
         _console.WriteLine();
         _console.WriteLine("Options:");
         _console.WriteLine("    --verbosity=value    Specifies the amount of information to be displayed.");
         _console.WriteLine("                         ({0})",
                            string.Join(", ", Enum.GetNames(typeof(Verbosity))));
         _console.WriteLine("    --debug              Performs a debug.");
         _console.WriteLine("    --showdescription    Shows description about tasks.");
         _console.WriteLine("    --showtree           Shows the task dependency tree.");
         _console.WriteLine("    --dryrun             Performs a dry run.");
         _console.WriteLine("    --exclusive          Execute a single task without any dependencies.");
         _console.WriteLine("    --bootstrap          Download/install modules defined by #module directives");
         _console.WriteLine("    --version            Displays version information.");
         _console.WriteLine("    --help               Displays usage information.");
         _console.WriteLine();
     }
     return(true);
 }
Esempio n. 5
0
        public CakeApplicationFixture()
        {
            Options           = new CakeOptions();
            Options.Verbosity = Verbosity.Diagnostic;

            CommandFactory = Substitute.For <ICommandFactory>();
        }
Esempio n. 6
0
        public bool Execute(CakeOptions options)
        {
            _console.WriteLine();
            _console.WriteLine(@"             +##   #;;'");
            _console.WriteLine(@"             #;;#  .+;;;;+,");
            _console.WriteLine(@"             '+;;#;,+';;;;;'#.");
            _console.WriteLine(@"             ++'''';;;;;;;;;;# ;#;");
            _console.WriteLine(@"            ##';;;;++'+#;;;;;'.   `#:");
            _console.WriteLine(@"         ;#   '+'';;;;;;;;;'#`       #.");
            _console.WriteLine(@"      `#,        .'++;;;;;':..........#");
            _console.WriteLine(@"    '+      `.........';;;;':.........#");
            _console.WriteLine(@"   #..................+;;;;;':........#");
            _console.WriteLine(@"   #..................#';;;;;'+''''''.#");
            _console.WriteLine(@"   #.......,:;''''''''##';;;;;'+'''''#,");
            _console.WriteLine(@"   #''''''''''''''''''###';;;;;;+''''#");
            _console.WriteLine(@"   #''''''''''''''''''####';;;;;;#'''#");
            _console.WriteLine(@"   #''''''''''''''''''#####';;;;;;#''#");
            _console.WriteLine(@"   #''''''''''''''''''######';;;;;;#'#");
            _console.WriteLine(@"   #''''''''''''''''''#######';;;;;;##");
            _console.WriteLine(@"   #''''''''''''''''''########';;;;;;#");
            _console.WriteLine(@"   #''''''''''''++####+;#######';;;;;;#");
            _console.WriteLine(@"   #+####':,`             ,#####';;;;;;'");
            _console.WriteLine(@"                              +##'''''+.");
            _console.WriteLine(@"   ___      _          ___       _ _     _ ");
            _console.WriteLine(@"  / __\__ _| | _____  / __\_   _(_) | __| |");
            _console.WriteLine(@" / /  / _` | |/ / _ \/__\// | | | | |/ _` |");
            _console.WriteLine(@"/ /___ (_| |   <  __/ \/  \ |_| | | | (_| |");
            _console.WriteLine(@"\____/\__,_|_|\_\___\_____/\__,_|_|_|\__,_|");
            _console.WriteLine();
            _console.WriteLine(@"                             Version {0}", GetVersion());
            _console.WriteLine();

            return(true);
        }
Esempio n. 7
0
 public bool Execute(CakeOptions options)
 {
     if (options.HasError)
     {
         _console.WriteLine("For usage, use parameter --help");
     }
     else
     {
         _console.WriteLine();
         _console.WriteLine("Usage: Cake.exe [script] [--verbosity=value]");
         _console.WriteLine("                [--showdescription] [--dryrun] [..]");
         _console.WriteLine();
         _console.WriteLine("Example: Cake.exe");
         _console.WriteLine("Example: Cake.exe build.cake --verbosity=quiet");
         _console.WriteLine("Example: Cake.exe build.cake --showdescription");
         _console.WriteLine();
         _console.WriteLine("Options:");
         _console.WriteLine("    --verbosity=value    Specifies the amount of information to be displayed.");
         _console.WriteLine("                         ({0})",
                            string.Join(", ", Enum.GetNames(typeof(Verbosity))));
         _console.WriteLine("    --debug              Performs a debug.");
         _console.WriteLine("    --showdescription    Shows description about tasks.");
         _console.WriteLine("    --dryrun             Performs a dry run.");
         _console.WriteLine("    --version            Displays version information.");
         _console.WriteLine("    --help               Displays usage information.");
         _console.WriteLine();
     }
     return(true);
 }
Esempio n. 8
0
            public void Should_Set_Verbosity_To_Normal()
            {
                // Given, When
                var result = new CakeOptions();

                // Then
                Assert.Equal(Verbosity.Normal, result.Verbosity);
            }
Esempio n. 9
0
 public bool Execute(CakeOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     _scriptRunner.Run(_host, options.Script, options.Arguments);
     return(true);
 }
Esempio n. 10
0
        private DirectoryPath GetModulePath(CakeOptions options)
        {
            var root = _configuration.GetValue(Constants.Paths.Modules);

            if (string.IsNullOrWhiteSpace(root))
            {
                return(options.Script.GetDirectory().Combine("tools/modules"));
            }
            return(new DirectoryPath(root));
        }
Esempio n. 11
0
 public DebugCommandFixture()
 {
     ScriptRunner = Substitute.For <IScriptRunner>();
     Log          = Substitute.For <ICakeLog>();
     Debugger     = Substitute.For <IDebugger>();
     Options      = new CakeOptions
     {
         Script = "build.cake"
     };
 }
Esempio n. 12
0
        public CakeApplicationFixture()
        {
            Options           = new CakeOptions();
            Options.Verbosity = Verbosity.Diagnostic;

            Log            = Substitute.For <IVerbosityAwareLog>();
            CommandFactory = Substitute.For <ICommandFactory>();

            ArgumentParser = Substitute.For <IArgumentParser>();
            ArgumentParser.Parse(Arg.Any <IEnumerable <string> >()).Returns(Options);
        }
Esempio n. 13
0
 public RoslynScriptEngine(
     CakeOptions options,
     RoslynScriptSessionFactory stableFactory,
     RoslynNightlyScriptSessionFactory nightlyFactory,
     ICakeLog log)
 {
     _options        = options;
     _nightlyFactory = nightlyFactory;
     _stableFactory  = stableFactory;
     _log            = log;
 }
Esempio n. 14
0
        public RoslynScriptSession(IScriptHost host, IAssemblyLoader loader, ICakeLog log, CakeOptions options)
        {
            _host    = host;
            _loader  = loader;
            _log     = log;
            _options = options;

            ReferencePaths = new HashSet <FilePath>(PathComparer.Default);
            References     = new HashSet <Assembly>();
            Namespaces     = new HashSet <string>(StringComparer.Ordinal);
        }
Esempio n. 15
0
                public void Should_Add_Unknown_Arguments_To_Argument_List()
                {
                    // Given
                    var fixture = new ArgumentParserFixture();
                    var parser  = new ArgumentParser(fixture.Log, fixture.VerbosityParser);

                    // When
                    CakeOptions result = parser.Parse(new[] { "-unknown" });

                    // Then
                    Assert.True(result.Arguments.ContainsKey("unknown"));
                }
Esempio n. 16
0
            public void Can_Parse_Empty_Parameters()
            {
                // Given
                var fixture = new ArgumentParserFixture();
                var parser  = new ArgumentParser(fixture.Log, fixture.VerbosityParser);

                // When
                CakeOptions result = parser.Parse(new string[] { });

                // Then
                Assert.NotNull(result);
            }
Esempio n. 17
0
 public void Execute(CakeOptions options)
 {
     _console.WriteLine("Usage: Cake.exe <build-script> [-verbosity=value] [-showdescription] [..]");
     _console.WriteLine();
     _console.WriteLine("Example: Cake.exe build.cake");
     _console.WriteLine("Example: Cake.exe build.cake -verbosity=quiet");
     _console.WriteLine("Example: Cake.exe build.cake -showdescription");
     _console.WriteLine();
     _console.WriteLine("Options:");
     _console.WriteLine("    -verbosity=value    Specifies the amount of information to be displayed.");
     _console.WriteLine("    -showdescription    Shows description about tasks.");
     _console.WriteLine("    -help               Displays usage information.");
 }
        public bool Initialize(CakeOptions options)
        {
            var serverExecutablePath = ScriptGenerationToolResolver.GetExecutablePath(_environment.TargetDirectory, _cakeConfiguration, options);

            if (File.Exists(serverExecutablePath))
            {
                _generationService = PlatformHelper.IsMono ?
                                     new ScriptGenerationClient(new MonoScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory) :
                                     new ScriptGenerationClient(serverExecutablePath, _environment.TargetDirectory, _loggerFactory);
            }

            return(_generationService != null);
        }
Esempio n. 19
0
            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);
            }
Esempio n. 20
0
            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);
            }
Esempio n. 21
0
            public void Should_Return_Default_Options_If_Multiple_Build_Configurations_Are_Provided()
            {
                // Given
                var fixture = new ArgumentParserFixture {
                    Log = new FakeLog()
                };
                var parser    = new ArgumentParser(fixture.Log, fixture.VerbosityParser);
                var arguments = new[] { "build1.config", "build2.config" };

                // When
                CakeOptions options = parser.Parse(arguments);

                // Then
                AssertDefaultOptions(options);
            }
Esempio n. 22
0
            public void Can_Parse_Script_With_Unix_Path(string input)
            {
                // Given
                var fixture   = new ArgumentParserFixture();
                var parser    = new ArgumentParser(fixture.Log, fixture.VerbosityParser);
                var arguments = new[] { input };

                // When
                CakeOptions result = parser.Parse(arguments);

                // Then
                Assert.NotNull(result);
                Assert.NotNull(result.Script);
                Assert.Equal("/home/test/build.cake", result.Script.FullPath);
            }
Esempio n. 23
0
        public bool Execute(CakeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.Exclusive)
            {
                _host.Settings.UseExclusiveTarget();
            }

            _scriptRunner.Run(_host, options.Script, options.Arguments);
            return(true);
        }
Esempio n. 24
0
            public void Should_Throw_If_Registrar_Are_Null()
            {
                // Given
                var fileSystem  = Substitute.For <IFileSystem>();
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var provider    = new CakeConfigurationProvider(fileSystem, environment);
                var options     = new CakeOptions();
                var module      = new ConfigurationModule(provider, options);

                // When
                var result = Record.Exception(() => module.Register(null));

                // Then
                AssertEx.IsArgumentNullException(result, "registrar");
            }
Esempio n. 25
0
        public bool Execute(CakeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _log.Debug("Performing debug...");
            _log.Information(Verbosity.Quiet, "Attach debugger to process {0} to continue", _debugger.GetProcessId());

            _debugger.WaitForAttach(Timeout.InfiniteTimeSpan);
            _log.Debug("Debugger attached");

            _scriptRunner.Run(_host, options.Script, options.Arguments);

            return(true);
        }
Esempio n. 26
0
            public void Should_Use_The_Script_Directory_As_Root_For_Configuration_File()
            {
                // Given
                var fileSystem  = Substitute.For <IFileSystem>();
                var environment = FakeEnvironment.CreateUnixEnvironment();
                var provider    = new CakeConfigurationProvider(fileSystem, environment);
                var registry    = new ContainerRegistrar();
                var options     = new CakeOptions {
                    Script = "./foo/bar/build.cake"
                };
                var module = new ConfigurationModule(provider, options);

                // When
                module.Register(registry);

                // Then
                fileSystem.Received(1).Exist(Arg.Is <FilePath>(f => f.FullPath == "/Working/foo/bar/cake.config"));
            }
Esempio n. 27
0
        public bool Initialize(CakeOptions options)
        {
            var serverExecutablePath = ScriptGenerationToolResolver.GetExecutablePath(_environment.TargetDirectory, _cakeConfiguration, options);

            if (File.Exists(serverExecutablePath))
            {
                _logger.LogInformation($"Using Cake.Bakery at {serverExecutablePath}");

                _generationService = PlatformHelper.IsMono ?
                                     new ScriptGenerationClient(new MonoScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory) :
                                     new ScriptGenerationClient(serverExecutablePath, _environment.TargetDirectory, _loggerFactory);
            }
            else if (!string.IsNullOrEmpty(serverExecutablePath))
            {
                _logger.LogWarning($"Cake.Bakery not found at path {serverExecutablePath}");
            }

            return(_generationService != null);
        }
Esempio n. 28
0
        private bool ParseOption(string name, string value, CakeOptions options)
        {
            if (name.Equals("verbosity", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("v", StringComparison.OrdinalIgnoreCase))
            {
                // Parse verbosity.
                options.Verbosity = _verbosityParser.Parse(value);
            }

            if (name.Equals("showdescription", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("s", StringComparison.OrdinalIgnoreCase))
            {
                options.ShowDescription = true;
            }

            if (name.Equals("dryrun", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("noop", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("whatif", StringComparison.OrdinalIgnoreCase))
            {
                options.PerformDryRun = true;
            }

            if (name.Equals("help", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("?", StringComparison.OrdinalIgnoreCase))
            {
                options.ShowHelp = true;
            }

            if (name.Equals("version", StringComparison.OrdinalIgnoreCase) ||
                name.Equals("ver", StringComparison.OrdinalIgnoreCase))
            {
                options.ShowVersion = true;
            }

            if (options.Arguments.ContainsKey(name))
            {
                _log.Error("Multiple arguments with the same name ({0}).", name);
                return(false);
            }

            options.Arguments.Add(name, value);
            return(true);
        }
Esempio n. 29
0
        public bool Execute(CakeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.Exclusive)
            {
                _host.Settings.UseExclusiveTarget();
            }

            if (!string.IsNullOrWhiteSpace(options.ContinueFromTaskName))
            {
                _host.Settings.SetContinueFromTask(options.ContinueFromTaskName);
            }

            _scriptRunner.Run(_host, options.Script, options.Arguments);
            return(true);
        }
Esempio n. 30
0
        public void LoadModules(IContainer container, CakeOptions options)
        {
            var root        = _configuration.GetModulePath(options.Script.GetDirectory(), _environment);
            var moduleTypes = _searcher.Search(root);

            if (moduleTypes.Count > 0)
            {
                using (var temporaryContainer = container.BeginLifetimeScope())
                {
                    // Register modules in the temporary container.
                    RegisterExternalModules(moduleTypes, temporaryContainer);

                    // Now let the modules register their types.
                    var builder = new ContainerRegistrar();
                    foreach (var module in temporaryContainer.Resolve <IEnumerable <ICakeModule> >())
                    {
                        builder.RegisterModule(module);
                    }
                    builder.Update(container);
                }
            }
        }