Esempio n. 1
0
        public async Task <int> ExecuteAsync()
        {
            var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version;

            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            _log.LogInformation($"Flubu v.{version}");

            if (_args.Help)
            {
                return(1);
            }

            if (_args.MainCommands.Count == 1 && _args.MainCommands.First().Equals("setup", StringComparison.OrdinalIgnoreCase))
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                int result = 0;
                do
                {
                    IBuildScript script = null;

                    try
                    {
                        if (!_flubuSession.InteractiveMode)
                        {
                            script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_args);
                        }
                        else
                        {
                            script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_flubuSession
                                                                                               .InteractiveArgs);
                        }
                    }
                    catch (BuildScriptLocatorException)
                    {
                        if (!_args.InteractiveMode && !_flubuSession.InteractiveMode)
                        {
                            throw;
                        }

                        await SimpleFlubuInteractiveMode(script);
                    }

                    _flubuSession.TargetTree.BuildScript = script;
                    _flubuSession.FlubuHelpText          = FlubuHelpText;
                    _flubuSession.Properties.Set(BuildProps.IsWebApi, _args.IsWebApi);
                    _flubuSession.ScriptArgs = _args.ScriptArguments;
                    _flubuSession.TargetTree.ResetTargetTree();
                    //// ReSharper disable once PossibleNullReferenceException
                    if (script != null)
                    {
                        result = script.Run(_flubuSession);
                    }
                }while (_flubuSession.InteractiveMode && ReloadCommands.Contains(_flubuSession.InteractiveArgs.MainCommands[0], StringComparer.OrdinalIgnoreCase));

                return(result);
            }
            catch (TaskExecutionException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{e.ToString()}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (FlubuException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (Exception e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(3);
            }
        }
Esempio n. 2
0
        public async Task <int> ExecuteAsync()
        {
            var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version;

            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            _log.LogInformation($"Flubu v.{version}");

            if (_args.Help)
            {
                return(1);
            }

            if (_args.MainCommands.Count == 1 && _args.MainCommands.First().Equals("setup", StringComparison.OrdinalIgnoreCase))
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                var script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_args);

                _taskSession.FlubuHelpText = FlubuHelpText;
                _taskSession.ScriptArgs    = _args.ScriptArguments;
                var result = script.Run(_taskSession);
                return(result);
            }
            catch (TaskExecutionException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{e.ToString()}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (FlubuException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (Exception e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(3);
            }
        }
Esempio n. 3
0
        public virtual async Task <int> ExecuteAsync()
        {
            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            if (_args.Help)
            {
                return(1);
            }

            if (_args.MainCommands.Count == 1 && _args.MainCommands.First().Equals("setup", StringComparison.OrdinalIgnoreCase))
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                int result = 0;
                do
                {
                    IBuildScript script = null;

                    try
                    {
                        if (!_flubuSession.InteractiveMode)
                        {
                            script = await _scriptProvider.GetBuildScriptAsync(_args);
                        }
                        else
                        {
                            script = await _scriptProvider.GetBuildScriptAsync(_flubuSession
                                                                               .InteractiveArgs, true);
                        }
                    }
                    catch (BuildScriptLocatorException)
                    {
                        if (!_args.InteractiveMode && !_flubuSession.InteractiveMode)
                        {
                            throw;
                        }

                        _flubuSession.LogInfo("Build script not found.");

                        script = await SimpleFlubuInteractiveMode(script);
                    }

                    _flubuSession.ScriptArgs             = _args.ScriptArguments;
                    _flubuSession.InteractiveMode        = _args.InteractiveMode;
                    _flubuSession.InteractiveArgs        = _args;
                    _flubuSession.TargetTree.BuildScript = script;
                    _flubuSession.FlubuHelpText          = FlubuHelpText;
                    _flubuSession.Properties.Set(BuildProps.IsWebApi, _args.IsWebApi);
                    _flubuSession.TargetTree.ResetTargetTree();

                    if (script != null)
                    {
                        if (_flubuSession.InteractiveMode)
                        {
                            FlubuInteractiveMode(_flubuSession, script);
                        }
                        else
                        {
                            result = script.Run(_flubuSession);
                        }
                    }
                }while (_flubuSession.InteractiveMode && InternalCommands.ReloadCommands.Contains(_flubuSession.InteractiveArgs.MainCommands[0], StringComparer.OrdinalIgnoreCase));

                return(result);
            }
            catch (TaskExecutionException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{e}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (FlubuException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (Exception e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(3);
            }
        }
Esempio n. 4
0
        public virtual async Task <int> ExecuteAsync()
        {
            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            if (_args.Help)
            {
                return(1);
            }

            if (_args.IsFlubuSetup())
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                var script = await _scriptProvider.GetBuildScriptAsync(_args);

                _flubuSession.FlubuHelpText          = FlubuHelpText;
                _flubuSession.ScriptArgs             = _args.ScriptArguments;
                _flubuSession.TargetTree.BuildScript = script;
                _flubuSession.Properties.Set(BuildProps.IsWebApi, _args.IsWebApi);
                var result = script.Run(_flubuSession);
                return(result);
            }
            catch (TaskExecutionException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{e.ToString()}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (FlubuException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (Exception e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(3);
            }
        }