예제 #1
0
 public PythonScriptedBuilder(Project project, IBuildScript buildScript, ISourceSetFingerprintFactory fingerprintFactory, IProjectBuildScriptRunner scriptRunner)
 {
     this.project            = project;
     this.buildScript        = buildScript;
     this.fingerprintFactory = fingerprintFactory;
     this.scriptRunner       = scriptRunner;
 }
예제 #2
0
        public List <string> GetPropertiesHelp(IBuildScript buildScript)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());
            List <string>        help  = new List <string>();

            foreach (var property in props)
            {
                var attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                foreach (var fromArgAttribute in attributes)
                {
                    var key  = $"-{fromArgAttribute.ArgKey.Replace("|", "|-")}";
                    var type = property.PropertyType;
                    if (type.IsEnum)
                    {
                        var enumValues = Enum.GetValues(type);

                        key = $"{key}(";
                        foreach (var enumValue in enumValues)
                        {
                            key = $"{key}{enumValue}, ";
                        }

                        key = $"{key.Substring(0, key.Length - 2)})";
                    }

                    if (!string.IsNullOrEmpty(fromArgAttribute.Help))
                    {
                        help.Add($"{key} : {fromArgAttribute.Help}");
                    }
                }
            }

            return(help);
        }
예제 #3
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);
        }
예제 #4
0
파일: Program.cs 프로젝트: breki/flubu
        public static int Main(string[] args)
        {
            try
            {
                IFileExistsService fileExistsService = new FileExistsService();
                IConsoleLogger     consoleLogger     = new ConsoleLogger();
                IScriptLoader      scriptLoader      = new ScriptLoader();

                List <string> arguments = new List <string>(args);

                BuildScriptLocator buildScriptLocator =
                    new BuildScriptLocator(fileExistsService, consoleLogger, scriptLoader);

                IBuildScript script =
                    buildScriptLocator.FindBuildScript(arguments);

                //Parser p = new Parser();
                //p.ParseArguments(args);

                return(script.Run(arguments));
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Error executing script the script");
                System.Console.WriteLine(ex.ToString());
                return(1);
            }
        }
