Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions main/OpenCover.Framework/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ public Filter(bool useRegexFilters = false)
/// <summary>
/// Decides whether an assembly should be included in the instrumentation
/// </summary>
/// <param name="processName">The name of the process being profiled</param>
/// <param name="processPath">The path-name of the process being profiled</param>
/// <param name="assemblyName">the name of the assembly under profile</param>
/// <remarks>All assemblies matching either the inclusion or exclusion filter should be included
/// as it is the class that is being filtered within these unless the class filter is *</remarks>
public bool UseAssembly(string processName, string assemblyName)
public bool UseAssembly(string processPath, string assemblyName)
{
processName = Path.GetFileNameWithoutExtension(processName);
var processName = string.Empty;
if (processPath.IndexOfAny(Path.GetInvalidPathChars()) < 0) { // avoids ArgumentException
processName = Path.GetFileNameWithoutExtension(processPath);
}
var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);
if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*" && exclusionFilter.IsMatchingProcessName(processName)))
if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*" && ((!string.IsNullOrEmpty(processName) && exclusionFilter.IsMatchingProcessName(processName)) || exclusionFilter.IsMatchingProcessName(processPath))))
{
return false;
}
Expand All @@ -82,20 +85,23 @@ public bool UseAssembly(string processName, string assemblyName)
/// <summary>
/// Determine if an [assemblyname]classname pair matches the current Exclusion or Inclusion filters
/// </summary>
/// <param name="processName">The name of the process</param>
/// <param name="processPath">The path-name of the process</param>
/// <param name="assemblyName">the name of the assembly under profile</param>
/// <param name="className">the name of the class under profile</param>
/// <returns>false - if pair matches the exclusion filter or matches no filters, true - if pair matches in the inclusion filter</returns>
public bool InstrumentClass(string processName, string assemblyName, string className)
public bool InstrumentClass(string processPath, string assemblyName, string className)
{
if (string.IsNullOrEmpty(processName) || string.IsNullOrEmpty(assemblyName) || string.IsNullOrEmpty(className))
if (string.IsNullOrEmpty(processPath) || string.IsNullOrEmpty(assemblyName) || string.IsNullOrEmpty(className))
{
return false;
}

processName = Path.GetFileNameWithoutExtension(processName);
var processName = string.Empty;
if (processPath.IndexOfAny(Path.GetInvalidPathChars()) < 0) { // avoids ArgumentException
processName = Path.GetFileNameWithoutExtension(processPath);
}
var matchingExclusionFilters = ExclusionFilters.GetMatchingFiltersForAssemblyName(assemblyName);
if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*" && exclusionFilter.IsMatchingProcessName(processName)))
if (matchingExclusionFilters.Any(exclusionFilter => exclusionFilter.ClassName == ".*" && ((!string.IsNullOrEmpty(processName) && exclusionFilter.IsMatchingProcessName(processName)) || exclusionFilter.IsMatchingProcessName(processPath))))
{
return false;
}
Expand Down