diff --git a/build/Directory.Packages.props b/build/Directory.Packages.props index 237cde56d9..c4744e792c 100644 --- a/build/Directory.Packages.props +++ b/build/Directory.Packages.props @@ -1,19 +1,18 @@  - - true - - - - - - - - - - - - - - - - + + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/build/Tasks/Test/UnitTest.cs b/build/build/Tasks/Test/UnitTest.cs index f1717fcbf1..f8ba3975ec 100644 --- a/build/build/Tasks/Test/UnitTest.cs +++ b/build/build/Tasks/Test/UnitTest.cs @@ -3,7 +3,6 @@ using Cake.Coverlet; using Cake.Incubator.LoggingExtensions; using Common.Utilities; -using CoverletSettings = Common.Addins.Cake.Coverlet.CoverletSettings; namespace Build.Tasks; diff --git a/build/build/build.csproj b/build/build/build.csproj index e524c14b31..7f35470aa1 100644 --- a/build/build/build.csproj +++ b/build/build/build.csproj @@ -7,7 +7,7 @@ - + diff --git a/build/common/Addins/Cake.Coverlet/ArgumentsProcessor.cs b/build/common/Addins/Cake.Coverlet/ArgumentsProcessor.cs deleted file mode 100644 index 75bf79ebdc..0000000000 --- a/build/common/Addins/Cake.Coverlet/ArgumentsProcessor.cs +++ /dev/null @@ -1,157 +0,0 @@ -using Cake.Coverlet; - -namespace Common.Addins.Cake.Coverlet; - -internal static class ArgumentsProcessor -{ - public static ProcessArgumentBuilder ProcessMsBuildArguments( - CoverletSettings settings, - ICakeEnvironment cakeEnvironment, - ProcessArgumentBuilder builder, - FilePath project) - { - builder.AppendMsBuildProperty(nameof(CoverletSettings.CollectCoverage), settings.CollectCoverage.ToString()); - builder.AppendPropertyList(nameof(CoverletSettings.CoverletOutputFormat), SplitFlagEnum(settings.CoverletOutputFormat)); - - if (settings.Threshold.HasValue) - { - if (settings.Threshold > 100) - { - throw new Exception("Threshold Percentage cannot be set as greater than 100%"); - } - - builder.AppendMsBuildProperty(nameof(CoverletSettings.Threshold), settings.Threshold.ToString()!); - - if (settings.ThresholdType != ThresholdType.NotSet) - { - builder.AppendPropertyList(nameof(CoverletSettings.ThresholdType), SplitFlagEnum(settings.ThresholdType)); - } - } - - if (settings.CoverletOutputDirectory != null && string.IsNullOrEmpty(settings.CoverletOutputName)) - { - var directoryPath = settings.CoverletOutputDirectory - .MakeAbsolute(cakeEnvironment).FullPath; - - builder.AppendMsBuildPropertyQuoted("CoverletOutput", directoryPath); - } - else if (!string.IsNullOrEmpty(settings.CoverletOutputName)) - { - var dir = settings.CoverletOutputDirectory ?? project.GetDirectory(); - var directoryPath = dir.MakeAbsolute(cakeEnvironment).FullPath; - - var filepath = FilePath.FromString(settings.OutputTransformer(settings.CoverletOutputName, directoryPath)); - - builder.AppendMsBuildPropertyQuoted("CoverletOutput", filepath.MakeAbsolute(cakeEnvironment).FullPath); - } - - if (settings.ExcludeByFile.Count > 0) - { - builder.AppendPropertyList(nameof(CoverletSettings.ExcludeByFile), settings.ExcludeByFile); - } - - - if (settings.Include.Count > 0) - { - builder.AppendPropertyList(nameof(CoverletSettings.Include), settings.Include); - } - - - if (settings.Exclude.Count > 0) - { - builder.AppendPropertyList(nameof(CoverletSettings.Exclude), settings.Exclude); - } - - if (settings.ExcludeByAttribute.Count > 0) - { - builder.AppendPropertyList(nameof(CoverletSettings.ExcludeByAttribute), settings.ExcludeByAttribute); - } - - if (settings.MergeWithFile != null && settings.MergeWithFile.GetExtension() == ".json") - { - builder.AppendMsBuildPropertyQuoted("MergeWith", settings.MergeWithFile.MakeAbsolute(cakeEnvironment).FullPath); - } - - if (settings.IncludeTestAssembly.HasValue) - { - builder.AppendMsBuildProperty(nameof(CoverletSettings.IncludeTestAssembly), settings.IncludeTestAssembly.Value ? bool.TrueString : bool.FalseString); - } - - return builder; - } - - public static ProcessArgumentBuilder ProcessToolArguments( - CoverletSettings settings, - ICakeEnvironment cakeEnvironment, - ProcessArgumentBuilder builder, - FilePath project) - { - builder.AppendSwitch("--format", SplitFlagEnum(settings.CoverletOutputFormat)); - - if (settings.Threshold.HasValue) - { - if (settings.Threshold > 100) - { - throw new Exception("Threshold Percentage cannot be set as greater than 100%"); - } - - builder.AppendSwitch(nameof(CoverletSettings.Threshold), settings.Threshold.ToString()); - - if (settings.ThresholdType != ThresholdType.NotSet) - { - builder.AppendSwitchQuoted("--threshold-type", SplitFlagEnum(settings.ThresholdType)); - } - } - - if (settings.CoverletOutputDirectory != null && string.IsNullOrEmpty(settings.CoverletOutputName)) - { - var directoryPath = settings.CoverletOutputDirectory - .MakeAbsolute(cakeEnvironment).FullPath; - - builder.AppendSwitchQuoted("--output", directoryPath); - } - else if (!string.IsNullOrEmpty(settings.CoverletOutputName)) - { - var dir = settings.CoverletOutputDirectory ?? project.GetDirectory(); - var directoryPath = dir.MakeAbsolute(cakeEnvironment).FullPath; - - var filepath = FilePath.FromString(settings.OutputTransformer(settings.CoverletOutputName, directoryPath)); - - builder.AppendSwitchQuoted("--output", filepath.MakeAbsolute(cakeEnvironment).FullPath); - } - - if (settings.ExcludeByFile.Count > 0) - { - builder.AppendSwitchQuoted("--exclude-by-file", settings.ExcludeByFile); - } - - if (settings.ExcludeByAttribute.Count > 0) - { - builder.AppendSwitchQuoted("--exclude-by-attribute", settings.ExcludeByAttribute); - } - - if (settings.Exclude.Count > 0) - { - builder.AppendSwitchQuoted("--exclude", settings.Exclude); - } - - if (settings.Include.Count > 0) - { - builder.AppendSwitchQuoted("--include", settings.Include); - } - - if (settings.MergeWithFile != null && settings.MergeWithFile.GetExtension() == ".json") - { - builder.AppendSwitchQuoted("--merge-with", settings.MergeWithFile.MakeAbsolute(cakeEnvironment).FullPath); - } - - if (settings.IncludeTestAssembly.HasValue) - { - builder.AppendSwitch("--include-test-assembly", settings.IncludeTestAssembly.Value ? bool.TrueString : bool.FalseString); - } - - return builder; - } - - private static IEnumerable SplitFlagEnum(Enum @enum) => @enum.ToString("g").Split(',').Select(s => s.ToLowerInvariant()); -} diff --git a/build/common/Addins/Cake.Coverlet/BuilderExtension.cs b/build/common/Addins/Cake.Coverlet/BuilderExtension.cs deleted file mode 100644 index b19425b49f..0000000000 --- a/build/common/Addins/Cake.Coverlet/BuilderExtension.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace Common.Addins.Cake.Coverlet; - -internal static class BuilderExtension -{ - internal static ProcessArgumentBuilder AppendMsBuildProperty(this ProcessArgumentBuilder builder, string propertyName, string value) - { - builder.AppendSwitch($"/property:{propertyName}", "=", value); - return builder; - } - - internal static ProcessArgumentBuilder AppendMsBuildPropertyQuoted(this ProcessArgumentBuilder builder, string propertyName, string value) - { - builder.AppendSwitchQuoted($"/property:{propertyName}", "=", value); - return builder; - } - - internal static ProcessArgumentBuilder AppendPropertyList(this ProcessArgumentBuilder builder, string propertyName, IEnumerable values) - { - builder.Append($"/property:{propertyName}=\\\"{string.Join(",", values.Select(s => s.Trim()))}\\\""); - return builder; - } - - internal static ProcessArgumentBuilder AppendSwitchQuoted(this ProcessArgumentBuilder builder, string @switch, IEnumerable values) - { - foreach (var type in values.Select(s => s.Trim())) - { - builder.AppendSwitchQuoted(@switch, type); - } - return builder; - } - - internal static ProcessArgumentBuilder AppendSwitch(this ProcessArgumentBuilder builder, string @switch, IEnumerable values) - { - foreach (var type in values.Select(s => s.Trim())) - { - builder.AppendSwitch(@switch, type); - } - return builder; - } -} diff --git a/build/common/Addins/Cake.Coverlet/CoverletSettings.cs b/build/common/Addins/Cake.Coverlet/CoverletSettings.cs deleted file mode 100644 index 4151855728..0000000000 --- a/build/common/Addins/Cake.Coverlet/CoverletSettings.cs +++ /dev/null @@ -1,207 +0,0 @@ -#nullable disable -using Cake.Coverlet; - -namespace Common.Addins.Cake.Coverlet; - -/// -/// A delegate representing the output transformation -/// -/// The file name -/// The directory path -/// The path and name of the file (without extension) -public delegate string OutputTransformer(string fileName, string directoryPath); - -/// -/// Settings used by Cake.Coverlet -/// -public class CoverletSettings : DotNetSettings -{ - /// - /// Gets or sets if coverage should be collected - /// - public bool CollectCoverage { get; set; } - - /// - /// Gets or sets the output format for Coverlet - /// - public CoverletOutputFormat CoverletOutputFormat { get; set; } = CoverletOutputFormat.json; - - /// - /// Gets or sets the threshold for Coverlet to use in percent - /// - public uint? Threshold { get; set; } - - /// - /// Gets or sets the type of threshold to apply. - /// - /// - /// This has no effect if Threshold is not set to a value - /// - public ThresholdType ThresholdType { get; set; } - - /// - /// Gets or sets the output directory the output files - /// - public DirectoryPath CoverletOutputDirectory { get; set; } - - /// - /// Gets or sets the name of the output file excluding format - /// - public string CoverletOutputName { get; set; } - - /// - /// Gets or sets the list of files to exclude - /// - public List ExcludeByFile { get; set; } = new(); - - /// - /// Gets or sets the list of files to exclude - /// - public List ExcludeByAttribute { get; set; } = new(); - - /// - /// Gets or sets the exclusion filters - /// - public List Exclude { get; set; } = new(); - - /// - /// Gets or sets a inclusion filters - /// - public List Include { get; set; } = new(); - - /// - /// Gets or sets if the test assembly should be included - /// - public bool? IncludeTestAssembly { get; set; } - - /// - /// Gets or sets the file to merge the results of the run with - /// - public FilePath MergeWithFile { get; set; } - - /// - /// Gets or sets a transformation function taking the and - /// returning the new file name without an extension - /// - public OutputTransformer OutputTransformer { get; set; } - = (fileName, dir) => $@"{dir}\{fileName}"; - - /// - /// Adds a filter to the list of exclusions - /// - /// The filter to add - /// - public CoverletSettings WithFilter(string filter) - { - Exclude.Add(filter); - return this; - } - - /// - /// Adds a file to the list of files to exclude - /// - /// The file to exclude - /// - public CoverletSettings WithFileExclusion(string file) - { - ExcludeByFile.Add(file); - return this; - } - - /// - /// Adds a attribute to the list of attribute to exclude - /// - /// The attribute to exclude - /// - public CoverletSettings WithAttributeExclusion(string attribute) - { - ExcludeByAttribute.Add(attribute); - return this; - } - - /// - /// Adds a filter to the list of inclusions - /// - /// The filter to add - /// - public CoverletSettings WithInclusion(string file) - { - Include.Add(file); - return this; - } - - /// - /// Add a type of threshold to combine with the existing - /// - /// The type of threshold to add - /// - public CoverletSettings WithThresholdType(ThresholdType type) - { - ThresholdType |= type; - return this; - } - - /// - /// Add a type of format to combine with the existing output formats - /// - /// The format type to add - /// - public CoverletSettings WithFormat(CoverletOutputFormat format) - { - CoverletOutputFormat |= format; - return this; - } - - /// - /// Add a default transformer appending the current date time at the time of calling test - /// - /// - public CoverletSettings WithDateTimeTransformer() - { - OutputTransformer = (fileName, directory) => $@"{directory}\{fileName}-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"; - return this; - } - - /// - /// Sets the output format to be a specific value - /// - /// - /// - public CoverletSettings SetFormat(CoverletOutputFormat format) - { - CoverletOutputFormat = format; - return this; - } - - /// - /// Sets the output format to be a specific value - /// - /// - /// - public CoverletSettings WithIncludeTestAssembly(bool includeTestAssembly) - { - IncludeTestAssembly = includeTestAssembly; - return this; - } - - /// - /// Clones the coverlet settings to a new instance - /// - /// - public CoverletSettings Clone() => new() - { - CollectCoverage = CollectCoverage, - CoverletOutputFormat = CoverletOutputFormat, - Threshold = Threshold, - ThresholdType = ThresholdType, - CoverletOutputDirectory = CoverletOutputDirectory == null ? null : DirectoryPath.FromString(CoverletOutputDirectory.FullPath), - CoverletOutputName = CoverletOutputName, - Include = new List(Include), - ExcludeByFile = new List(ExcludeByFile), - ExcludeByAttribute = new List(ExcludeByAttribute), - Exclude = new List(Exclude), - IncludeTestAssembly = IncludeTestAssembly, - MergeWithFile = MergeWithFile == null ? null : FilePath.FromString(MergeWithFile.FullPath), - OutputTransformer = OutputTransformer - }; -} diff --git a/build/common/Utilities/ContextExtensions.cs b/build/common/Utilities/ContextExtensions.cs index 036e6e1e47..0f1157cadd 100644 --- a/build/common/Utilities/ContextExtensions.cs +++ b/build/common/Utilities/ContextExtensions.cs @@ -1,32 +1,9 @@ -using Cake.Common.Tools.DotNet.Test; -using Common.Addins.Cake.Coverlet; using Xunit; -using CoverletSettings = Common.Addins.Cake.Coverlet.CoverletSettings; namespace Common.Utilities; public static class ContextExtensions { - public static void DotNetTest( - this ICakeContext context, - FilePath project, - DotNetTestSettings settings, - CoverletSettings coverletSettings) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - var currentCustomization = settings.ArgumentCustomization; - settings.ArgumentCustomization = (args) => ArgumentsProcessor.ProcessMsBuildArguments( - coverletSettings, - context.Environment, - currentCustomization?.Invoke(args) ?? args, - project); - - context.DotNetTest(project.FullPath, settings); - } - public static IEnumerable ExecuteCommand(this ICakeContext context, FilePath exe, string? args, DirectoryPath? workDir = null) { var processSettings = new ProcessSettings { Arguments = args, RedirectStandardOutput = true }; diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index e61dea3688..b4c73fd3b7 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -21,7 +21,7 @@ - +