From 04cd109a95b27411ab497b3662a825d61a78f79f Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Tue, 12 Nov 2024 22:33:41 +0100 Subject: [PATCH] wip --- build/Build.PublicApi.cs | 2 +- .../Nuke.Build/Attributes/VerbosityMappingAttribute.cs | 6 +++--- source/Nuke.Build/Execution/BuildManager.cs | 2 +- source/Nuke.Tooling/Configure.cs | 4 ++-- source/Nuke.Tooling/Options.cs | 9 +++++++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/build/Build.PublicApi.cs b/build/Build.PublicApi.cs index dc1e62dee..7bbe05840 100644 --- a/build/Build.PublicApi.cs +++ b/build/Build.PublicApi.cs @@ -69,7 +69,7 @@ bool DefaultFilter(MemberInfo member) if (!(member.IsPublic() || member.IsFamily() && !member.DeclaringType.NotNull().IsSealed)) return false; - if (member is FieldInfo field && field.IsSpecialName) + if (member is FieldInfo { IsSpecialName: true }) return false; return true; diff --git a/source/Nuke.Build/Attributes/VerbosityMappingAttribute.cs b/source/Nuke.Build/Attributes/VerbosityMappingAttribute.cs index f363d3de3..d8c77e1de 100644 --- a/source/Nuke.Build/Attributes/VerbosityMappingAttribute.cs +++ b/source/Nuke.Build/Attributes/VerbosityMappingAttribute.cs @@ -51,9 +51,9 @@ internal static class VerbosityMapping { public static readonly LookupTable Mappings = new(); - public static void Apply(object obj) + public static void Apply(ToolOptions options) { - foreach (var property in obj.GetType().GetProperties()) + foreach (var property in options.GetType().GetProperties()) { if (!Mappings.Contains(property.PropertyType)) continue; @@ -62,7 +62,7 @@ public static void Apply(object obj) foreach (var (verbosity, mappedVerbosity) in mappings) { if (verbosity == NukeBuild.Verbosity) - property.SetValue(obj, mappedVerbosity); + options.Set(property.Name, mappedVerbosity); } } } diff --git a/source/Nuke.Build/Execution/BuildManager.cs b/source/Nuke.Build/Execution/BuildManager.cs index f0a68a9fe..5ec1d2713 100644 --- a/source/Nuke.Build/Execution/BuildManager.cs +++ b/source/Nuke.Build/Execution/BuildManager.cs @@ -43,7 +43,7 @@ public static int Execute(Expression>[] defaultTargetExpressi Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; Console.CancelKeyPress += (_, _) => s_cancellationHandlers.ForEach(x => x()); - ToolOptions.Created += (settings, _) => VerbosityMapping.Apply(settings); + ToolOptions.Created += (options, _) => VerbosityMapping.Apply((ToolOptions)options); var build = new T(); diff --git a/source/Nuke.Tooling/Configure.cs b/source/Nuke.Tooling/Configure.cs index 45e61532b..7cd16ad77 100644 --- a/source/Nuke.Tooling/Configure.cs +++ b/source/Nuke.Tooling/Configure.cs @@ -76,11 +76,11 @@ private static IReadOnlyCollection Invoke( try { var result = executor(x.DisableProcessOutputLogging()); - invocations.Add((x, x.ProcessLogger, result, default)); + invocations.Add((x, x.GetLogger(), result, default)); } catch (Exception exception) { - invocations.Add((x, x.ProcessLogger, default, exception)); + invocations.Add((x, x.GetLogger(), default, exception)); if (!completeOnFailure) throw; diff --git a/source/Nuke.Tooling/Options.cs b/source/Nuke.Tooling/Options.cs index 90eb363c8..a74f1838e 100644 --- a/source/Nuke.Tooling/Options.cs +++ b/source/Nuke.Tooling/Options.cs @@ -58,15 +58,20 @@ private static string GetOptionName(LambdaExpression lambdaExpression) } internal Options Set(Expression> propertyProvider, object value) + { + return Set(GetOptionName(propertyProvider), value); + } + + internal Options Set(string propertyName, object value) { if (value != null) { var internalOption = JValue.FromObject(value, JsonSerializer); - InternalOptions[GetOptionName(propertyProvider)] = internalOption; + InternalOptions[propertyName] = internalOption; } else { - Remove(propertyProvider); + InternalOptions.Property(propertyName)?.Remove(); } return this;