예제 #5
0
        private async Task SimpleFlubuInteractiveMode(IBuildScript script)
        {
            do
            {
                try
                {
                    var flubuConsole = new FlubuConsole(null, new List <Hint>());
                    var commandLine  = flubuConsole.ReadLine(Directory.GetCurrentDirectory());

                    var splitedLine = commandLine.Split(' ').ToList();

                    if (InteractiveExitCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    var app = new CommandLineApplication(false);
                    IFlubuCommandParser parser = new FlubuCommandParser(app, null);
                    var args = parser.Parse(commandLine.Split(' ')
                                            .Where(x => !string.IsNullOrWhiteSpace(x))
                                            .Select(x => x.Trim()).ToArray());
                    _flubuSession.InteractiveArgs = args;
                    _flubuSession.ScriptArgs      = args.ScriptArguments;

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

                    if (!ReloadCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        var command    = splitedLine.First();
                        var runProgram = _flubuSession.Tasks().RunProgramTask(command).DoNotLogTaskExecutionInfo()
                                         .WorkingFolder(".");
                        splitedLine.RemoveAt(0);
                        try
                        {
                            runProgram.WithArguments(splitedLine.ToArray()).Execute(_flubuSession);
                        }
                        catch (CommandUnknownException)
                        {
                            _flubuSession.LogError($"'{command}' is not recognized as a internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException)
                        {
                        }
                    }
                    else
                    {
                        script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_flubuSession.InteractiveArgs);
                    }
                }
                catch (BuildScriptLocatorException)
                {
                }
            }while (script == null);
        }
예제 #6
0
        public async Task LoadSimpleScript()
        {
            CommandArguments args = new CommandArguments();

            _scriptLocator.Setup(x => x.FindBuildScript(args)).Returns("e3.cs");
            _fileLoader.Setup(i => i.ReadAllLines("e3.cs"))
            .Returns(new List <string>
            {
                "using FlubuCore.Scripting;",
                "using System;",
                "using FlubuCore.Context;",
                "using Microsoft.Extensions.DependencyInjection;",
                "using Microsoft.Extensions.Logging;",
                string.Empty,
                "public class MyBuildScript : IBuildScript",
                "{",
                "    public int Run(IFlubuSession session)",
                "    {",
                "        Console.WriteLine(\"11\");",
                "        return 0;",
                "    }",

                "    public void ConfigureServices(IServiceCollection services)",
                "    {",
                "    }",

                "    public void Configure(ILoggerFactory loggerFactory)",
                "    {",
                "    }",
                "}",
            });

            _analyzer.Setup(i => i.Analyze(It.IsAny <List <string> >()))
            .Returns(new ScriptAnalyzerResult()
            {
                ClassName = "MyBuildScript"
            });

            IBuildScript t = await _loader.FindAndCreateBuildScriptInstanceAsync(args);

            var provider = new ServiceCollection()
                           .AddSingleton <IScriptProperties, ScriptProperties>()
                           .AddSingleton <ITargetCreator, TargetCreator>()
                           .BuildServiceProvider();

            var targetTree = new TargetTree(provider, new CommandArguments());

            t.Run(new FlubuSession(
                      _loggerTaskSession.Object,
                      targetTree,
                      new CommandArguments(),
                      new ScriptFactory(provider),
                      new DotnetTaskFactory(provider),
                      new FluentInterfaceFactory(provider),
                      new BuildPropertiesSession(targetTree),
                      new BuildSystem()));
        }
예제 #7
0
        public void Test()
        {
            ScriptLoader loader = new ScriptLoader();
            IBuildScript script = loader.FindAndCreateBuildScriptInstance(
                Path.Combine(
                    TestContext.CurrentContext.TestDirectory,
                    @"Samples\BuildScript.cs"));

            Assert.IsNotNull(script);
        }
예제 #8
0
        /// <summary>
        /// Searches methods with Target attribute in specified type and creates targets.
        /// </summary>
        /// <param name="buildScriptType"></param>
        /// <param name="taskSession"></param>
        public static void CreateTargetFromMethodAttributes(IBuildScript buildScript, ITaskSession taskSession)
        {
            #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 = taskSession.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()}");
                        }
                    }

                    methodInfo.Invoke(buildScript, attributeParamaters.ToArray());
                }
            }
#endif
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        public async Task <IBuildScript> GetBuildScriptAsync(CommandArguments commandArguments, bool forceReload = false)
        {
            if (_script != null && !forceReload)
            {
                return(_script);
            }

            _script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(commandArguments);

            return(_script);
        }
예제 #11
0
        public async System.Threading.Tasks.Task LoadDefaultScriptWithAnotherClass()
        {
            CommandArguments args = new CommandArguments();

            _scriptLocator.Setup(x => x.FindBuildScript(args)).Returns("e2.cs");
            _fileLoader.Setup(i => i.ReadAllLines("e2.cs"))
            .Returns(new List <string>
            {
                "using System;",
                "using FlubuCore.Context;",
                "using FlubuCore.Scripting;",
                string.Empty,
                "public class MyBuildScript : DefaultBuildScript",
                "{",
                "    protected override void ConfigureBuildProperties(IBuildPropertiesContext context)",
                "    {",
                "        System.Console.WriteLine(\"2222\");",
                "        }",
                string.Empty,
                "        protected override void ConfigureTargets(ITaskContext context)",
                "        {",
                "            var test = new Test();",
                "        }",
                "    }",
                "public class Test",
                "{",
                "}"
            });

            _analyzer.Setup(i => i.Analyze(It.IsAny <List <string> >()))
            .Returns(new ScriptAnalyzerResult()
            {
                ClassName = "MyBuildScript"
            });

            IBuildScript t = await _loader.FindAndCreateBuildScriptInstanceAsync(args);

            var provider = new ServiceCollection()
                           .AddSingleton <IScriptProperties, ScriptProperties>()
                           .AddSingleton <ITargetCreator, TargetCreator>()
                           .BuildServiceProvider();
            var targetTree = new TargetTree(provider, new CommandArguments());

            t.Run(new FlubuSession(
                      _loggerTaskSession.Object,
                      targetTree,
                      new CommandArguments(),
                      new ScriptFactory(provider),
                      new DotnetTaskFactory(provider),
                      new FluentInterfaceFactory(provider),
                      new BuildPropertiesSession(targetTree),
                      new BuildSystem()));
        }
