Skip to content

Commit

Permalink
#704 Improved handling of file filters (unified behavior for all repo…
Browse files Browse the repository at this point in the history
…rt formats)
  • Loading branch information
danielpalme committed Nov 9, 2024
1 parent 9cc5ad8 commit ea18ace
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)
int totalProjectNcloc = 0;
int totalProjectFiles = 0;

foreach (var assembly in summaryResult.Assemblies)
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

foreach (var assembly in assembliesWithClasses)
{
if (this.packageElementsByName.TryGetValue(assembly.Name, out XElement packageElement))
{
Expand Down Expand Up @@ -356,7 +360,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
new XAttribute("loc", totalProjectLoc.ToString(CultureInfo.InvariantCulture)),
new XAttribute("ncloc", totalProjectNcloc.ToString(CultureInfo.InvariantCulture)),
new XAttribute("files", totalProjectFiles.ToString(CultureInfo.InvariantCulture)),
new XAttribute("packages", summaryResult.Assemblies.Count.ToString(CultureInfo.InvariantCulture))));
new XAttribute("packages", assembliesWithClasses.Length.ToString(CultureInfo.InvariantCulture))));

var testProjectElement = new XElement(
"testproject",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)
{
decimal? summaryComplexity = null;

foreach (var assembly in summaryResult.Assemblies)
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

foreach (var assembly in assembliesWithClasses)
{
decimal? assemblyComplexity = null;
if (this.packageElementsByName.TryGetValue(assembly.Name, out XElement packageElement))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using Palmmedia.ReportGenerator.Core.Common;
Expand Down Expand Up @@ -120,7 +121,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)

reportTextWriter.WriteLine(" \"source_files\": [");

foreach (var assembly in summaryResult.Assemblies)
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

foreach (var assembly in assembliesWithClasses)
{
foreach (var clazz in assembly.Classes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
Expand Down Expand Up @@ -83,6 +82,10 @@ public void CreateSummaryReport(SummaryResult summaryResult)

using (var reportTextWriter = File.CreateText(targetPath))
{
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

reportTextWriter.WriteLine(ReportResources.Summary);
reportTextWriter.WriteLine(
"{0};{1}",
Expand All @@ -95,15 +98,15 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine(
"{0};{1}",
ReportResources.Assemblies2,
summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture));
assembliesWithClasses.Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine(
"{0};{1}",
ReportResources.Classes,
summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
assembliesWithClasses.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine(
"{0};{1}",
ReportResources.Files2,
summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
assembliesWithClasses.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine(
"{0};{1}",
ReportResources.Coverage2,
Expand All @@ -125,7 +128,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
ReportResources.TotalLines,
summaryResult.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));

foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
reportTextWriter.WriteLine();
reportTextWriter.WriteLine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,16 @@ public virtual void CreateSummaryReport(IHtmlRenderer reportRenderer, SummaryRes
reportRenderer.BeginSummaryReport(this.CreateTargetDirectory(), null, title);
reportRenderer.HeaderWithGithubLinks(title);

var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

var infoCardItems = new List<CardLineItem>()
{
new CardLineItem(ReportResources.Parser, summaryResult.UsedParser, null, CardLineItemAlignment.Left),
new CardLineItem(ReportResources.Assemblies2, summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture), null),
new CardLineItem(ReportResources.Classes, summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture), null),
new CardLineItem(ReportResources.Files2, summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture), null)
new CardLineItem(ReportResources.Assemblies2, assembliesWithClasses.Count().ToString(CultureInfo.InvariantCulture), null),
new CardLineItem(ReportResources.Classes, assembliesWithClasses.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture), null),
new CardLineItem(ReportResources.Files2, assembliesWithClasses.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture), null)
};

if (this.ReportContext.ReportConfiguration.Tag != null)
Expand Down Expand Up @@ -356,12 +360,12 @@ public virtual void CreateSummaryReport(IHtmlRenderer reportRenderer, SummaryRes

reportRenderer.Header(ReportResources.Coverage3);

if (summaryResult.Assemblies.Any())
if (assembliesWithClasses.Any())
{
reportRenderer.BeginSummaryTable();
reportRenderer.BeginSummaryTable(summaryResult.SupportsBranchCoverage, proVersion);

foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
reportRenderer.SummaryAssembly(assembly, summaryResult.SupportsBranchCoverage, proVersion);

Expand All @@ -384,7 +388,7 @@ public virtual void CreateSummaryReport(IHtmlRenderer reportRenderer, SummaryRes
}

reportRenderer.CustomSummary(
summaryResult.Assemblies,
assembliesWithClasses,
this.ReportContext.RiskHotspotAnalysisResult.RiskHotspots,
summaryResult.SupportsBranchCoverage,
proVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ public void CreateSummaryReport(SummaryResult summaryResult)

using (var reportTextWriter = new StreamWriter(new FileStream(targetPath, FileMode.Create), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)))
{
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

reportTextWriter.WriteLine("{");
reportTextWriter.WriteLine(" \"summary\": {");
reportTextWriter.WriteLine($" \"generatedon\": \"{DateTime.Now.ToUniversalTime().ToString("s")}Z\",");
reportTextWriter.WriteLine($" \"parser\": \"{summaryResult.UsedParser}\",");
reportTextWriter.WriteLine($" \"assemblies\": {summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"classes\": {summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"files\": {summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"assemblies\": {assembliesWithClasses.Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"classes\": {assembliesWithClasses.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"files\": {assembliesWithClasses.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"coveredlines\": {summaryResult.CoveredLines.ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"uncoveredlines\": {(summaryResult.CoverableLines - summaryResult.CoveredLines).ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"coverablelines\": {summaryResult.CoverableLines.ToString(CultureInfo.InvariantCulture)},");
Expand Down Expand Up @@ -161,7 +165,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)

int assemblyCounter = 0;

foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
if (assemblyCounter > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
Expand Down Expand Up @@ -85,7 +85,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine("TN:");
long branchCounter = 0;

foreach (var assembly in summaryResult.Assemblies)
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

foreach (var assembly in assembliesWithClasses)
{
foreach (var @class in assembly.Classes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,14 @@ public virtual void CreateSummaryReport(ILatexRenderer reportRenderer, SummaryRe
reportRenderer.KeyValueRow(ReportResources.CoverageDate, summaryResult.CoverageDate());
}

var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

reportRenderer.KeyValueRow(ReportResources.Parser, summaryResult.UsedParser);
reportRenderer.KeyValueRow(ReportResources.Assemblies2, summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.Classes, summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.Files2, summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.Assemblies2, assembliesWithClasses.Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.Classes, assembliesWithClasses.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.Files2, assembliesWithClasses.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.CoveredLines, summaryResult.CoveredLines.ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.UncoveredLines, (summaryResult.CoverableLines - summaryResult.CoveredLines).ToString(CultureInfo.InvariantCulture));
reportRenderer.KeyValueRow(ReportResources.CoverableLines, summaryResult.CoverableLines.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -252,11 +256,11 @@ public virtual void CreateSummaryReport(ILatexRenderer reportRenderer, SummaryRe

reportRenderer.Header(ReportResources.Coverage3);

if (summaryResult.Assemblies.Any())
if (assembliesWithClasses.Any())
{
reportRenderer.BeginSummaryTable(summaryResult.SupportsBranchCoverage, true);

foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
reportRenderer.SummaryAssembly(assembly, summaryResult.SupportsBranchCoverage, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine();
reportTextWriter.WriteLine();

if (summaryResult.Assemblies.Any())
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

if (assembliesWithClasses.Any())
{
reportTextWriter.Write(
"|**{0}**|**{1}**|",
Expand Down Expand Up @@ -148,7 +152,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)

reportTextWriter.WriteLine();

foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
reportTextWriter.Write("|**{0}**", assembly.Name);
reportTextWriter.Write("|**{0}**", assembly.CoverageQuota.HasValue ? assembly.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "%" : string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void CreateSummaryReport(SummaryResult summaryResult)

using (var reportTextWriter = File.CreateText(targetPath))
{
var assembliesWithClasses = summaryResult.Assemblies
.Where(a => a.Classes.Any())
.ToArray();

if (this.ReportContext.ReportConfiguration.Title != null)
{
reportTextWriter.WriteLine("# {0} - {1}", ReportResources.Summary, this.ReportContext.ReportConfiguration.Title);
Expand All @@ -111,9 +115,9 @@ public void CreateSummaryReport(SummaryResult summaryResult)
}

reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Parser, summaryResult.UsedParser);
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Assemblies2, summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Classes, summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Files2, summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Assemblies2, assembliesWithClasses.Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Classes, assembliesWithClasses.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.Files2, assembliesWithClasses.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| **{0}** | {1} |", ReportResources.Coverage2, summaryResult.CoverageQuota.HasValue ? $"{summaryResult.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture)}% ({summaryResult.CoveredLines.ToString(CultureInfo.InvariantCulture)} {ReportResources.Of} {summaryResult.CoverableLines.ToString(CultureInfo.InvariantCulture)})" : string.Empty);
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.CoveredLines, summaryResult.CoveredLines.ToString(CultureInfo.InvariantCulture));
reportTextWriter.WriteLine("| {0} | {1} |", ReportResources.UncoveredLines, (summaryResult.CoverableLines - summaryResult.CoveredLines).ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -158,9 +162,9 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine();
reportTextWriter.WriteLine("## {0}", ReportResources.Coverage3);

if (summaryResult.Assemblies.Any())
if (assembliesWithClasses.Any())
{
foreach (var assembly in summaryResult.Assemblies)
foreach (var assembly in assembliesWithClasses)
{
reportTextWriter.WriteLine(
"<details><summary>{0} - {1}</summary>",
Expand Down
Loading

0 comments on commit ea18ace

Please sign in to comment.