private static void InjectPropertyFromFetchBuildVersionFomFileAttribute(IFlubuSession flubuSession, IBuildScript buildScript, PropertyInfo property)
        {
            var fetchBuildVersion = property.GetCustomAttribute <FetchBuildVersionFromFileAttribute>();

            if (fetchBuildVersion == null)
            {
                return;
            }

            var task = flubuSession.Tasks().FetchBuildVersionFromFileTask().NoLog()
                       .When(() => fetchBuildVersion.AllowSuffix, t => t.AllowSuffix())
                       .When(() => !string.IsNullOrEmpty(fetchBuildVersion.ProjectVersionFileName),
                             t => t.ProjectVersionFileName(fetchBuildVersion.ProjectVersionFileName))
                       .When(() => fetchBuildVersion.PrefixesToRemove != null, t =>
            {
                foreach (var prefixToRemove in fetchBuildVersion.PrefixesToRemove)
                {
                    t.RemovePrefix(prefixToRemove);
                }
            });

            task.LogTaskExecutionInfo = false;

            var buildVersion = task.Execute(flubuSession);

            if (property.PropertyType != typeof(BuildVersion))
            {
                throw new ScriptException($"Failed to fetch build version. Property '{property.Name}' must be of type '{nameof(BuildVersion)}'");
            }

            property.SetValue(buildScript, buildVersion);
        }
Beispiel #2
0
        public static List <Hint> GetPropertiesHints(IBuildScript buildScript, IFlubuSession flubuSession)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());
            List <Hint>          hints = new List <Hint>();

            foreach (var property in props)
            {
                var attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                if (attributes.Count == 0)
                {
                    hints.Add(new Hint {
                        Name = property.Name
                    });
                }
                else
                {
                    foreach (var fromArgAttribute in attributes)
                    {
                        hints.Add(new Hint
                        {
                            Name      = fromArgAttribute.ArgKey,
                            Help      = fromArgAttribute.Help,
                            HintColor = ConsoleColor.DarkCyan
                        });
                    }
                }
            }

            return(hints);
        }
Beispiel #3
0
 public UpdateCenterController(IGitHubClient client, ITaskFactory taskFactory, IFlubuSession flubuSession, IHostEnvironment hostEnvironment, IHostApplicationLifetime applicationLifetime)
 {
     _client              = client;
     _taskFactory         = taskFactory;
     _flubuSession        = flubuSession;
     _hostEnvironment     = hostEnvironment;
     _applicationLifetime = applicationLifetime;
 }
        private void RunBuild(IFlubuSession flubuSession)
        {
            flubuSession.TargetTree.ResetTargetTree();
            ConfigureBuildProperties(flubuSession);

            ConfigureDefaultTargets(flubuSession);

            _scriptProperties.InjectProperties(this, flubuSession);

            _targetCreator.CreateTargetFromMethodAttributes(this, flubuSession);

            ConfigureTargets(flubuSession);

            if (!flubuSession.Args.InteractiveMode)
            {
                var targetsInfo = ParseCmdLineArgs(flubuSession.Args.MainCommands, flubuSession.TargetTree);
                flubuSession.UnknownTarget = targetsInfo.unknownTarget;
                if (targetsInfo.targetsToRun == null || targetsInfo.targetsToRun.Count == 0)
                {
                    var defaultTargets = flubuSession.TargetTree.DefaultTargets;
                    targetsInfo.targetsToRun = new List <string>();
                    if (defaultTargets != null && defaultTargets.Count != 0)
                    {
                        foreach (var defaultTarget in defaultTargets)
                        {
                            targetsInfo.targetsToRun.Add(defaultTarget.TargetName);
                        }
                    }
                    else
                    {
                        targetsInfo.targetsToRun.Add(FlubuTargets.Help);
                    }
                }

                var generateCIConfigs = flubuSession.Args.GenerateContinousIntegrationConfigs;
                if (generateCIConfigs != null)
                {
                    GenerateCiConfigs(flubuSession, generateCIConfigs, targetsInfo);
                }
                else
                {
                    if (!flubuSession.Args.IsWebApi)
                    {
                        GenerateCiConfigs(flubuSession, _flubuConfiguration.GenerateOnBuild(), targetsInfo);
                    }

                    ExecuteTarget(flubuSession, targetsInfo);
                }
            }
            else
            {
                var targetsInfo = ParseCmdLineArgs(flubuSession.InteractiveArgs.MainCommands, flubuSession.TargetTree);
                ExecuteTarget(flubuSession, targetsInfo);
            }
        }
        public void InjectProperties(IBuildScript buildScript, IFlubuSession flubuSession)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());

            foreach (var property in props)
            {
                InjectPropertiesFromScriptArg(buildScript, flubuSession, property);
                InjectPropertiesFromTaskAttributes(buildScript, flubuSession, property);
            }
        }
 public CommandExecutor(
     CommandArguments args,
     IScriptProvider scriptProvider,
     IFlubuSession flubuSession,
     ILogger <CommandExecutor> log,
     IFlubuTemplateTasksExecutor flubuTemplateTasksExecutor)
     : base(flubuSession, args, flubuTemplateTasksExecutor)
 {
     _scriptProvider = scriptProvider;
     _log            = log;
 }
