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); }
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); }
public void BeforeFileCopy(string sourceFilePath) { if (_replacementTokens.Any()) { _flubuSession.Tasks().ReplaceTokensTask(sourceFilePath) .Replace(_replacementTokens.ToArray()) .DoNotLogTaskExecutionInfo() .NoLog() .Execute(_flubuSession); } }
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); }
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); }