Ejemplo n.º 1
0
        /// <summary>
        /// Builds the required services and an <see cref="ICakeHost" /> using the specified options.
        /// </summary>
        /// <returns>The built <see cref="ICakeHost" />.</returns>
        public ICakeHost Build()
        {
            try
            {
                // Create the "base" container with the minimum
                // stuff registered to run Cake at all.
                var registrar = new ContainerRegistrar();
                registrar.RegisterModule(new CoreModule());
                registrar.RegisterModule(new FrostingModule());
                var container = registrar.Build();

                // Add custom registrations to the container.
                AddCustomRegistrations(container);

                // Find and register tasks with the container.
                RegisterTasks(container);

                // Resolve the application and run it.
                return(container.Resolve <ICakeHost>());
            }
            catch (Exception exception)
            {
                return(new ErrorCakeHost(exception));
            }
        }
Ejemplo n.º 2
0
        private static void AddCakeCoreModules(ContainerBuilder containerBuilder)
        {
            var cakeRegistrar = new ContainerRegistrar(containerBuilder);

            cakeRegistrar.RegisterModule(new CoreModule());
            cakeRegistrar.RegisterModule(new CakeExtModule());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            ICakeLog log = null;

            try
            {
                // Parse arguments.
                var args = QuoteAwareStringSplitter
                           .Split(Environment.CommandLine)
                           .Skip(1) // Skip executable.
                           .ToArray();

                var builder = new ContainerRegistrar();
                builder.RegisterModule(new CakeModule());
                builder.RegisterModule(new CoreModule());
                builder.RegisterModule(new CommonModule());

                // Build the container.
                using (var container = builder.Build())
                {
                    // Resolve the log.
                    log = container.Resolve <ICakeLog>();

                    // Parse the options.
                    var parser  = container.Resolve <IArgumentParser>();
                    var options = parser.Parse(args);

                    // Set verbosity.
                    log.Verbosity = options.Verbosity;

                    // Rebuild the container.
                    builder = new ContainerRegistrar();
                    var provider = container.Resolve <CakeConfigurationProvider>();
                    builder.RegisterModule(new ConfigurationModule(provider, options));
                    builder.RegisterModule(new ArgumentsModule(options));
                    builder.RegisterModule(new ScriptingModule(options, log));
                    builder.Update(container);

                    // Register the NuGetModule
                    builder = new ContainerRegistrar();
                    var configuration = container.Resolve <ICakeConfiguration>();
                    builder.RegisterModule(new NuGetModule(configuration));
                    builder.Update(container);

                    // Load all modules.
                    var loader = container.Resolve <ModuleLoader>();
                    loader.LoadModules(container, options);

                    // Resolve and run the application.
                    var application = container.Resolve <CakeApplication>();
                    return(application.Run(options));
                }
            }
            catch (Exception ex)
            {
                return(LogException(log, ex));
            }
        }