예제 #12
0
        public static void SetPropertiesFromScriptArg(IBuildScript buildScript, ITaskSession taskSession)
        {
            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 (!taskSession.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 = taskSession.ScriptArgs[fromArgAttribute.ArgKey].Split(fromArgAttribute.Seperator)
                                       .ToList();
                            property.SetValue(buildScript, list);
                        }
                    }
                    else
                    {
                        property.SetValue(buildScript, MethodParameterModifier.ParseValueByType(taskSession.ScriptArgs[fromArgAttribute.ArgKey], property.PropertyType));
                    }
                }

                if (taskSession.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, taskSession.ScriptArgs[property.Name].Split(',').ToList());
                        }
                    }
                    else
                    {
                        property.SetValue(buildScript, MethodParameterModifier.ParseValueByType(taskSession.ScriptArgs[property.Name], property.PropertyType));
                    }
                }
            }
        }
예제 #13
0
        public PythonScriptedBuilder(Project project, IBuildScript buildScript, ISourceSetFingerprintFactory fingerprintFactory, IProjectBuildScriptRunner scriptRunner)
        {
            this.project      = project;
            this.buildScript  = buildScript;
            this.scriptRunner = scriptRunner;

            dependencies = new Lazy <IDependencies>(() => MultipleDependenciesHelper.CreateMultipleDependencies(
                                                        new HashSet <IDependencies>(new IDependencies[]
            {
                new SourceSetDependencies(fingerprintFactory, project.GetSourceSet(buildScript.SourceSetName)),
                new ScriptDependency(buildScript)
            })));
        }
예제 #14
0
 private static void SetPropertyValue(PropertyInfo propertyInfo, IBuildScript buildScript, string value, Type type, string argKey)
 {
     try
     {
         propertyInfo.SetValue(buildScript, MethodParameterModifier.ParseValueByType(value, type));
     }
     catch (FormatException e)
     {
         throw new ScriptException($"Could not pass value '{value}' from argument '{argKey}' to build script property '{propertyInfo.Name}'", e);
     }
     catch (ArgumentException e)
     {
         throw new ScriptException($"Could not pass value '{value}' from argument '{argKey}' to build script property '{propertyInfo.Name}'", e);
     }
 }