Beispiel #7
0
 public CommandExecutor(
     CommandArguments args,
     IScriptLoader scriptLoader,
     IFlubuSession flubuSession,
     ILogger <CommandExecutor> log)
 {
     _args         = args;
     _scriptLoader = scriptLoader;
     _flubuSession = flubuSession;
     _log          = log;
 }
Beispiel #8
0
        public static void SetPropertiesFromScriptArg(IBuildScript buildScript, IFlubuSession flubuSession)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());

            foreach (var property in props)
            {
                var attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                foreach (var fromArgAttribute in attributes)
                {
                    if (!flubuSession.ScriptArgs.ContainsKey(fromArgAttribute.ArgKey))
                    {
                        continue;
                    }

                    if (property.PropertyType.GetTypeInfo().IsGenericType)
                    {
                        var propertyGenericTypeDefinition = property.PropertyType.GetGenericTypeDefinition();
                        if (propertyGenericTypeDefinition == typeof(IList <>) ||
                            propertyGenericTypeDefinition == typeof(List <>) ||
                            propertyGenericTypeDefinition == typeof(IEnumerable <>))
                        {
                            var list = flubuSession.ScriptArgs[fromArgAttribute.ArgKey].Split(fromArgAttribute.Seperator)
                                       .ToList();
                            property.SetValue(buildScript, list);
                        }
                    }
                    else
                    {
                        property.SetValue(buildScript, MethodParameterModifier.ParseValueByType(flubuSession.ScriptArgs[fromArgAttribute.ArgKey], property.PropertyType));
                    }
                }

                if (flubuSession.ScriptArgs.ContainsKey(property.Name))
                {
                    if (property.PropertyType.GetTypeInfo().IsGenericType)
                    {
                        var propertyGenericTypeDefinition = property.PropertyType.GetGenericTypeDefinition();
                        if (propertyGenericTypeDefinition == typeof(IList <>) ||
                            propertyGenericTypeDefinition == typeof(List <>) ||
                            propertyGenericTypeDefinition == typeof(IEnumerable <>))
                        {
                            property.SetValue(buildScript, flubuSession.ScriptArgs[property.Name].Split(',').ToList());
                        }
                    }
                    else
                    {
                        property.SetValue(buildScript, MethodParameterModifier.ParseValueByType(flubuSession.ScriptArgs[property.Name], property.PropertyType));
                    }
                }
            }
        }
