public static void ValidateRequirements(NukeBuild build) { foreach (var target in build.ExecutionPlan) { foreach (var requirement in target.Requirements) { if (requirement is Expression <Func <bool> > boolExpression) { ControlFlow.Assert(boolExpression.Compile().Invoke(), $"Target '{target.Name}' requires '{requirement.Body}'."); } else if (IsMemberNull(requirement.GetMemberInfo(), build, target)) { ControlFlow.Fail($"Target '{target.Name}' requires member '{requirement.GetMemberInfo().Name}' to be not null."); } } } var requiredMembers = InjectionUtility.GetParameterMembers(build.GetType()).Where(x => x.HasCustomAttribute <RequiredAttribute>()); foreach (var member in requiredMembers) { if (IsMemberNull(member, build)) { ControlFlow.Fail($"Member '{member.Name}' is required to be not null."); } } }
public void OnBeforeLogo( NukeBuild build, IReadOnlyCollection <ExecutableTarget> executableTargets) { var completionItems = new SortedDictionary <string, string[]>(); var targetNames = build.ExecutableTargets.Select(x => x.Name).OrderBy(x => x).ToList(); completionItems[Constants.InvokedTargetsParameterName] = targetNames.ToArray(); completionItems[Constants.SkippedTargetsParameterName] = targetNames.ToArray(); var parameters = InjectionUtility.GetParameterMembers(build.GetType(), includeUnlisted: false); foreach (var parameter in parameters) { var parameterName = ParameterService.GetParameterMemberName(parameter); if (completionItems.ContainsKey(parameterName)) { continue; } var subItems = ParameterService.GetParameterValueSet(parameter, build)?.Select(x => x.Text); completionItems[parameterName] = subItems?.ToArray(); } SerializationTasks.YamlSerializeToFile(completionItems, Constants.GetCompletionFile(NukeBuild.RootDirectory)); if (EnvironmentInfo.GetParameter <bool>(Constants.CompletionParameterName)) { Environment.Exit(exitCode: 0); } }
public static string GetParametersText(NukeBuild build) { var defaultTarget = build.ExecutableTargets.Single(x => x.IsDefault); var builder = new StringBuilder(); var parameters = InjectionUtility.GetParameterMembers(build.GetType()) .Where(x => !x.HasCustomAttribute <UnlistedAttribute>()) .OrderBy(x => x.Name).ToList(); var padRightParameter = Math.Max(parameters.Max(x => x.Name.Length), val2: 16); void PrintParameter(MemberInfo parameter) { var description = SplitLines( // TODO: remove ParameterService.Instance.GetParameterDescription(parameter) ?.Replace("{default_target}", defaultTarget.Name).Append(".") ?? "<no description>"); var parameterName = ParameterService.Instance.GetParameterName(parameter).SplitCamelHumpsWithSeparator("-"); builder.AppendLine($" --{parameterName.PadRight(padRightParameter)} {description.First()}"); foreach (var line in description.Skip(count: 1)) { builder.AppendLine($"{new string(c: ' ', count: padRightParameter + 6)}{line}"); } } builder.AppendLine("Parameters:"); var customParameters = parameters.Where(x => x.DeclaringType != typeof(NukeBuild)).ToList(); if (customParameters.Count > 0) { builder.AppendLine(); } foreach (var parameter in customParameters) { PrintParameter(parameter); } builder.AppendLine(); var inheritedParameters = parameters.Where(x => x.DeclaringType == typeof(NukeBuild)); foreach (var parameter in inheritedParameters) { PrintParameter(parameter); } return(builder.ToString()); }
public static string GetParametersText <T>(T build) where T : NukeBuild { var defaultTarget = build.TargetDefinitions.Single(x => x.IsDefault); var builder = new StringBuilder(); var parameters = InjectionUtility.GetParameterMembers(build.GetType()).OrderBy(x => x.Name).ToList(); var padRightParameter = Math.Max(parameters.Max(x => x.Name.Length), val2: 16); void PrintParameter(MemberInfo parameter) { var attribute = parameter.GetCustomAttribute <ParameterAttribute>().NotNull(); var description = SplitLines( // TODO: remove attribute.Description.Replace("{default_target}", defaultTarget.Name)); var parameterName = (attribute.Name ?? parameter.Name).SplitCamelHumpsWithSeparator("-"); builder.AppendLine($" --{parameterName.PadRight(padRightParameter)} {description.First()}"); foreach (var line in description.Skip(count: 1)) { builder.AppendLine($"{new string(c: ' ', count: padRightParameter + 6)}{line}"); } } builder.AppendLine("Parameters:"); var customParameters = parameters.Where(x => x.DeclaringType != typeof(NukeBuild)).ToList(); if (customParameters.Count > 0) { builder.AppendLine(); } foreach (var parameter in customParameters) { PrintParameter(parameter); } builder.AppendLine(); var inheritedParameters = parameters.Where(x => x.DeclaringType == typeof(NukeBuild)); foreach (var parameter in inheritedParameters) { PrintParameter(parameter); } return(builder.ToString()); }
public void Execute(NukeBuild build) { var completionItems = new SortedDictionary <string, string[]>(); var targetNames = build.ExecutableTargets.Select(x => x.Name).OrderBy(x => x).ToList(); completionItems[Constants.InvokedTargetsParameterName] = targetNames.ToArray(); completionItems[Constants.SkippedTargetsParameterName] = targetNames.ToArray(); string[] GetSubItems(Type type) { if (type.IsEnum) { return(type.GetEnumNames()); } if (type.IsSubclassOf(typeof(Enumeration))) { return(type.GetFields(ReflectionService.Static).Select(x => x.Name).ToArray()); } return(null); } foreach (var parameter in InjectionUtility.GetParameterMembers(build.GetType())) { var parameterName = ParameterService.Instance.GetParameterName(parameter); if (completionItems.ContainsKey(parameterName)) { continue; } completionItems[parameterName] = GetSubItems(parameter.GetFieldOrPropertyType())?.OrderBy(x => x).ToArray(); } SerializationTasks.YamlSerializeToFile(completionItems, Constants.GetCompletionFile(NukeBuild.RootDirectory)); if (EnvironmentInfo.ParameterSwitch(Constants.CompletionParameterName)) { Environment.Exit(exitCode: 0); } }