From 35d5a678fcf08330891b08cf5e89553044144e27 Mon Sep 17 00:00:00 2001 From: sawilde Date: Sat, 6 Feb 2016 07:39:44 +1100 Subject: [PATCH 1/5] refactor filter error reporting --- main/OpenCover.Framework/Filter.cs | 39 ++++++++++++++----- .../Filtering/FilterHelper.cs | 28 +------------ 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/main/OpenCover.Framework/Filter.cs b/main/OpenCover.Framework/Filter.cs index 1773b917b..895705c9c 100644 --- a/main/OpenCover.Framework/Filter.cs +++ b/main/OpenCover.Framework/Filter.cs @@ -5,7 +5,6 @@ // using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; @@ -137,9 +136,9 @@ public void AddFilter(string processAssemblyClassFilter) { if (!RegExFilters) { - processFilter = (string.IsNullOrEmpty(processFilter) ? "*" : processFilter).ValidateAndEscape("<>|\""); // Path.GetInvalidPathChars except *? - assemblyFilter = assemblyFilter.ValidateAndEscape(); - classFilter = classFilter.ValidateAndEscape(); + processFilter = ValidateAndEscape((string.IsNullOrEmpty(processFilter) ? "*" : processFilter), "<>|\"", "process"); // Path.GetInvalidPathChars except *? + assemblyFilter = ValidateAndEscape(assemblyFilter, @"\[]", "assembly"); + classFilter = ValidateAndEscape(classFilter, @"\[]", "class/type"); } var filter = new AssemblyAndClassFilter(processFilter, assemblyFilter, classFilter); @@ -182,9 +181,9 @@ private static void GetAssemblyClassName(string processAssemblyClassFilter, bool } } - private static void HandleInvalidFilterFormat(string assemblyClassName) + private static void HandleInvalidFilterFormat(string filter) { - Logger.ErrorFormat("Unable to process the filter '{0}'. Please check your syntax against the usage guide and try again.", assemblyClassName); + Logger.ErrorFormat("Unable to process the filter '{0}'. Please check your syntax against the usage guide and try again.", filter); Logger.ErrorFormat("The usage guide can also be found at https://github.com/OpenCover/opencover/wiki/Usage."); throw new ExitApplicationWithoutReportingException(); } @@ -195,7 +194,7 @@ private static void HandleInvalidFilterFormat(string assemblyClassName) /// An array of filters that are used to wildcard match an attribute public void AddAttributeExclusionFilters(string[] exclusionFilters) { - ExcludedAttributes.AddFilters(exclusionFilters, RegExFilters); + AddFilters(ExcludedAttributes, exclusionFilters, RegExFilters, "attribute"); } /// @@ -305,7 +304,7 @@ public bool ExcludeByFile(string fileName) /// public void AddFileExclusionFilters(string[] exclusionFilters) { - ExcludedFiles.AddFilters(exclusionFilters, RegExFilters); + AddFilters(ExcludedFiles, exclusionFilters, RegExFilters, "file exclusion"); } /// @@ -327,7 +326,7 @@ public bool UseTestAssembly(string assemblyName) /// public void AddTestFileFilters(string[] testFilters) { - TestFiles.AddFilters(testFilters, RegExFilters); + AddFilters(TestFiles, testFilters, RegExFilters, "test assembly"); } /// @@ -446,5 +445,27 @@ public static IFilter BuildFilter(CommandLineParser parser) return filter; } + + static void AddFilters(ICollection target, IEnumerable filters, bool isRegexFilter, string filterType) + { + if (filters == null) + return; + + foreach (var regexFilter in filters.Where(x => x != null).Select(filter => isRegexFilter ? new RegexFilter(filter, false) : new RegexFilter(ValidateAndEscape(filter, @"[]", filterType)))) + { + target.Add(regexFilter); + } + } + + static string ValidateAndEscape(string match, string notAllowed, string filterType) + { + if (match.IndexOfAny(notAllowed.ToCharArray()) >= 0) + { + Logger.ErrorFormat("The string '{0}' is invalid for a{2} '{1}' filter name", + match, filterType, "aeiou".Contains(filterType[0]) ? "n" : ""); + HandleInvalidFilterFormat(match); + } + return match.Replace(@"\", @"\\").Replace(@".", @"\.").Replace(@"*", @".*"); + } } } diff --git a/main/OpenCover.Framework/Filtering/FilterHelper.cs b/main/OpenCover.Framework/Filtering/FilterHelper.cs index a30dae4fa..6dc649295 100644 --- a/main/OpenCover.Framework/Filtering/FilterHelper.cs +++ b/main/OpenCover.Framework/Filtering/FilterHelper.cs @@ -11,13 +11,6 @@ internal static string WrapWithAnchors(this string data) return String.Format("^({0})$", data); } - internal static string ValidateAndEscape(this string match, string notAllowed = @"\[]") - { - if (match.IndexOfAny(notAllowed.ToCharArray()) >= 0) - throw new InvalidOperationException(String.Format("The string is invalid for an filter name {0}", match)); - return match.Replace(@"\", @"\\").Replace(@".", @"\.").Replace(@"*", @".*"); - } - internal static IList GetMatchingFiltersForAssemblyName(this IEnumerable filters, string assemblyName) { var matchingFilters = filters @@ -41,25 +34,6 @@ internal static void AddRange (this ICollection collection, IEnumerable } } - internal static void AddFilters(this ICollection target, IEnumerable filters, bool isRegexFilter) - { - if (filters == null) - return; - - foreach (var filter in filters.Where(x => x != null)) - { - RegexFilter regexFilter; - if (isRegexFilter) - { - regexFilter = new RegexFilter(filter, false); - } - else - { - regexFilter = new RegexFilter(filter.ValidateAndEscape(@"[]")); - } - - target.Add(regexFilter); - } - } + } } From 3437be64f9fa361151a83bcefdf9808019c638d6 Mon Sep 17 00:00:00 2001 From: sawilde Date: Thu, 11 Feb 2016 08:16:47 +1100 Subject: [PATCH 2/5] have a debug and release (via CI) drdump tokens --- appveyor.yml | 2 ++ default.build | 16 ++++++++++++++-- main/OpenCover.Console/Program.cs | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 81534853f..7c81f77c5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,8 @@ environment: secure: +9YfPnwJzGsvdyto85pHwg== SONARQUBE_PASSWORD: secure: Ptvd9aDNKfVhXvPpq6o1Fw== + DRDUMP_TOKEN: + secure: 16PEs46poxfT7drt6BdHSHPPzAymXBYrIaqoAsHvY49os5Azz4rNTp3QaUhtITZ+ cache: - build/Version/opencover.snk - build/Version/opencover.public.snk diff --git a/default.build b/default.build index 431360c25..30f5fc2e5 100644 --- a/default.build +++ b/default.build @@ -33,7 +33,7 @@ - + @@ -61,7 +61,7 @@ tofile="${solution.folder}/bin/zip/opencover.${buildnumber.major}.${buildnumber.minor}.${buildnumber.build}.zip" /> - + @@ -154,6 +154,18 @@ + + + + + + + + + + + + diff --git a/main/OpenCover.Console/Program.cs b/main/OpenCover.Console/Program.cs index f6965af0e..5e254ed40 100644 --- a/main/OpenCover.Console/Program.cs +++ b/main/OpenCover.Console/Program.cs @@ -40,7 +40,7 @@ static int Main(string[] args) { var returnCode = 0; var returnCodeOffset = 0; - + AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; try @@ -121,7 +121,7 @@ private static void ReportCrash(Exception exception) { AnonymousData = new AnonymousData { - ApplicationGuid = new Guid("e6542474-21df-42f4-826b-15a12764da6f"), + ApplicationGuid = new Guid("dbbb1d35-be49-45e2-b81d-84f1042c455d"), Exception = exception, ToEmail = "" } From ac7cd0be204c48f445882b2db54307be64be159d Mon Sep 17 00:00:00 2001 From: sawilde Date: Sat, 13 Feb 2016 10:09:19 +1100 Subject: [PATCH 3/5] use templates to generate assembly copyright - years --- build/Version/AssemblyCopyright.cs | 3 +++ build/Version/AssemblyCopyright.tt | 6 ++++++ build/Version/GlobalAssemblyInfo.cs | 2 +- main/OpenCover.Console/OpenCover.Console.csproj | 15 ++++++++++++++- .../OpenCover.Extensions.csproj | 16 ++++++++++++++++ .../OpenCover.Framework.csproj | 14 ++++++++++++++ 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 build/Version/AssemblyCopyright.cs create mode 100644 build/Version/AssemblyCopyright.tt diff --git a/build/Version/AssemblyCopyright.cs b/build/Version/AssemblyCopyright.cs new file mode 100644 index 000000000..eed86a078 --- /dev/null +++ b/build/Version/AssemblyCopyright.cs @@ -0,0 +1,3 @@ +using System.Reflection; + +[assembly: AssemblyCopyright("Copyright © OpenCover 2011, 2012, 2013, 2014, 2015, 2016")] \ No newline at end of file diff --git a/build/Version/AssemblyCopyright.tt b/build/Version/AssemblyCopyright.tt new file mode 100644 index 000000000..b9292d613 --- /dev/null +++ b/build/Version/AssemblyCopyright.tt @@ -0,0 +1,6 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +using System.Reflection; + +[assembly: AssemblyCopyright("Copyright © OpenCover <#= string.Join(", ", Enumerable.Range(2011, (DateTime.UtcNow.Year - 2011) + 1).Select(y => y.ToString())) #>")] \ No newline at end of file diff --git a/build/Version/GlobalAssemblyInfo.cs b/build/Version/GlobalAssemblyInfo.cs index b0c2226ab..0b9a37cf5 100644 --- a/build/Version/GlobalAssemblyInfo.cs +++ b/build/Version/GlobalAssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyCompany("OpenCover")] -[assembly: AssemblyCopyright("Copyright © OpenCover 2011-2099")] [assembly: AssemblyTrademark("")] + diff --git a/main/OpenCover.Console/OpenCover.Console.csproj b/main/OpenCover.Console/OpenCover.Console.csproj index 68291f2b5..67d80425c 100644 --- a/main/OpenCover.Console/OpenCover.Console.csproj +++ b/main/OpenCover.Console/OpenCover.Console.csproj @@ -97,6 +97,12 @@ + + Properties\AssemblyCopyright.cs + True + True + AssemblyCopyright.tt + Properties\GlobalAssemblyInfo.cs @@ -110,6 +116,11 @@ + + Properties\AssemblyCopyright.tt + TextTemplatingFileGenerator + AssemblyCopyright.cs + log4net.config Always @@ -150,7 +161,9 @@ Icon.ico - + + +