Beispiel #9
0
 public CommandExecutorInteractive(
     CommandArguments args,
     IScriptProvider scriptProvider,
     IFlubuSession flubuSession,
     IScriptProperties scriptProperties,
     ILogger <CommandExecutorInteractive> log)
 {
     _args             = args;
     _scriptProvider   = scriptProvider;
     _flubuSession     = flubuSession;
     _scriptProperties = scriptProperties;
     _log = log;
 }
Beispiel #10
0
        public ScriptPropertiesSetterTests()
        {
            var sp = new ServiceCollection().AddTransient <ITarget, TargetFluentInterface>()
                     .AddTransient <ICoreTaskFluentInterface, CoreTaskFluentInterface>()
                     .AddTransient <ITaskFluentInterface, TaskFluentInterface>()
                     .AddTransient <ILinuxTaskFluentInterface, LinuxTaskFluentInterface>()
                     .AddTransient <IIisTaskFluentInterface, IisTaskFluentInterface>()
                     .AddTransient <IWebApiFluentInterface, WebApiFluentInterface>()
                     .AddSingleton <IHttpClientFactory, HttpClientFactory>()
                     .BuildServiceProvider();

            _flubuSession = new FlubuSession(new Mock <ILogger <FlubuSession> >().Object, new TargetTree(null, null), new CommandArguments(), new Mock <ITaskFactory>().Object, new FluentInterfaceFactory(sp), null, null);
        }
 public CommandExecutorInteractive(
     CommandArguments args,
     IScriptProvider scriptProvider,
     IFlubuSession flubuSession,
     IScriptProperties scriptProperties,
     ILogger <CommandExecutorInteractive> log,
     IFlubuTemplateTasksExecutor flubuTemplateTasksExecutor)
     : base(flubuSession, args, flubuTemplateTasksExecutor)
 {
     _scriptProvider   = scriptProvider;
     _flubuSession     = flubuSession;
     _scriptProperties = scriptProperties;
     _log = log;
 }
Beispiel #12
0
 public CommandExecutor(
     CommandArguments args,
     IScriptLoader scriptLoader,
     IFlubuSession flubuSession,
     IFileWrapper file,
     IPathWrapper path,
     ILogger <CommandExecutor> log)
 {
     _args         = args;
     _scriptLoader = scriptLoader;
     _flubuSession = flubuSession;
     _file         = file;
     _path         = path;
     _log          = log;
 }
