Skip to content

Commit

Permalink
#363: Improved handling of HTML generation (several HTML reports at o…
Browse files Browse the repository at this point in the history
…nce)
  • Loading branch information
danielpalme committed Sep 7, 2020
1 parent 15514a3 commit 1c2b7c1
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 50 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ variables:
- name: disable.coverage.autogenerate
value: 'true'
- name: version
value: '4.6.6'
value: '4.6.7'

stages:
- stage: Build
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/ReportGenerator/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 4,
"Minor": 6,
"Patch": 6
"Patch": 7
},
"instanceNameFormat": "ReportGenerator",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion src/AzureDevopsTask/vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "reportgenerator",
"name": "ReportGenerator",
"version": "4.6.6",
"version": "4.6.7",
"publisher": "Palmmedia",
"public": true,
"targets": [
Expand Down
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

4.6.7.0

* Fix: #363: Improved handling of HTML generation (several HTML reports at once)

4.6.6.0

* New: #379: Added setting to allow saving report types to different directories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>ReportGenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.Console.NetCore.Program</StartupObject>
<AssemblyVersion>4.6.6.0</AssemblyVersion>
<FileVersion>4.6.6.0</FileVersion>
<AssemblyVersion>4.6.7.0</AssemblyVersion>
<FileVersion>4.6.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.6.6.0")]
[assembly: AssemblyFileVersion("4.6.6.0")]
[assembly: AssemblyVersion("4.6.7.0")]
[assembly: AssemblyFileVersion("4.6.7.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Palmmedia.ReportGenerator.Core.Test</RootNamespace>
<AssemblyVersion>4.6.6.0</AssemblyVersion>
<FileVersion>4.6.6.0</FileVersion>
<AssemblyVersion>4.6.7.0</AssemblyVersion>
<FileVersion>4.6.7.0</FileVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Core/ReportGenerator.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyName>ReportGenerator.Core</AssemblyName>
<AssemblyVersion>4.6.6.0</AssemblyVersion>
<FileVersion>4.6.6.0</FileVersion>
<AssemblyVersion>4.6.7.0</AssemblyVersion>
<FileVersion>4.6.7.0</FileVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
/// </summary>
public class HtmlInlineAzurePipelinesDarkReportBuilder : ReportBuilderBase
{
/// <summary>
/// Dictionary containing the filenames of the class reports by class.
/// </summary>
private readonly IDictionary<string, string> fileNameByClass = new Dictionary<string, string>();

/// <summary>
/// Gets the report type.
/// </summary>
Expand All @@ -25,7 +30,7 @@ public class HtmlInlineAzurePipelinesDarkReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -37,7 +42,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
/// </summary>
public class HtmlInlineAzurePipelinesReportBuilder : ReportBuilderBase
{
/// <summary>
/// Dictionary containing the filenames of the class reports by class.
/// </summary>
private readonly IDictionary<string, string> fileNameByClass = new Dictionary<string, string>();

/// <summary>
/// Gets the report type.
/// </summary>
Expand All @@ -25,7 +30,7 @@ public class HtmlInlineAzurePipelinesReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -37,7 +42,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
/// </summary>
public class HtmlInlineCssAndJavaScriptReportBuilder : ReportBuilderBase
{
/// <summary>
/// Dictionary containing the filenames of the class reports by class.
/// </summary>
private readonly IDictionary<string, string> fileNameByClass = new Dictionary<string, string>();

/// <summary>
/// Gets the report type.
/// </summary>
Expand All @@ -25,7 +30,7 @@ public class HtmlInlineCssAndJavaScriptReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -37,7 +42,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, HtmlMode.InlineCssAndJavaScript))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
10 changes: 7 additions & 3 deletions src/ReportGenerator.Core/Reporting/Builders/HtmlReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class HtmlReportBuilder : ReportBuilderBase
/// </summary>
private readonly HtmlMode htmlMode;

/// <summary>
/// Dictionary containing the filenames of the class reports by class.
/// </summary>
private readonly IDictionary<string, string> fileNameByClass = new Dictionary<string, string>();

/// <summary>
/// Initializes a new instance of the <see cref="HtmlReportBuilder" /> class.
/// </summary>
Expand All @@ -41,15 +46,14 @@ public HtmlReportBuilder(bool externalCssAndJavaScriptWithQueryStringHandling)
/// </value>
public override string ReportType => "Html";


/// <summary>
/// Creates a class report.
/// </summary>
/// <param name="class">The class.</param>
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, this.htmlMode))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, this.htmlMode))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -61,7 +65,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, this.htmlMode))
using (var renderer = new HtmlRenderer(this.fileNameByClass, false, this.htmlMode))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(true, HtmlMode.InlineCssAndJavaScript))
using (var renderer = new HtmlRenderer(new Dictionary<string, string>(), true, HtmlMode.InlineCssAndJavaScript))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ internal class HtmlRenderer : IReportRenderer, IDisposable
/// <summary>
/// Dictionary containing the filenames of the class reports by class.
/// </summary>
private static readonly Dictionary<string, string> FileNameByClass = new Dictionary<string, string>();