예제 #15
0
        /// <summary>
        /// Executes the given build script on the given project, returning the set of
        /// target files the script generated.
        ///
        /// <para>
        /// The script's global scope has the following predefined variables set:
        /// - <c>project</c> refers to the project being built
        /// - <c>sourceSet</c> is the project's source set associated with the build script
        /// - <c>targetRoot</c> is the root target directory where all the files are generated
        /// - <c>targetDir</c> is where the project's output should be built
        /// </para>
        /// <para>
        /// A special global function <c>get_tool</c> is available which accepts a reference URI and
        /// a file name.
        /// The same protocols are supported as for references in the suite definition. The
        /// function's return value is the absolute path of the given file, where the tool
        /// has been deployed.
        /// </para>
        /// </summary>
        /// <param name="project">The input project to build</param>
        /// <param name="buildScript">The build script to execute</param>
        /// <returns>Returns the set of files generated by the script. They have to be
        /// indicated in the script's <c>results</c> variable, relative to <c>targetDir</c>.</returns>
        public ISet <TargetRelativePath> Run(Project project, IBuildScript buildScript)
        {
            var engine = CreateEngine();

            var runtime = engine.Runtime;

            try
            {
                var scope = runtime.CreateScope();

                scope.SetVariable("project", project);
                scope.SetVariable("sourceSet",
                                  project.GetSourceSet(buildScript.SourceSetName)
                                  .Files.Select(srp => (string)srp)
                                  .ToList());
                AddGetToolToScope(scope, project);

                var targetDir       = TargetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);
                var localTargetDir  = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);

                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;

                    var script = engine.CreateScriptSourceFromString(buildScript.Source, SourceCodeKind.File);
                    script.Compile(pco);
                    script.Execute(scope);

                    return(new HashSet <TargetRelativePath>(
                               scope.GetVariable <IList <object> >("results")
                               .Cast <string>()
                               .Select(t => GetTargetRelativePath(targetDir, t))));
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }
예제 #16
0
        /// <summary>
        /// Executes the given build script on the given project, returning the set of
        /// target files the script generated.
        /// 
        /// <para>
        /// The script's global scope has the following predefined variables set:
        /// - <c>project</c> refers to the project being built
        /// - <c>sourceSet</c> is the project's source set associated with the build script
        /// - <c>targetRoot</c> is the root target directory where all the files are generated
        /// - <c>targetDir</c> is where the project's output should be built
        /// </para>
        /// <para>
        /// A special global function <c>get_tool</c> is available which accepts a reference URI and
        /// a file name. 
        /// The same protocols are supported as for references in the suite definition. The 
        /// function's return value is the absolute path of the given file, where the tool
        /// has been deployed.
        /// </para>
        /// </summary>
        /// <param name="project">The input project to build</param>
        /// <param name="buildScript">The build script to execute</param>
        /// <returns>Returns the set of files generated by the script. They have to be
        /// indicated in the script's <c>results</c> variable, relative to <c>targetDir</c>.</returns>
        public ISet<TargetRelativePath> Run(Project project, IBuildScript buildScript)
        {
            var engine = CreateEngine();
            
            var runtime = engine.Runtime;
            try
            {
                var scope = runtime.CreateScope();

                scope.SetVariable("project", project);
                scope.SetVariable("sourceSet",
                                  project.GetSourceSet(buildScript.SourceSetName)
                                         .Files.Select(srp => (string) srp)
                                         .ToList());
                AddGetToolToScope(scope, project);

                var targetDir = TargetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);
                var localTargetDir = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);

                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;
                    
                    var script = engine.CreateScriptSourceFromString(buildScript.Source, SourceCodeKind.File);
                    script.Compile(pco);
                    script.Execute(scope);

                    return new HashSet<TargetRelativePath>(
                        scope.GetVariable<IList<object>>("results")
                             .Cast<string>()
                             .Select(t => GetTargetRelativePath(targetDir, t)));
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }
예제 #17
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);
        }
예제 #18
0
        public static List <string> GetPropertiesHelp(IBuildScript buildScript)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());
            List <string>        help  = new List <string>();

            foreach (var property in props)
            {
                var attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                foreach (var fromArgAttribute in attributes)
                {
                    if (!string.IsNullOrEmpty(fromArgAttribute.Help))
                    {
                        help.Add($"-{fromArgAttribute.ArgKey} : {fromArgAttribute.Help}");
                    }
                }
            }

            return(help);
        }
예제 #19
0
        public async Task LoadSimpleScript()
        {
            CommandArguments args = new CommandArguments();

            _scriptLocator.Setup(x => x.FindBuildScript(args)).Returns("e3.cs");
            _fileLoader.Setup(i => i.ReadAllLines("e3.cs"))
            .Returns(new List <string>
            {
                "using FlubuCore.Scripting;",
                "using System;",
                "using FlubuCore.Context;",
                string.Empty,
                "public class MyBuildScript : IBuildScript",
                "{",
                "    public int Run(ITaskSession session)",
                "    {",
                "        Console.WriteLine(\"11\");",
                "        return 0;",
                "    }",
                "}",
            });

            _analyser.Setup(i => i.Analyze(It.IsAny <List <string> >()))
            .Returns(new AnalyserResult()
            {
                ClassName = "MyBuildScript"
            });

            IBuildScript t = await _loader.FindAndCreateBuildScriptInstanceAsync(args);

            var provider = new ServiceCollection().BuildServiceProvider();

            t.Run(new TaskSession(
                      null,
                      new TargetTree(provider, new CommandArguments()),
                      new CommandArguments(),
                      new DotnetTaskFactory(provider),
                      new FluentInterfaceFactory(provider),
                      new BuildPropertiesSession(),
                      new BuildSystem()));
        }