Beispiel #13
0
        private void RunBuild(IFlubuSession flubuSession)
        {
            bool resetTargetTree = false;

            ConfigureDefaultProps(flubuSession);

            ConfigureBuildProperties(flubuSession);

            ConfigureDefaultTargets(flubuSession);

            ScriptProperties.SetPropertiesFromScriptArg(this, flubuSession);

            TargetCreator.CreateTargetFromMethodAttributes(this, flubuSession);

            ConfigureTargets(flubuSession);

            var targetsInfo = default((List <string> targetsToRun, bool unknownTarget, List <string> notFoundTargets));

            ConsoleHintedInput inputReader = null;

            if (!flubuSession.Args.InteractiveMode)
            {
                targetsInfo = ParseCmdLineArgs(flubuSession.Args.MainCommands, flubuSession.TargetTree);
                flubuSession.UnknownTarget = targetsInfo.unknownTarget;
                if (targetsInfo.targetsToRun == null || targetsInfo.targetsToRun.Count == 0)
                {
                    var defaultTargets = flubuSession.TargetTree.DefaultTargets;
                    targetsInfo.targetsToRun = new List <string>();
                    if (defaultTargets != null && defaultTargets.Count != 0)
                    {
                        foreach (var defaultTarget in defaultTargets)
                        {
                            targetsInfo.targetsToRun.Add(defaultTarget.TargetName);
                        }
                    }
                    else
                    {
                        targetsInfo.targetsToRun.Add("help");
                    }
                }

                ExecuteTarget(flubuSession, targetsInfo);
            }
            else
            {
                FlubuInteractiveMode(flubuSession, inputReader, targetsInfo, resetTargetTree);
            }
        }
        protected virtual FlubuConsole InitializeFlubuConsole(IFlubuSession flubuSession, IBuildScript script)
        {
            var source       = new Dictionary <string, IReadOnlyCollection <Hint> >();
            var propertyKeys = _scriptProperties.GetPropertiesHints(script);

            propertyKeys.Add(new Hint {
                Name = "--parallel", Help = "If applied target's are executed in parallel.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--dryrun", Help = "Performs a dry run of the specified target.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--noColor", Help = "Disables colored logging.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--nodeps", Help = "If applied no target dependencies are executed.", HintColor = ConsoleColor.Magenta
            });
            source.Add("-", propertyKeys);
            var enumHints = _scriptProperties.GetEnumHints(script, flubuSession);

            if (enumHints != null)
            {
                source.AddRange(enumHints);
            }

            List <Hint> defaultHints = new List <Hint>();

            if (script is DefaultBuildScript defaultBuildScript)
            {
                defaultBuildScript.ConfigureDefaultProps(flubuSession);
                defaultBuildScript.ConfigureBuildPropertiesInternal(flubuSession);
                defaultBuildScript.ConfigureTargetsInternal(flubuSession);
            }

            foreach (var targetName in flubuSession.TargetTree.GetTargetNames())
            {
                var target = flubuSession.TargetTree.GetTarget(targetName);
                defaultHints.Add(new Hint
                {
                    Name = target.TargetName,
                    Help = target.Description
                });
            }

            var flubuConsole = new FlubuConsole(flubuSession.TargetTree, defaultHints, source);

            return(flubuConsole);
        }
        public void ConfigureTargetWithIisTasks()
        {
            IFlubuSession session = _sp.GetRequiredService <IFlubuSession>();

            SimpleBuildScript bs = new SimpleBuildScript();

            bs.Run(session);

            Assert.True(session.TargetTree.HasAllTargets(new List <string>()
            {
                "IIS"
            }, out _));

            Target t = (Target)session.TargetTree.GetTarget("IIS");

            Assert.Equal(2, t.TasksGroups.Count);
            Assert.Empty(t.Dependencies);
        }
Beispiel #16
0
 public CommandExecutorInteractive(
     CommandArguments args,
     IScriptProvider scriptProvider,
     IFlubuSession flubuSession,
     IScriptProperties scriptProperties,
     IFlubuCommandParser parser,
     IFileWrapper fileWrapper,
     IBuildScriptLocator buildScriptLocator,
     ILogger <CommandExecutorInteractive> log)
 {
     _args               = args;
     _scriptProvider     = scriptProvider;
     _flubuSession       = flubuSession;
     _scriptProperties   = scriptProperties;
     _parser             = parser;
     _fileWrapper        = fileWrapper;
     _buildScriptLocator = buildScriptLocator;
     _log = log;
 }
        public void ConfigureSimpleTarget()
        {
            IFlubuSession session = _sp.GetRequiredService <IFlubuSession>();

            SimpleBuildScript bs = new SimpleBuildScript();

            bs.Run(session);

            Assert.True(session.TargetTree.HasAllTargets(new List <string>()
            {
                "test"
            }, out _));
            Assert.True(session.TargetTree.HasAllTargets(new List <string>()
            {
                "test1"
            }, out _));

            ITargetInternal t  = session.TargetTree.GetTarget("test");
            ITargetInternal t1 = session.TargetTree.GetTarget("test1");

            Assert.Equal(t.TargetName, t1.Dependencies.FirstOrDefault().Key);
        }
        private static void InjectPropertyFromLoadSolutionAttribute(IFlubuSession flubuSession, IBuildScript buildScript, PropertyInfo property)
        {
            var loadSolutionAttribute = property.GetCustomAttribute <LoadSolutionAttribute>();

            if (loadSolutionAttribute == null)
            {
                return;
            }

            if (property.PropertyType != typeof(VSSolution))
            {
                throw new ScriptException($"Failed to fetch Solution information. Property '{property.Name}' must be of type '{nameof(VSSolution)}'");
            }

            var vsSolution = !string.IsNullOrEmpty(loadSolutionAttribute.SolutionName)
                ? flubuSession.Tasks().LoadSolutionTask(loadSolutionAttribute.SolutionName)
                             .Execute(flubuSession)
                : flubuSession.Tasks().LoadSolutionTask()
                             .Execute(flubuSession);

            property.SetValue(buildScript, vsSolution);
        }
        private static void InjectPropertyFromGitVersionAttribute(IFlubuSession flubuSession, IBuildScript buildScript, PropertyInfo property)
        {
            var gitVersionAttr = property.GetCustomAttribute <GitVersionAttribute>();

            if (gitVersionAttr == null)
            {
                return;
            }

            var task = flubuSession.Tasks().GitVersionTask().NoLog();

            task.LogTaskExecutionInfo = false;

            var gitVersion = task.Execute(flubuSession);

            if (property.PropertyType != typeof(GitVersion))
            {
                throw new ScriptException($"Failed to fetch git version. Property '{property.Name}' must be of type '{nameof(GitVersion)}'");
            }

            property.SetValue(buildScript, gitVersion);
        }
