public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { try { var executionList = Setup(defaultTargetExpression); return(new ExecutionListRunner().Run(executionList)); } catch (AggregateException exception) { foreach (var innerException in exception.Flatten().InnerExceptions) { OutputSink.Error(innerException.Message, innerException.StackTrace); } return(-exception.Message.GetHashCode()); } catch (TargetInvocationException exception) { var innerException = exception.InnerException.NotNull(); OutputSink.Error(innerException.Message, innerException.StackTrace); return(-exception.Message.GetHashCode()); } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); return(-exception.Message.GetHashCode()); } }
public static int Execute <T> (Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { try { var executionList = Setup(defaultTargetExpression); return(new ExecutionListRunner().Run(executionList)); } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); return(-exception.Message.GetHashCode()); } }
public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { Logger.Log(FigletTransform.GetText("NUKE")); Logger.Log($"Version: {typeof(BuildExecutor).GetTypeInfo().Assembly.GetVersionText()}"); Logger.Log($"Host: {EnvironmentInfo.HostType}"); Logger.Log(); var executionList = default(IReadOnlyCollection <TargetDefinition>); try { var build = CreateBuildInstance(defaultTargetExpression); InjectionService.InjectValues(build); HandleEarlyExits(build); executionList = TargetDefinitionLoader.GetExecutingTargets(build); RequirementService.ValidateRequirements(executionList, build); Execute(executionList); return(0); } catch (AggregateException exception) { foreach (var innerException in exception.Flatten().InnerExceptions) { OutputSink.Error(innerException.Message, innerException.StackTrace); } return(-exception.Message.GetHashCode()); } catch (TargetInvocationException exception) { var innerException = exception.InnerException.NotNull(); OutputSink.Error(innerException.Message, innerException.StackTrace); return(-exception.Message.GetHashCode()); } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); return(-exception.Message.GetHashCode()); } finally { if (executionList != null) { OutputSink.WriteSummary(executionList); } } }
public int Run(IReadOnlyCollection <TargetDefinition> executionList) { foreach (var target in executionList) { if (target.Factory == null) { target.Status = ExecutionStatus.Absent; continue; } if (target.Conditions.Any(x => !x())) { target.Status = ExecutionStatus.Skipped; continue; } using (Logger.Block(target.Name)) { var stopwatch = Stopwatch.StartNew(); try { target.Actions.ForEach(x => x()); target.Duration = stopwatch.Elapsed; target.Status = ExecutionStatus.Executed; } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); target.Status = ExecutionStatus.Failed; break; } finally { target.Duration = stopwatch.Elapsed; } } } OutputSink.WriteSummary(executionList); return(-executionList.Count(x => x.Status == ExecutionStatus.Failed)); }
/// <summary> /// Logs a message as error. /// </summary> public static void Error(string text = null) { OutputSink.Error(text ?? string.Empty); }