예제 #20
0
        public static List <string> GetPropertiesKeys(IBuildScript buildScript, ITaskSession taskSession)
        {
            var buildScriptType        = buildScript.GetType();
            IList <PropertyInfo> props = new List <PropertyInfo>(buildScriptType.GetProperties());
            List <string>        keys  = new List <string>();

            foreach (var property in props)
            {
                var attributes = property.GetCustomAttributes <FromArgAttribute>(false).ToList();
                if (attributes.Count == 0)
                {
                    keys.Add(property.Name);
                }
                else
                {
                    foreach (var fromArgAttribute in attributes)
                    {
                        keys.Add(fromArgAttribute.ArgKey);
                    }
                }
            }

            return(keys);
        }
        public virtual async Task <int> ExecuteAsync()
        {
            if (Args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

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

            if (Args.IsInternalCommand())
            {
                await ExecuteInternalCommand();

                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)
                        {
                            _flubuSession.LogInfo("Build script not found.");
                            script = await SimpleFlubuInteractiveMode(script);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    _flubuSession.ScriptArgs             = Args.ScriptArguments;
                    _flubuSession.InteractiveMode        = Args.InteractiveMode;
                    _flubuSession.InteractiveArgs        = Args;
                    _flubuSession.TargetTree.BuildScript = script;
                    _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 && InternalTerminalCommands.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);
            }
        }
        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);
        }
        protected virtual async Task <IBuildScript> SimpleFlubuInteractiveMode(IBuildScript script)
        {
            do
            {
                try
                {
                    var flubuConsole = new FlubuConsole(_flubuSession.TargetTree, new List <Hint>());
                    var commandLine  = flubuConsole.ReadLine();

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

                    var splitedLine = commandLine.Split(' ').ToList();

                    if (InternalTerminalCommands.InteractiveExitOnlyCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    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());
                    _flubuSession.InteractiveArgs = args;
                    _flubuSession.ScriptArgs      = args.ScriptArguments;
                    Args = args;
                    Args.InteractiveMode = true;

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

                    if (!InternalTerminalCommands.ReloadCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        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 internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException)
                        {
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (Win32Exception)
                        {
                        }
                    }
                    else
                    {
                        script = await _scriptProvider.GetBuildScriptAsync(_flubuSession.InteractiveArgs, true);
                    }
                }
                catch (BuildScriptLocatorException)
                {
                    _flubuSession.LogInfo("Build script not found.");
                }
            }while (script == null);

            return(script);
        }
        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);
        }