Beispiel #20
0
 private void ExecuteTarget(IFlubuSession flubuSession, (List <string> targetsToRun, bool unknownTarget, List <string> notFoundTargets) targetsInfo)
        public int Run(IFlubuSession flubuSession)
        {
            _flubuSession       = flubuSession;
            _scriptProperties   = flubuSession.ScriptServiceProvider.GetScriptProperties();
            _targetCreator      = flubuSession.ScriptServiceProvider.GetTargetCreator();
            _flubuConfiguration = flubuSession.ScriptServiceProvider.GetFlubuConfiguration();

            try
            {
                ConfigureDefaultProps(flubuSession);
                BeforeBuildExecution(flubuSession);
                RunBuild(flubuSession);
                flubuSession.Complete();
                AfterBuildExecution(flubuSession);
                return(0);
            }
            catch (TargetNotFoundException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);
                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                flubuSession.LogError($"{Environment.NewLine}{e.Message}");
                return(3);
            }
            catch (WebApiException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);
                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(1);
            }
            catch (FlubuException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);

                if (!flubuSession.Args.RethrowOnException)
                {
                    flubuSession.LogError($"ERROR: {e.Message}", Color.Red);
                }

                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(1);
            }
            catch (Exception e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);

                if (!flubuSession.Args.RethrowOnException)
                {
                    flubuSession.LogError($"ERROR: {e}", Color.Red);
                }

                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(2);
            }
        }
        protected virtual void FlubuInteractiveMode(IFlubuSession flubuSession, IBuildScript script)
        {
            flubuSession.InteractiveMode = true;
            var flubuConsole = InitializeFlubuConsole(flubuSession, script);

            flubuSession.TargetTree.ScriptArgsHelp = _scriptProperties.GetPropertiesHelp(script);
            flubuSession.TargetTree.RunTarget(flubuSession, FlubuTargets.HelpOnlyTargets);
            flubuSession.LogInfo(" ");

            do
            {
                if (flubuSession.InteractiveMode)
                {
                    var commandLine = flubuConsole.ReadLine();

                    if (string.IsNullOrEmpty(commandLine))
                    {
                        continue;
                    }

                    var cmdApp = new CommandLineApplication()
                    {
                        UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.CollectAndContinue
                    };
                    var parser = new FlubuCommandParser(cmdApp, null, null, null);
                    var args   = parser.Parse(commandLine.Split(' ')

                                              .Where(x => !string.IsNullOrWhiteSpace(x))
                                              .Select(x => x.Trim()).ToArray());
                    var targetsInfo = DefaultBuildScript.ParseCmdLineArgs(args.MainCommands, flubuSession.TargetTree);

                    if (args.MainCommands.Count == 0)
                    {
                        continue;
                    }

                    if (!args.MainCommands[0].Equals("l", StringComparison.OrdinalIgnoreCase) &&
                        !args.MainCommands[0].Equals("load", StringComparison.OrdinalIgnoreCase))
                    {
                        args.Script = flubuSession.InteractiveArgs.Script;
                    }

                    flubuSession.InteractiveArgs = args;
                    flubuSession.ScriptArgs      = args.ScriptArguments;
                    _scriptProperties.InjectProperties(script, flubuSession);

                    if (InternalTerminalCommands.InteractiveExitAndReloadCommands.Contains(args.MainCommands[0],
                                                                                           StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    if (targetsInfo.unknownTarget)
                    {
                        var internalCommandExecuted = flubuConsole.ExecuteInternalCommand(commandLine);
                        if (internalCommandExecuted)
                        {
                            continue;
                        }

                        var splitedLine = commandLine.Split(' ').ToList();
                        var command     = splitedLine.First();
                        var runProgram  = flubuSession.Tasks().RunProgramTask(command).DoNotLogTaskExecutionInfo()
                                          .WorkingFolder(Directory.GetCurrentDirectory());
                        splitedLine.RemoveAt(0);
                        try
                        {
                            runProgram.WithArguments(splitedLine.ToArray()).Execute(flubuSession);
                        }
                        catch (CommandUnknownException)
                        {
                            flubuSession.LogError(
                                $"'{command}' is not recognized as a flubu target, internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException e)
                        {
                            flubuSession.LogError($"ERROR: {(flubuSession.Args.Debug ? e.ToString() : e.Message)}", Color.Red);
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (Win32Exception)
                        {
                        }

                        continue;
                    }
                }

                try
                {
                    script.Run(flubuSession);
                    flubuSession.LogInfo(" ");
                }
                catch (Exception e)
                {
                    flubuSession.LogError($"ERROR: {(flubuSession.Args.Debug ? e.ToString() : e.Message)}", Color.Red);
                }
            }while (flubuSession.InteractiveMode);
        }
Beispiel #23
0
        public static void SetPropertiesFromScriptArg(IBuildScript buildScript, IFlubuSession flubuSession)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());

            foreach (var property in props)
            {
                var    attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                string argKey     = null;
                foreach (var fromArgAttribute in attributes)
                {
                    var argKeys = fromArgAttribute.ArgKey.Split('|');
                    foreach (var key in argKeys)
                    {
                        if (!flubuSession.ScriptArgs.ContainsKey(key))
                        {
                            continue;
                        }

                        argKey = key;
                        break;
                    }

                    if (argKey == null)
                    {
                        continue;
                    }

                    if (property.PropertyType.GetTypeInfo().IsGenericType)
                    {
                        var propertyGenericTypeDefinition = property.PropertyType.GetGenericTypeDefinition();
                        if (propertyGenericTypeDefinition == typeof(IList <>) ||
                            propertyGenericTypeDefinition == typeof(List <>) ||
                            propertyGenericTypeDefinition == typeof(IEnumerable <>))
                        {
                            var list = flubuSession.ScriptArgs[argKey].Split(fromArgAttribute.Seperator)
                                       .ToList();
                            property.SetValue(buildScript, list);
                        }
                    }
                    else
                    {
                        SetPropertyValue(property, buildScript, flubuSession.ScriptArgs[argKey], property.PropertyType, argKey);
                    }
                }

                if (flubuSession.ScriptArgs.ContainsKey(property.Name))
                {
                    if (property.PropertyType.GetTypeInfo().IsGenericType)
                    {
                        var propertyGenericTypeDefinition = property.PropertyType.GetGenericTypeDefinition();
                        if (propertyGenericTypeDefinition == typeof(IList <>) ||
                            propertyGenericTypeDefinition == typeof(List <>) ||
                            propertyGenericTypeDefinition == typeof(IEnumerable <>))
                        {
                            property.SetValue(buildScript, flubuSession.ScriptArgs[property.Name].Split(',').ToList());
                        }
                    }
                    else
                    {
                        SetPropertyValue(property, buildScript, flubuSession.ScriptArgs[property.Name], property.PropertyType, property.Name);
                    }
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Searches methods with Target attribute in specified type and creates targets.
        /// </summary>
        /// <param name="buildScriptType"></param>
        /// <param name="flubuSession"></param>
        public void CreateTargetFromMethodAttributes(IBuildScript buildScript, IFlubuSession flubuSession)
        {
            #if !NETSTANDARD1_6
            var buildScriptType = buildScript.GetType();
            var methods         = buildScriptType.GetRuntimeMethods().Where(x => x.DeclaringType == buildScriptType).ToList();
            foreach (var methodInfo in methods)
            {
                var attributes = methodInfo.GetCustomAttributes <TargetAttribute>(false).ToList();

                if (attributes.Count == 0)
                {
                    continue;
                }

                foreach (var attribute in attributes)
                {
                    var methodParameters = methodInfo.GetParameters().ToList();

                    if (methodParameters.Count == 0)
                    {
                        throw new ScriptException($"Failed to create target '{attribute.TargetName}'. Method '{methodInfo.Name}' must have atleast one parameter which must be of type '{nameof(ITarget)}'");
                    }

                    if (methodParameters[0].ParameterType != typeof(ITarget))
                    {
                        throw new ScriptException($"Failed to create target '{attribute.TargetName}' first parameter in method '{methodInfo.Name}' must be of type '{nameof(ITarget)}'");
                    }

                    var target = flubuSession.CreateTarget(attribute.TargetName);
                    var attributeParamaters = new List <object>()
                    {
                        target
                    };

                    attributeParamaters.AddRange(attribute.MethodParameters);

                    if (methodParameters.Count != attributeParamaters.Count)
                    {
                        throw new ScriptException($"Failed to create target '{attribute.TargetName}'. Method parameters {methodInfo.Name} do not match count of attribute parametrs.");
                    }

                    for (int i = 0; i < methodParameters.Count; i++)
                    {
                        if (i != 0 && methodParameters[i].ParameterType != attributeParamaters[i].GetType())
                        {
                            throw new ScriptException($"Failed to create target '{attribute.TargetName}'. Attribute parameter {i + 1.ToString()} does not match '{methodInfo.Name}' method parameter {i + 1.ToString()}. Expected {methodParameters[i].ParameterType} Actual: {attributeParamaters[i].GetType()}");
                        }
                    }

                    var parameterInfos = methodInfo.GetParameters();
                    for (int i = 0; i < parameterInfos.Length; i++)
                    {
                        ParameterInfo parameter       = parameterInfos[i];
                        var           paramAttributes = parameter.GetCustomAttributes <FromArgAttribute>(false).ToList();
                        foreach (var fromArgAttribute in paramAttributes)
                        {
                            if (!flubuSession.Args.ScriptArguments.ContainsKey(fromArgAttribute.ArgKey))
                            {
                                continue;
                            }

                            attributeParamaters[i] = MethodParameterModifier.ParseValueByType(flubuSession.Args.ScriptArguments[fromArgAttribute.ArgKey], parameter.ParameterType);
                        }

                        if (flubuSession.Args.ScriptArguments.ContainsKey(parameter.Name))
                        {
                            object parsedValue = MethodParameterModifier.ParseValueByType(flubuSession.Args.ScriptArguments[parameter.Name], parameter.ParameterType);
                            attributeParamaters[i] = parsedValue;
                        }
                    }

                    methodInfo.Invoke(buildScript, attributeParamaters.ToArray());
                }
            }
#endif
        }
 public TemplateReplacementTokenTask(IFlubuSession flubuSession)
 {
     _flubuSession = flubuSession;
 }
Beispiel #26
0
 protected InternalCommandExecutor(IFlubuSession flubuSession, CommandArguments args, IFlubuTemplateTasksExecutor flubuTemplateTasksExecutor)
 {
     FlubuSession = flubuSession;
     Args         = args;
     FlubuTemplateTasksExecutor = flubuTemplateTasksExecutor;
 }
Beispiel #27
0
        public int Run(IFlubuSession flubuSession)
        {
            _flubuSession = flubuSession;
            try
            {
                ConfigureDefaultProps(flubuSession);
                BeforeBuildExecution(flubuSession);
                RunBuild(flubuSession);
                flubuSession.Complete();
                AfterBuildExecution(flubuSession);
                return(0);
            }
            catch (TargetNotFoundException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);
                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                flubuSession.LogError(e.Message);
                return(3);
            }
            catch (WebApiException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);
                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(1);
            }
            catch (FlubuException e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);

                if (!flubuSession.Args.RethrowOnException)
                {
#if !NETSTANDARD1_6
                    flubuSession.LogError($"ERROR: {e.Message}", Color.Red);
#else
                    flubuSession.LogError($"error: {e.Message}");
#endif
                }

                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(1);
            }
            catch (Exception e)
            {
                flubuSession.ResetDepth();
                OnBuildFailed(flubuSession, e);

                if (!flubuSession.Args.RethrowOnException)
                {
#if !NETSTANDARD1_6
                    flubuSession.LogError($"ERROR: {e}", Color.Red);
#else
                    flubuSession.LogError($"error: {e}");
#endif
                }

                AfterBuildExecution(flubuSession);
                if (flubuSession.Args.RethrowOnException)
                {
                    throw;
                }

                return(2);
            }
        }
Beispiel #28
0
        public static Dictionary <string, IReadOnlyCollection <Hint> > GetEnumHints(IBuildScript buildScript, IFlubuSession flubuSession)
        {
#if !NETSTANDARD1_6
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());
            Dictionary <string, IReadOnlyCollection <Hint> > hints = new Dictionary <string, IReadOnlyCollection <Hint> >();
            foreach (var property in props)
            {
                var type = property.PropertyType;
                if (type.IsEnum)
                {
                    var    attribute = property.GetCustomAttribute <FromArgAttribute>(false);
                    string argKey    = null;

                    if (attribute != null)
                    {
                        argKey = attribute.ArgKey.Split('|')[0];
                    }
                    else
                    {
                        argKey = property.Name;
                    }

                    var enumValues = Enum.GetValues(type);

                    List <Hint> values = new List <Hint>();
                    foreach (var enumValue in enumValues)
                    {
                        values.Add(new Hint
                        {
                            Name     = enumValue.ToString(),
                            HintType = HintType.Value,
                        });
                    }

                    hints.Add(argKey.ToLower(), values);
                }
            }

            return(hints);
#endif
            return(null);
        }
 private static void InjectPropertiesFromTaskAttributes(IBuildScript buildScript, IFlubuSession flubuSession, PropertyInfo property)
 {
     InjectPropertyFromFetchBuildVersionFomFileAttribute(flubuSession, buildScript, property);
     InjectPropertyFromGitVersionAttribute(flubuSession, buildScript, property);
     InjectPropertyFromLoadSolutionAttribute(flubuSession, buildScript, property);
 }
Beispiel #30
0
 public ReportsController(IHostingEnvironment hostingEnvironment, ITaskFactory taskFactory, IFlubuSession flubuSession)
 {
     _hostingEnvironment = hostingEnvironment;
     _taskFactory        = taskFactory;
     _flubuSession       = flubuSession;
 }