Beispiel #1
0
 public int Run(IRemainingArguments arguments, BuildFeatureSettings settings)
 {
     using (new ScriptAssemblyResolver(_environment, _log))
     {
         return(RunCore(arguments, settings));
     }
 }
        public void Configure(
            ICakeContainerRegistrar registrar,
            ICakeConfiguration configuration,
            IRemainingArguments arguments)
        {
            // Arguments
            registrar.RegisterInstance(new CakeArguments(arguments.Parsed)).AsSelf().As <ICakeArguments>();

            // Scripting
            registrar.RegisterType <RoslynScriptEngine>().As <IScriptEngine>().Singleton();
            registrar.RegisterType <BuildScriptHost>().Singleton();
            registrar.RegisterType <DryRunScriptHost>().Singleton();
            registrar.RegisterType <TreeScriptHost>().Singleton();
            registrar.RegisterType <DescriptionScriptHost>().Singleton();

            // Diagnostics
            registrar.RegisterType <CakeBuildLog>().As <ICakeLog>().Singleton();
            registrar.RegisterType <CakeDebugger>().As <ICakeDebugger>().Singleton();

            // External modules
            new CoreModule().Register(registrar);
            new CommonModule().Register(registrar);
            new NuGetModule(configuration).Register(registrar);

            // Misc registrations.
            registrar.RegisterType <CakeReportPrinter>().As <ICakeReportPrinter>().Singleton();
            registrar.RegisterType <CakeConsole>().As <IConsole>().Singleton();
            registrar.RegisterInstance(configuration).As <ICakeConfiguration>().Singleton();
        }
Beispiel #3
0
        private static CakeArguments CreateCakeArguments(IRemainingArguments remainingArguments, DefaultCommandSettings settings)
        {
            var arguments = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase);

            // Keep the actual remaining arguments in the cake arguments
            foreach (var group in remainingArguments.Parsed)
            {
                arguments[group.Key] = new List <string>();
                foreach (var argument in group)
                {
                    arguments[group.Key].Add(argument);
                }
            }

            // Fixes #3291, We have to add arguments manually which are defined within the DefaultCommandSettings type. Those are not considered "as remaining" because they could be parsed
            const string targetArgumentName = "target";

            if (!arguments.ContainsKey(targetArgumentName))
            {
                arguments[targetArgumentName] = new List <string>();
            }
            arguments[targetArgumentName].Add(settings.Target);

            var argumentLookUp = arguments.SelectMany(a => a.Value, Tuple.Create).ToLookup(a => a.Item1.Key, a => a.Item2);

            return(new CakeArguments(argumentLookUp));
        }
Beispiel #4
0
        protected ICakeConfiguration ReadConfiguration(
            IRemainingArguments remaining, DirectoryPath root)
        {
            var provider = new CakeConfigurationProvider(_fileSystem, _environment);
            var args     = remaining.Parsed.ToDictionary(x => x.Key, x => x.FirstOrDefault() ?? string.Empty);

            return(provider.CreateConfiguration(root, args));
        }
Beispiel #5
0
        protected IContainer CreateScope(
            ICakeConfiguration configuration,
            IRemainingArguments arguments,
            Action <ICakeContainerRegistrar> action = null)
        {
            var registrar = new AutofacTypeRegistrar(new ContainerBuilder());

            _configurator.Configure(registrar, configuration, arguments);
            action?.Invoke(registrar);

            return(registrar.BuildContainer());
        }
        public void Configure(
            ICakeContainerRegistrar registrar,
            ICakeConfiguration configuration,
            IRemainingArguments arguments)
        {
            _decorated.Configure(registrar, configuration, arguments);

            foreach (var action in _actions)
            {
                action(registrar);
            }
        }