예제 #25
0
        /// <summary>
        /// Executes the given build script on the given project, returning the set of
        /// target files the script generated.
        /// 
        /// <para>
        /// The script's global scope has the following predefined variables set:
        /// - <c>project</c> refers to the project being built
        /// - <c>sourceSet</c> is the project's source set associated with the build script
        /// - <c>targetRoot</c> is the root target directory where all the files are generated
        /// - <c>targetDir</c> is where the project's output should be built
        /// </para>
        /// <para>
        /// A special global function <c>get_tool</c> is available which accepts a reference URI and
        /// a file name. 
        /// The same protocols are supported as for references in the suite definition. The 
        /// function's return value is the absolute path of the given file, where the tool
        /// has been deployed.
        /// </para>
        /// </summary>
        /// <param name="project">The input project to build</param>
        /// <param name="buildScript">The build script to execute</param>
        /// <returns>Returns the set of files generated by the script. They have to be
        /// indicated in the script's <c>results</c> variable, relative to <c>targetDir</c>.</returns>
        public ISet<TargetRelativePath> Run(Project project, IBuildScript buildScript)
        {
            var engine = CreateEngine();

            var runtime = engine.Runtime;
            try
            {
                var scope = runtime.CreateScope();

                scope.SetVariable("is_mono", parameters.UseMono);
                scope.SetVariable("project", project);
                scope.SetVariable("sourceSet",
                                  project.GetSourceSet(buildScript.SourceSetName)
                                         .Files.Select(srp => (string) srp)
                                         .ToList());
                AddGetToolToScope(scope, project);

                var targetDir = TargetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);
                var localTargetDir = targetDir as LocalFileSystemDirectory;
                var localTargetRoot = TargetRoot as LocalFileSystemDirectory;
                if (localTargetDir != null && localTargetRoot != null)
                {
                    scope.SetVariable("targetRoot", localTargetRoot.AbsolutePath);
                    scope.SetVariable("targetDir", localTargetDir.AbsolutePath);

                    var pco = (PythonCompilerOptions)engine.GetCompilerOptions();
                    pco.Module |= ModuleOptions.Optimized;

                    try
                    {
                        var script = engine.CreateScriptSourceFromString(buildScript.Source, SourceCodeKind.File);
                        script.Compile(pco);
                        script.Execute(scope);

                        return new HashSet<TargetRelativePath>(
                            scope.GetVariable<IList<object>>("results")
                                .Cast<string>()
                                .Select(t => GetTargetRelativePath(targetDir, t)));
                    }
                    catch (Exception ex)
                    {
                        var eo = engine.GetService<ExceptionOperations>();

                        string msg, typeName;
                        eo.GetExceptionMessage(ex, out msg, out typeName);

                        foreach (var line in msg.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            output.Error(line);
                        }

                        output.Error("Call stack:");
                        foreach (var frame in eo.GetStackFrames(ex))
                        {
                            var line = frame.GetFileLineNumber();
                            var method = frame.GetMethodName();

                            output.Error(String.Format("Line {0} in {1}", line, method));
                        }

                        throw new ScriptException(buildScript);
                    }
                }
                else
                {
                    throw new NotSupportedException("Only local file system is supported for python scripts!");
                }
            }
            finally
            {
                runtime.Shutdown();
            }
        }
예제 #26
0
 private static void InjectPropertiesFromTaskAttributes(IBuildScript buildScript, IFlubuSession flubuSession, PropertyInfo property)
 {
     InjectPropertyFromFetchBuildVersionFomFileAttribute(flubuSession, buildScript, property);
     InjectPropertyFromGitVersionAttribute(flubuSession, buildScript, property);
     InjectPropertyFromLoadSolutionAttribute(flubuSession, buildScript, property);
 }
예제 #27
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);
                    }
                }
            }
        }
예제 #28
0
 internal void AddTargets(IBuildScript buildScript)
 {
     _targetsWindow.ProjectName = buildScript.Name;
     _targetsWindow.SetTargets(buildScript.Targets, buildScript.HideTargetsWithoutDescription);
 }
예제 #29
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
        }
예제 #30
0
        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);
        }
 public PythonScriptedBuilder CreatePythnoScriptedBuilder(Project project, IBuildScript buildScript)
 {
     return store.Add(baseImpl.CreatePythnoScriptedBuilder(project, buildScript));
 }
예제 #32
0
        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);
        }
예제 #33
0
 /// <summary>
 /// Adds a new build script to the suite
 /// </summary>
 /// <param name="sourceSetName">Name of the source set for which this build script
 /// should be executed.</param>
 /// <param name="buildScript">The build script</param>
 public void Add(string sourceSetName, IBuildScript buildScript)
 {
     buildScriptsForSourceSets.Add(sourceSetName, buildScript);
 }
예제 #34
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);
            }
        }
예제 #35
0
        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);
        }
예제 #36
0
        internal void SaveAs(string filename, string contents)
        {
            Assert.NotNull(filename, "filename");
            Assert.NotNull(contents, "contents");

            FullName = filename;
            Contents = contents;

            File.WriteAllText(FullName, Contents);

            FileInfo fileInfo = new FileInfo(filename);
            Name = fileInfo.Name;
            Directory = fileInfo.DirectoryName;
            LastModified = fileInfo.LastWriteTime;
            FileType = FileType.Existing;

            BuildScript = ScriptParserFactory.Create(fileInfo, Settings.Default.HideTargetsWithoutDescription);
            _buildRunner = BuildRunnerFactory.Create(fileInfo, _logger, _options);

            ParseBuildFile();
        }