Ejemplo n.º 4
0
        public static int Main()
        {
            // Parse arguments.
            var args = ArgumentParser.Parse(
                QuoteAwareStringSplitter
                .Split(EnvironmentHelper.GetCommandLine())
                .Skip(1));

            if (args.ContainsKey(Constants.CommandLine.Debug))
            {
                Console.WriteLine($"Attach debugger to process {Process.GetCurrentProcess().Id} to continue. ..");
                while (!Debugger.IsAttached)
                {
                    Thread.Sleep(100);
                }
            }

            // Validate the port argument.
            if (!args.ContainsKey(Constants.CommandLine.Port) ||
                !int.TryParse(args[Constants.CommandLine.Port], out int port))
            {
                throw new ArgumentException("Port not specified or invalid.");
            }

            var loggerFactory = new LoggerFactory();

            if (args.ContainsKey(Constants.CommandLine.Verbose))
            {
                loggerFactory.AddProvider(new LoggerProvider());
            }

            var registrar = new ContainerRegistrar();

            registrar.RegisterModule(new CoreModule());
            registrar.RegisterModule(new BakeryModule(loggerFactory));

            // Build the container.
            using (var container = registrar.Build())
            {
                var fileSystem            = container.Resolve <IFileSystem>();
                var log                   = container.Resolve <ICakeLog>();
                var configurationProvider = container.Resolve <CakeConfigurationProvider>();
                var workingDirectory      = new DirectoryPath(System.IO.Directory.GetCurrentDirectory());

                var configuration = configurationProvider.CreateConfiguration(workingDirectory, args);

                // Rebuild the container for NuGet and Buffered File System.
                registrar = new ContainerRegistrar();
                registrar.RegisterInstance(configuration);
                registrar.RegisterModule(new NuGetModule(configuration));
                registrar.RegisterModule(new ScriptingModule(fileSystem, log));
                registrar.Builder.Update(container);

                var environment            = container.Resolve <ICakeEnvironment>();
                var aliasFinder            = container.Resolve <IScriptAliasFinder>();
                var processor              = container.Resolve <Core.Scripting.IScriptProcessor>();
                var aliasGenerator         = container.Resolve <ICakeAliasGenerator>();
                var loadDirectiveProviders = container.Resolve <IEnumerable <ILoadDirectiveProvider> >();

                // Rebuild the container for Cached Alias Finder.
                registrar = new ContainerRegistrar();
                registrar.RegisterModule(new CacheModule(aliasFinder, processor, environment, aliasGenerator, loadDirectiveProviders));
                registrar.Builder.Update(container);

                // Get Script generator.
                var scriptGenerator = container.Resolve <IScriptGenerationService>();

                environment.WorkingDirectory = workingDirectory;

                try
                {
                    using (var server = new ScriptGenerationServer(scriptGenerator, port, loggerFactory))
                    {
                        server.Start();

                        var cancel = new ManualResetEvent(false);

                        server.OnDisconnected  += (sender, e) => { cancel.Set(); };
                        Console.CancelKeyPress += (sender, e) =>
                        {
                            cancel.Set();
                            e.Cancel = true;
                        };

                        cancel.WaitOne();
                        server.Stop();
                    }
                }
                catch (Exception e)
                {
                    loggerFactory.CreateLogger <Program>().LogCritical(0, e, "Unhandled Exception");
                    throw;
                }
            }

            return(0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The application entry point.
        /// </summary>
        /// <returns>The application exit code.</returns>
        public static int Main()
        {
            ICakeLog log = null;

            try
            {
                // Parse arguments.
                var args = ArgumentTokenizer
                           .Tokenize(EnvironmentHelper.GetCommandLine())
                           .Skip(1) // Skip executable.
                           .ToArray();

                var builder = new ContainerRegistrar();
                builder.RegisterModule(new CakeModule());
                builder.RegisterModule(new CoreModule());
                builder.RegisterModule(new CommonModule());
                builder.RegisterModule(new NuGetModule());

                // Build the container.
                using (var container = builder.Build())
                {
                    // Resolve the log.
                    log = container.Resolve <ICakeLog>();

                    // Parse the options.
                    var parser  = container.Resolve <IArgumentParser>();
                    var options = parser.Parse(args);

                    // Set verbosity.
                    log.Verbosity = options.Verbosity;

                    // Rebuild the container.
                    builder = new ContainerRegistrar();
                    var provider = container.Resolve <CakeConfigurationProvider>();
                    builder.RegisterModule(new ConfigurationModule(provider, options));
                    builder.RegisterModule(new ArgumentsModule(options));
                    builder.RegisterModule(new ScriptingModule(options));
                    builder.Update(container);

                    // Load all modules.
                    var loader = container.Resolve <ModuleLoader>();
                    loader.LoadModules(container, options);

                    // Resolve and run the application.
                    var application = container.Resolve <CakeApplication>();
                    return(application.Run(options));
                }
            }
            catch (Exception ex)
            {
                log = log ?? new CakeBuildLog(new CakeConsole());
                if (log.Verbosity == Verbosity.Diagnostic)
                {
                    log.Error("Error: {0}", ex);
                }
                else
                {
                    log.Error("Error: {0}", ex.Message);
                }
                return(1);
            }
        }