Beispiel #7
0
        public int Run(IRemainingArguments arguments, BootstrapFeatureSettings settings)
        {
            // Fix the script path.
            settings.Script = settings.Script ?? new FilePath("build.cake");
            settings.Script = settings.Script.MakeAbsolute(_environment);

            // Read the configuration.
            var configuration = ReadConfiguration(arguments, settings.Script.GetDirectory());

            // Create the scope where we will perform the bootstrapping.
            using (var scope = CreateScope(configuration, arguments))
            {
                var analyzer  = scope.Resolve <IScriptAnalyzer>();
                var processor = scope.Resolve <IScriptProcessor>();

                // Set log verbosity for log in new scope.
                var log = scope.Resolve <ICakeLog>();
                log.Verbosity = settings.Verbosity;

                // Get the root directory.
                var root = settings.Script.GetDirectory();

                // Analyze the script.
                log.Debug("Looking for modules...");
                ScriptAnalyzerResult result = PerformAnalysis(analyzer, root, settings);
                if (result.Modules.Count == 0)
                {
                    log.Debug("No modules found to install.");
                    return(0);
                }

                // Install modules.
                processor.InstallModules(
                    result.Modules,
                    configuration.GetModulePath(root, _environment));
            }

            return(0);
        }
Beispiel #8
0
        public int Run(IRemainingArguments arguments, BootstrapFeatureSettings settings)
        {
            // Fix the script path.
            settings.Script = settings.Script ?? new FilePath("build.cake");
            settings.Script = settings.Script.MakeAbsolute(_environment);

            // Read the configuration.
            var configuration = ReadConfiguration(arguments, settings.Script.GetDirectory());

            // Create the scope where we will perform the bootstrapping.
            using (var scope = CreateScope(configuration, arguments))
            {
                var analyzer  = scope.Resolve <IScriptAnalyzer>();
                var processor = scope.Resolve <IScriptProcessor>();

                // Set log verbosity for log in new scope.
                var log = scope.Resolve <ICakeLog>();
                log.Verbosity = settings.Verbosity;

                // Get the root directory.
                var root = settings.Script.GetDirectory();

                // Analyze the script.
                var result = analyzer.Analyze(settings.Script);
                if (!result.Succeeded)
                {
                    var messages = string.Join("\n", result.Errors.Select(s => $"{root.GetRelativePath(s.File).FullPath}, line #{s.Line}: {s.Message}"));
                    throw new AggregateException($"Bootstrapping failed for '{settings.Script}'.\n{messages}");
                }

                // Install modules.
                processor.InstallModules(
                    result.Modules,
                    configuration.GetModulePath(root, _environment));
            }

            return(0);
        }
Beispiel #9
0
    public async Task <int> Run(string name, IRemainingArguments remaining)
    {
        var example = _finder.FindExample(name);

        if (example == null)
        {
            return(-1);
        }

        if (!await Build(example).ConfigureAwait(false))
        {
            return(-1);
        }

        var arguments = "run";

        if (remaining.Raw.Count > 0)
        {
            arguments += $"--no-build --no-restore -- {string.Join(" ", remaining.Raw)}";
        }

        // Run the example using "dotnet run"
        var info = new ProcessStartInfo("dotnet")
        {
            Arguments        = arguments,
            WorkingDirectory = example.GetWorkingDirectory().FullPath,
        };

        var process = Process.Start(info);

        if (process == null)
        {
            throw new InvalidOperationException("An error occured when starting the 'dotnet' process");
        }

        process.WaitForExit();
        return(process.ExitCode);
    }
