private void RunBuild(ITaskSession taskSession) { ConfigureDefaultProps(taskSession); ConfigureBuildProperties(taskSession); ConfigureDefaultTargets(taskSession); ScriptProperties.SetPropertiesFromScriptArg(this, taskSession); TargetCreator.CreateTargetFromMethodAttributes(this, taskSession); ConfigureTargets(taskSession); (List <string> targetsToRun, bool unknownTarget, List <string> notFoundTargets)targetsInfo = default((List <string> targetsToRun, bool unknownTarget, List <string> notFoundTargets)); bool runInTerminalMode; ConsoleHintedInput inputReader = null; if (!taskSession.Args.InteractiveMode) { runInTerminalMode = false; targetsInfo = ParseCmdLineArgs(taskSession.Args.MainCommands, taskSession.TargetTree); taskSession.UnknownTarget = targetsInfo.unknownTarget; if (targetsInfo.targetsToRun == null || targetsInfo.targetsToRun.Count == 0) { var defaultTargets = taskSession.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"); } } } else { runInTerminalMode = true; var source = new Dictionary <char, IReadOnlyCollection <string> >(); var propertyKeys = ScriptProperties.GetPropertiesKeys(this, taskSession); propertyKeys.Add("-parallel"); propertyKeys.Add("-dryrun"); propertyKeys.Add("-noColor"); source.Add('-', propertyKeys); inputReader = new ConsoleHintedInput(taskSession.TargetTree.GetTargetNames().ToList(), source); taskSession.TargetTree.RunTarget(taskSession, "help.onlyTargets"); taskSession.LogInfo(" "); } do { if (runInTerminalMode) { var commandLine = inputReader.ReadHintedLine(); 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()); targetsInfo = ParseCmdLineArgs(args.MainCommands, taskSession.TargetTree); taskSession.ScriptArgs = args.ScriptArguments; ScriptProperties.SetPropertiesFromScriptArg(this, taskSession); if (args.MainCommands[0].Equals("exit", StringComparison.OrdinalIgnoreCase) || args.MainCommands[0].Equals("quit", StringComparison.OrdinalIgnoreCase) || args.MainCommands[0].Equals("x", StringComparison.OrdinalIgnoreCase) || args.MainCommands[0].Equals("q", StringComparison.OrdinalIgnoreCase)) { break; } } taskSession.Start(); //// specific target help if (targetsInfo.targetsToRun.Count == 2 && targetsInfo.targetsToRun[1].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.RunTargetHelp(taskSession, targetsInfo.targetsToRun[0]); return; } if (targetsInfo.targetsToRun.Count == 1 || !taskSession.Args.ExecuteTargetsInParallel) { if (targetsInfo.targetsToRun[0].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.ScriptArgsHelp = ScriptProperties.GetPropertiesHelp(this); } BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { taskSession.TargetTree.RunTarget(taskSession, targetToRun); } AfterTargetExecution(taskSession); } else { taskSession.LogInfo("Running target's in parallel."); var tasks = new List <Task>(); BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { tasks.Add(taskSession.TargetTree.RunTargetAsync(taskSession, targetToRun, true)); } Task.WaitAll(tasks.ToArray()); AfterTargetExecution(taskSession); } if (targetsInfo.unknownTarget) { var targetNotFoundMsg = $"Target {string.Join(" and ", targetsInfo.notFoundTargets)} not found."; if (taskSession.Args.InteractiveMode) { taskSession.LogInfo(targetNotFoundMsg); } else { throw new TargetNotFoundException(targetNotFoundMsg); } } AssertAllTargetDependenciesWereExecuted(taskSession); }while (runInTerminalMode); }
private void RunBuild(ITaskSession taskSession) { ConfigureDefaultProps(taskSession); ConfigureBuildProperties(taskSession); ConfigureDefaultTargets(taskSession); ScriptProperties.SetPropertiesFromScriptArg(this, taskSession); TargetCreator.CreateTargetFromMethodAttributes(this, taskSession); ConfigureTargets(taskSession); var targetsInfo = ParseCmdLineArgs(taskSession, taskSession.TargetTree); if (targetsInfo.targetsToRun == null || targetsInfo.targetsToRun.Count == 0) { var defaultTargets = taskSession.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"); } } taskSession.Start(s => { foreach (var target in s.TargetTree.EnumerateExecutedTargets()) { var targt = target as Target; if (targt?.TaskStopwatch.ElapsedTicks > 0) { s.LogInfo($"Target {target.TargetName} took {(int)targt.TaskStopwatch.Elapsed.TotalSeconds} s"); } } if (taskSession.Args.DryRun) { s.LogInfo("DRY RUN PERFORMED"); } else if (!targetsInfo.unknownTarget) { s.LogInfo(s.HasFailed ? "BUILD FAILED" : "BUILD SUCCESSFUL"); } }); //// specific target help if (targetsInfo.targetsToRun.Count == 2 && targetsInfo.targetsToRun[1].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.RunTargetHelp(taskSession, targetsInfo.targetsToRun[0]); return; } if (targetsInfo.targetsToRun.Count == 1 || !taskSession.Args.ExecuteTargetsInParallel) { if (targetsInfo.targetsToRun[0].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.ScriptArgsHelp = ScriptProperties.GetPropertiesHelp(this); } BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { taskSession.TargetTree.RunTarget(taskSession, targetToRun); } AfterTargetExecution(taskSession); } else { taskSession.LogInfo("Running target's in parallel."); var tasks = new List <Task>(); BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { tasks.Add(taskSession.TargetTree.RunTargetAsync(taskSession, targetToRun)); } Task.WaitAll(tasks.ToArray()); AfterTargetExecution(taskSession); } if (targetsInfo.unknownTarget) { throw new TargetNotFoundException($"Target {string.Join(" and ", targetsInfo.notFoundTargets)} not found."); } AssertAllTargetDependenciesWereExecuted(taskSession); }
private void RunBuild(ITaskSession taskSession) { ConfigureDefaultProps(taskSession); ConfigureBuildProperties(taskSession); ConfigureDefaultTargets(taskSession); ScriptProperties.SetPropertiesFromScriptArg(this, taskSession); TargetCreator.CreateTargetFromMethodAttributes(this, taskSession); ConfigureTargets(taskSession); var targetsInfo = ParseCmdLineArgs(taskSession, taskSession.TargetTree); taskSession.UnknownTarget = targetsInfo.unknownTarget; if (targetsInfo.targetsToRun == null || targetsInfo.targetsToRun.Count == 0) { var defaultTargets = taskSession.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"); } } taskSession.Start(); //// specific target help if (targetsInfo.targetsToRun.Count == 2 && targetsInfo.targetsToRun[1].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.RunTargetHelp(taskSession, targetsInfo.targetsToRun[0]); return; } if (targetsInfo.targetsToRun.Count == 1 || !taskSession.Args.ExecuteTargetsInParallel) { if (targetsInfo.targetsToRun[0].Equals("help", StringComparison.OrdinalIgnoreCase)) { taskSession.TargetTree.ScriptArgsHelp = ScriptProperties.GetPropertiesHelp(this); } BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { taskSession.TargetTree.RunTarget(taskSession, targetToRun); } AfterTargetExecution(taskSession); } else { taskSession.LogInfo("Running target's in parallel."); var tasks = new List <Task>(); BeforeTargetExecution(taskSession); foreach (var targetToRun in targetsInfo.targetsToRun) { tasks.Add(taskSession.TargetTree.RunTargetAsync(taskSession, targetToRun)); } Task.WaitAll(tasks.ToArray()); AfterTargetExecution(taskSession); } if (targetsInfo.unknownTarget) { throw new TargetNotFoundException( $"Target {string.Join(" and ", targetsInfo.notFoundTargets)} not found."); } AssertAllTargetDependenciesWereExecuted(taskSession); }