public static IReadOnlyCollection <TargetDefinition> GetExecutingTargets(NukeBuild build, [CanBeNull] string[] invokedTargetNames = null) { ControlFlow.Assert(build.TargetDefinitions.All(x => !x.Name.EqualsOrdinalIgnoreCase(BuildExecutor.DefaultTarget)), $"The name '{BuildExecutor.DefaultTarget}' cannot be used as target name."); var invokedTargets = invokedTargetNames?.Select(x => GetDefinition(x, build)).ToList() ?? new List <TargetDefinition>(); var executingTargets = GetUnfilteredExecutingTargets(build, invokedTargets); var skippedTargets = executingTargets .Where(x => !invokedTargets.Contains(x) && build.SkippedTargets != null && (build.SkippedTargets.Length == 0 || build.SkippedTargets.Contains(x.Name, StringComparer.OrdinalIgnoreCase))).ToList(); skippedTargets.ForEach(x => x.Skip = true); executingTargets .Where(x => x.DependencyBehavior == DependencyBehavior.Skip) .Where(x => x.Conditions.Any(y => !y())) .ForEach(x => SkipTargetAndDependencies(x, invokedTargets, executingTargets)); string[] GetNames(IEnumerable <TargetDefinition> targets) => targets.Select(x => x.Name).ToArray(); ReflectionService.SetValue(build, nameof(NukeBuild.InvokedTargets), GetNames(invokedTargets)); ReflectionService.SetValue(build, nameof(NukeBuild.SkippedTargets), GetNames(skippedTargets)); ReflectionService.SetValue(build, nameof(NukeBuild.ExecutingTargets), GetNames(executingTargets.Except(skippedTargets))); return(executingTargets); }
public static void InjectValues(NukeBuild build) { var anyInjected = false; var injectionMembers = build.GetInjectionMembers() .OrderByDescending(x => x.GetCustomAttribute <ParameterAttribute>() != null); foreach (var member in injectionMembers) { if (member.DeclaringType == typeof(NukeBuild)) { continue; } var attributes = member.GetCustomAttributes().OfType <InjectionAttributeBase>().ToList(); if (attributes.Count == 0) { continue; } ControlFlow.Assert(attributes.Count == 1, $"Member '{member.Name}' has multiple injection attributes applied."); var attribute = attributes.Single(); var value = attribute.GetValue(member, build); if (value == null) { continue; } var valueType = value.GetType(); ControlFlow.Assert(member.GetFieldOrPropertyType().IsAssignableFrom(valueType), $"Member '{member.Name}' must be of type '{valueType.Name}' to get its valued injected from '{attribute.GetType().Name}'."); ReflectionService.SetValue(build, member, value); anyInjected = true; } if (anyInjected) { Logger.Log(); } }
public static IReadOnlyCollection <TargetDefinition> GetExecutingTargets(NukeBuild build) { ControlFlow.Assert(build.TargetDefinitions.All(x => !x.Name.EqualsOrdinalIgnoreCase(BuildExecutor.DefaultTarget)), "The name 'default' cannot be used as target name."); var invokedTargets = build.InvokedTargets.Select(x => GetDefinition(x, build)).ToList(); var executingTargets = GetUnfilteredExecutingTargets(build, invokedTargets); var skippedTargets = executingTargets .Where(x => !invokedTargets.Contains(x) && build.SkippedTargets != null && (build.SkippedTargets.Length == 0 || build.SkippedTargets.Contains(x.Name, StringComparer.OrdinalIgnoreCase))).ToList(); skippedTargets.ForEach(x => x.Conditions.Add(() => false)); string[] GetNames(IEnumerable <TargetDefinition> targets) => targets.Select(x => x.Name).ToArray(); ReflectionService.SetValue(build, nameof(NukeBuild.InvokedTargets), GetNames(invokedTargets)); ReflectionService.SetValue(build, nameof(NukeBuild.SkippedTargets), GetNames(skippedTargets)); ReflectionService.SetValue(build, nameof(NukeBuild.ExecutingTargets), GetNames(executingTargets.Except(skippedTargets))); return(executingTargets); }