/// <summary>
/// Indicates that JavaScript was generated.
/// </summary>
private static bool javaScriptGenerated;
private readonly IDictionary<string, string> fileNameByClass;

/// <summary>
/// Indicates that only a summary report is created (no class reports).
Expand All @@ -83,6 +78,11 @@ internal class HtmlRenderer : IReportRenderer, IDisposable
/// </summary>
private readonly string additionalCssFileResource;

/// <summary>
/// Indicates that JavaScript was generated.
/// </summary>
private bool javaScriptGenerated;

/// <summary>
/// The report builder.
/// </summary>
Expand All @@ -96,12 +96,19 @@ internal class HtmlRenderer : IReportRenderer, IDisposable
/// <summary>
/// Initializes a new instance of the <see cref="HtmlRenderer" /> class.
/// </summary>
/// <param name="fileNameByClass">Dictionary containing the filenames of the class reports by class.</param>
/// <param name="onlySummary">if set to <c>true</c> only a summary report is created (no class reports).</param>
/// <param name="htmlMode">Defines how CSS and JavaScript are referenced.</param>
/// <param name="cssFileResource">Optional CSS file resource.</param>
/// <param name="additionalCssFileResource">Optional additional CSS file resource.</param>
internal HtmlRenderer(bool onlySummary, HtmlMode htmlMode, string cssFileResource = "custom.css", string additionalCssFileResource = null)
internal HtmlRenderer(
IDictionary<string, string> fileNameByClass,
bool onlySummary,
HtmlMode htmlMode,
string cssFileResource = "custom.css",
string additionalCssFileResource = null)
{
this.fileNameByClass = fileNameByClass;
this.onlySummary = onlySummary;
this.htmlMode = htmlMode;
this.javaScriptContent = new StringBuilder();
Expand Down Expand Up @@ -153,7 +160,7 @@ public void BeginClassReport(string targetDirectory, string assemblyName, string
{
this.classReport = true;

string targetPath = GetClassReportFilename(assemblyName, className);
string targetPath = this.GetClassReportFilename(assemblyName, className);

Logger.DebugFormat(Resources.WritingReportFile, targetPath);
this.CreateTextWriter(Path.Combine(targetDirectory, targetPath));
Expand Down Expand Up @@ -476,7 +483,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
this.javaScriptContent.AppendFormat("\"name\": \"{0}\",", @class.Name.Replace(@"\", @"\\"));
this.javaScriptContent.AppendFormat(
" \"rp\": \"{0}\",",
this.onlySummary ? string.Empty : GetClassReportFilename(@class.Assembly.ShortName, @class.Name));
this.onlySummary ? string.Empty : this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name));
this.javaScriptContent.AppendFormat(" \"cl\": {0},", @class.CoveredLines);
this.javaScriptContent.AppendFormat(" \"ucl\": {0},", @class.CoverableLines - @class.CoveredLines);
this.javaScriptContent.AppendFormat(" \"cal\": {0},", @class.CoverableLines);
Expand Down Expand Up @@ -548,7 +555,7 @@ public void CustomSummary(IEnumerable<Assembly> assemblies, IEnumerable<RiskHots
this.javaScriptContent.AppendLine(" {");
this.javaScriptContent.AppendFormat(" \"assembly\": \"{0}\",", riskHotspot.Assembly.ShortName);
this.javaScriptContent.AppendFormat(" \"class\": \"{0}\",", riskHotspot.Class.Name);
this.javaScriptContent.AppendFormat(" \"reportPath\": \"{0}\",", this.onlySummary ? string.Empty : GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name));
this.javaScriptContent.AppendFormat(" \"reportPath\": \"{0}\",", this.onlySummary ? string.Empty : this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name));
this.javaScriptContent.AppendFormat(" \"methodName\": \"{0}\",", riskHotspot.MethodMetric.FullName);
this.javaScriptContent.AppendFormat(" \"methodShortName\": \"{0}\",", riskHotspot.MethodMetric.ShortName);
this.javaScriptContent.AppendFormat(" \"fileIndex\": {0},", riskHotspot.FileIndex);
Expand Down Expand Up @@ -997,7 +1004,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
filenameColumn = string.Format(
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(riskHotspot.Class.Name));
}

Expand All @@ -1010,7 +1017,7 @@ public void RiskHotspots(IEnumerable<RiskHotspot> riskHotspots)
this.reportTextWriter.Write(
"<td title=\"{0}\"><a href=\"{1}#file{2}_line{3}\">{4}</a></td>",
WebUtility.HtmlEncode(riskHotspot.MethodMetric.FullName),
WebUtility.HtmlEncode(GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(riskHotspot.Assembly.ShortName, riskHotspot.Class.Name)),
riskHotspot.FileIndex,
riskHotspot.MethodMetric.Line,
WebUtility.HtmlEncode(riskHotspot.MethodMetric.ShortName));
Expand Down Expand Up @@ -1092,7 +1099,7 @@ public void SummaryClass(Class @class, bool branchCoverageAvailable)
filenameColumn = string.Format(
CultureInfo.InvariantCulture,
"<a href=\"{0}\">{1}</a>",
WebUtility.HtmlEncode(GetClassReportFilename(@class.Assembly.ShortName, @class.Name)),
WebUtility.HtmlEncode(this.GetClassReportFilename(@class.Assembly.ShortName, @class.Name)),
WebUtility.HtmlEncode(@class.Name));
}