Beispiel #10
0
    public async Task <int> RunAll(IRemainingArguments remaining)
    {
        var examples = _finder.FindExamples();

        foreach (var(_, first, _, example) in examples.Enumerate())
        {
            if (!first)
            {
                _console.WriteLine();
            }

            _console.Write(new Rule($"Example: [silver]{example.Name}[/]").LeftAligned().RuleStyle("grey"));

            var exitCode = await Run(example.Name, remaining).ConfigureAwait(false);

            if (exitCode != 0)
            {
                _console.MarkupLine($"[red]Error:[/] Example [u]{example.Name}[/] did not return a successful exit code.");
                return(exitCode);
            }
        }

        return(0);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandContext"/> class.
 /// </summary>
 /// <param name="remaining">The remaining arguments.</param>
 /// <param name="name">The command name.</param>
 /// <param name="data">The command data.</param>
 public CommandContext(IRemainingArguments remaining, string name, object?data)
 {
     Remaining = remaining ?? throw new System.ArgumentNullException(nameof(remaining));
     Name      = name ?? throw new System.ArgumentNullException(nameof(name));
     Data      = data;
 }
Beispiel #12
0
        private int RunCore(IRemainingArguments arguments, BuildFeatureSettings settings)
        {
            // Fix the script path.
            settings.Script = settings.Script ?? new FilePath("build.cake");
            settings.Script = settings.Script.MakeAbsolute(_environment);

            // Read the configuration.
            var configuration = ReadConfiguration(arguments, settings.Script.GetDirectory());

            // Define the callback for modifying the scope.
            void ModifyScope(ICakeContainerRegistrar registrar)
            {
                LoadModules(registrar);
                registrar.RegisterInstance(settings).As <IScriptHostSettings>();
            }

            // Define a local method for loading modules into a registrar.
            void LoadModules(ICakeContainerRegistrar registrar)
            {
                var root        = settings.Script.GetDirectory();
                var moduleTypes = _searcher.FindModuleTypes(root, configuration).ToArray();

                if (moduleTypes.Length > 0)
                {
                    using (var scope = CreateScope(configuration, arguments))
                    {
                        var loader  = new ModuleLoader(scope);
                        var modules = loader.LoadModules(moduleTypes);

                        foreach (var module in modules)
                        {
                            module.Register(registrar);
                        }
                    }
                }
            }

            // Create the scope where we're going to execute the script.
            using (var scope = CreateScope(configuration, arguments, ModifyScope))
            {
                var runner = scope.Resolve <IScriptRunner>();

                // Set log verbosity for log in new scope.
                var log = scope.Resolve <ICakeLog>();
                log.Verbosity = settings.Verbosity;

                // Create the script host.
                var host = CreateScriptHost(settings, scope);
                if (settings.Exclusive)
                {
                    host.Settings.UseExclusiveTarget();
                }

                // Debug?
                if (settings.Debug)
                {
                    var debugger = scope.Resolve <ICakeDebugger>();
                    debugger.WaitForAttach(Timeout.InfiniteTimeSpan);
                }

                runner.Run(host, settings.Script);
            }

            return(0);
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandContext"/> class.
 /// </summary>
 /// <param name="remaining">The remaining arguments.</param>
 /// <param name="name">The command name.</param>
 /// <param name="data">The command data.</param>
 internal CommandContext(IRemainingArguments remaining, string name, object?data)
 {
     Remaining = remaining;
     Name      = name;
     Data      = data;
 }
Beispiel #14
0
        public FrostingConfiguration(IEnumerable <FrostingConfigurationValue> values, IFileSystem fileSystem, ICakeEnvironment environment, IRemainingArguments remainingArguments)
        {
            if (values is null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (fileSystem is null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (environment is null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            var baseConfiguration = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var value in values)
            {
                baseConfiguration[value.Key] = value.Value;
            }

            var provider = new CakeConfigurationProvider(fileSystem, environment);
            var args     = remainingArguments.Parsed.ToDictionary(x => x.Key, x => x.FirstOrDefault() ?? string.Empty);

            _cakeConfiguration = provider.CreateConfiguration(environment.WorkingDirectory, baseConfiguration, args);
        }
Beispiel #15
0
 public CommandTreeParserResult(CommandTree tree, IRemainingArguments remaining)
 {
     Tree      = tree;
     Remaining = remaining;
 }
        int IBuildFeature.Run(IRemainingArguments arguments, BuildFeatureSettings settings)
        {
            var feature = new BuildFeature(FileSystem, Environment, Bootstrapper, ModuleSearcher, Log);

            return(feature.Run(arguments, settings));
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandContext"/> class.
 /// </summary>
 /// <param name="remaining">The remaining arguments.</param>
 internal CommandContext(IRemainingArguments remaining)
 {
     Remaining = remaining;
 }