Skip to content

Commit

Permalink
#242: Improved option to remove risk hotspots section
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed May 22, 2019
1 parent 0629498 commit 7a30288
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ For further details take a look at LICENSE.txt.

CHANGELOG

4.1.7.0

* Fix: Issue #242: Improved option to remove risk hotspots section
* Fix: Issue #243, #244: Made SummaryResult class public
* Fix: Issue #245, #246: Improved nested class handling for Cobertura

4.1.6.0

* New: Issue #239: Added link back to the summary page
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Palmmedia.ReportGenerator.Core;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Plugin;
Expand Down Expand Up @@ -33,11 +32,11 @@ public void GetReportBuilders_DefaultReportBuilderReturned()

var factory = new ReportBuilderFactory(new ReflectionPluginLoader(plugins));

var reportContext = new ReportContext(new ReportConfiguration() { TargetDirectory = "C:\\temp", ReportTypes = new[] { "Html" } });
var reportContext = new ReportContext(new ReportConfiguration() { TargetDirectory = "C:\\temp", ReportTypes = new[] { "Html" } }, new Settings());
var reportBuilders = factory.GetReportBuilders(reportContext);
Assert.Single(reportBuilders);

reportContext = new ReportContext(new ReportConfiguration() { TargetDirectory = "C:\\temp", ReportTypes = new[] { "Latex" } });
reportContext = new ReportContext(new ReportConfiguration() { TargetDirectory = "C:\\temp", ReportTypes = new[] { "Latex" } }, new Settings());
reportBuilders = factory.GetReportBuilders(reportContext);
Assert.Single(reportBuilders);
Assert.Equal(typeof(AdditionalLatexReportBuilder).FullName, reportBuilders.First().GetType().FullName);
Expand Down
60 changes: 55 additions & 5 deletions src/ReportGenerator.Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,61 @@ public bool GenerateReport(IReportConfiguration reportConfiguration)
try
{
var configuration = this.GetConfiguration();
var reportContext = new ReportContext(reportConfiguration);
configuration.GetSection("settings").Bind(reportContext.Settings);

var settings = new Settings();
configuration.GetSection("settings").Bind(settings);

var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds();
configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds);

return this.GenerateReport(reportConfiguration, settings, riskHotspotsAnalysisThresholds);
}
catch (Exception ex)
{
Logger.Error(ex.GetExceptionMessageForDisplay());
Logger.Error(ex.StackTrace);

#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
Console.ReadKey();
}
#endif

return false;
}
}

/// <summary>
/// Executes the report generation.
/// </summary>
/// <param name="reportConfiguration">The report configuration.</param>
/// <param name="settings">The settings.</param>
/// <param name="riskHotspotsAnalysisThresholds">The risk hotspots analysis thresholds.</param>
/// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns>
public bool GenerateReport(
IReportConfiguration reportConfiguration,
Settings settings,
RiskHotspotsAnalysisThresholds riskHotspotsAnalysisThresholds)
{
if (reportConfiguration == null)
{
throw new ArgumentNullException(nameof(reportConfiguration));
}

if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

if (riskHotspotsAnalysisThresholds == null)
{
throw new ArgumentNullException(nameof(riskHotspotsAnalysisThresholds));
}

try
{
var reportContext = new ReportContext(reportConfiguration, settings);

var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins);

Expand Down Expand Up @@ -75,9 +128,6 @@ public bool GenerateReport(IReportConfiguration reportConfiguration)

Logger.DebugFormat(Resources.ReportParsingTook, stopWatch.ElapsedMilliseconds / 1000d);

var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds();
configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds);

reportContext.RiskHotspotAnalysisResult = new RiskHotspotsAnalyzer(riskHotspotsAnalysisThresholds, reportContext.Settings.DisableRiskHotspots)
.PerformRiskHotspotAnalysis(parserResult.Assemblies);

Expand Down
11 changes: 7 additions & 4 deletions src/ReportGenerator.Core/ReportContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Palmmedia.ReportGenerator.Core.CodeAnalysis;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Reporting;
Expand All @@ -19,9 +20,11 @@ internal class ReportContext : IReportContext
/// Initializes a new instance of the <see cref="ReportContext"/> class.
/// </summary>
/// <param name="reportConfiguration">The configuration options.</param>
internal ReportContext(IReportConfiguration reportConfiguration)
/// <param name="settings">The settings.</param>
internal ReportContext(IReportConfiguration reportConfiguration, Settings settings)
{
this.ReportConfiguration = reportConfiguration;
this.ReportConfiguration = reportConfiguration ?? throw new ArgumentNullException(nameof(reportConfiguration));
this.Settings = settings ?? throw new ArgumentNullException(nameof(settings));
}

/// <summary>
Expand All @@ -32,7 +35,7 @@ internal ReportContext(IReportConfiguration reportConfiguration)
/// <summary>
/// Gets the settings.
/// </summary>
public Settings Settings { get; } = new Settings();
public Settings Settings { get; }

/// <summary>
/// Gets or sets the risk hotspot analysis result.
Expand Down

0 comments on commit 7a30288

Please sign in to comment.