Expand Down Expand Up @@ -1160,10 +1167,10 @@ public void SaveClassReport(string targetDirectory, string assemblyName, string
{
this.SaveReport();

if (this.htmlMode != HtmlMode.InlineCssAndJavaScript && !javaScriptGenerated)
if (this.htmlMode != HtmlMode.InlineCssAndJavaScript && !this.javaScriptGenerated)
{
this.SaveJavaScript(targetDirectory);
javaScriptGenerated = true;
this.javaScriptGenerated = true;
}
}

Expand Down Expand Up @@ -1280,13 +1287,13 @@ private static string GetTooltip(LineAnalysis analysis)
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="className">Name of the class.</param>
/// <returns>The file name.</returns>
private static string GetClassReportFilename(string assemblyName, string className)
private string GetClassReportFilename(string assemblyName, string className)
{
string key = assemblyName + "_" + className;

string fileName = null;

if (!FileNameByClass.TryGetValue(key, out fileName))
if (!this.fileNameByClass.TryGetValue(key, out fileName))
{
string shortClassName = null;

Expand Down Expand Up @@ -1317,7 +1324,7 @@ private static string GetClassReportFilename(string assemblyName, string classNa
fileName = firstPart + lastPart;
}

if (FileNameByClass.Values.Any(v => v.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
if (this.fileNameByClass.Values.Any(v => v.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
{
int counter = 2;
string fileNameWithoutExtension = fileName.Substring(0, fileName.Length - 4);
Expand All @@ -1327,10 +1334,10 @@ private static string GetClassReportFilename(string assemblyName, string classNa
fileName = fileNameWithoutExtension + counter + ".html";
counter++;
}
while (FileNameByClass.Values.Any(v => v.Equals(fileName, StringComparison.OrdinalIgnoreCase)));
while (this.fileNameByClass.Values.Any(v => v.Equals(fileName, StringComparison.OrdinalIgnoreCase)));
}

FileNameByClass.Add(key, fileName);
this.fileNameByClass.Add(key, fileName);
}

return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>dotnet-reportgenerator</AssemblyName>
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
<StartupObject>Palmmedia.ReportGenerator.DotnetCliTool.Program</StartupObject>
<AssemblyVersion>4.6.6.0</AssemblyVersion>
<FileVersion>4.6.6.0</FileVersion>
<AssemblyVersion>4.6.7.0</AssemblyVersion>
<FileVersion>4.6.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RootNamespace>ReportGenerator.DotnetCorePluginLoader</RootNamespace>
<AssemblyVersion>4.6.6.0</AssemblyVersion>
<FileVersion>4.6.6.0</FileVersion>
<AssemblyVersion>4.6.7.0</AssemblyVersion>
<FileVersion>4.6.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 1c2b7c1

Please sign in to comment.