Skip to content

Commit 3e49288

Browse files
committed
#379: Added setting to allow saving report types to different directories
1 parent 9b54432 commit 3e49288

33 files changed

+365
-64
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ variables:
1212
- name: disable.coverage.autogenerate
1313
value: 'true'
1414
- name: version
15-
value: '4.6.5'
15+
value: '4.6.6'
1616

1717
stages:
1818
- stage: Build

src/AzureDevopsTask/ReportGenerator/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 4,
1515
"Minor": 6,
16-
"Patch": 5
16+
"Patch": 6
1717
},
1818
"instanceNameFormat": "ReportGenerator",
1919
"groups": [

src/AzureDevopsTask/vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "reportgenerator",
44
"name": "ReportGenerator",
5-
"version": "4.6.5",
5+
"version": "4.6.6",
66
"publisher": "Palmmedia",
77
"public": true,
88
"targets": [

src/Readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ For further details take a look at LICENSE.txt.
6363

6464
CHANGELOG
6565

66+
4.6.6.0
67+
68+
* New: #379: Added setting to allow saving report types to different directories
69+
6670
4.6.5.0
6771

6872
* New: #364: Added addtional columns for branch coverage in summary

src/ReportGenerator.Console.NetCore/ReportGenerator.Console.NetCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<AssemblyName>ReportGenerator</AssemblyName>
88
<RootNamespace>Palmmedia.ReportGenerator</RootNamespace>
99
<StartupObject>Palmmedia.ReportGenerator.Console.NetCore.Program</StartupObject>
10-
<AssemblyVersion>4.6.5.0</AssemblyVersion>
11-
<FileVersion>4.6.5.0</FileVersion>
10+
<AssemblyVersion>4.6.6.0</AssemblyVersion>
11+
<FileVersion>4.6.6.0</FileVersion>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

src/ReportGenerator.Console/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("4.6.5.0")]
35-
[assembly: AssemblyFileVersion("4.6.5.0")]
34+
[assembly: AssemblyVersion("4.6.6.0")]
35+
[assembly: AssemblyFileVersion("4.6.6.0")]

src/ReportGenerator.Core.Test/ReportGenerator.Core.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<RootNamespace>Palmmedia.ReportGenerator.Core.Test</RootNamespace>
7-
<AssemblyVersion>4.6.5.0</AssemblyVersion>
8-
<FileVersion>4.6.5.0</FileVersion>
7+
<AssemblyVersion>4.6.6.0</AssemblyVersion>
8+
<FileVersion>4.6.6.0</FileVersion>
99
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1010
</PropertyGroup>
1111

src/ReportGenerator.Core/ReportGenerator.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
88
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
99
<AssemblyName>ReportGenerator.Core</AssemblyName>
10-
<AssemblyVersion>4.6.5.0</AssemblyVersion>
11-
<FileVersion>4.6.5.0</FileVersion>
10+
<AssemblyVersion>4.6.6.0</AssemblyVersion>
11+
<FileVersion>4.6.6.0</FileVersion>
1212
</PropertyGroup>
1313

1414
<PropertyGroup>

src/ReportGenerator.Core/Reporting/Builders/BadgeReportBuilder.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.IO;
5+
using Palmmedia.ReportGenerator.Core.Common;
56
using Palmmedia.ReportGenerator.Core.Logging;
67
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
78
using Palmmedia.ReportGenerator.Core.Properties;
@@ -202,7 +203,27 @@ public void CreateSummaryReport(SummaryResult summaryResult)
202203
throw new ArgumentNullException(nameof(summaryResult));
203204
}
204205

205-
string targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "badge_linecoverage.svg");
206+
string targetDirectory = this.ReportContext.ReportConfiguration.TargetDirectory;
207+
208+
if (this.ReportContext.Settings.CreateSubdirectoryForAllReportTypes)
209+
{
210+
targetDirectory = Path.Combine(targetDirectory, this.ReportType);
211+
212+
if (!Directory.Exists(targetDirectory))
213+
{
214+
try
215+
{
216+
Directory.CreateDirectory(targetDirectory);
217+
}
218+
catch (Exception ex)
219+
{
220+
Logger.ErrorFormat(Resources.TargetDirectoryCouldNotBeCreated, targetDirectory, ex.GetExceptionMessageForDisplay());
221+
return;
222+
}
223+
}
224+
}
225+
226+
string targetPath = Path.Combine(targetDirectory, "badge_linecoverage.svg");
206227

207228
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
208229

@@ -212,7 +233,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
212233

213234
foreach (var color in ShieldIoColors)
214235
{
215-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, $"badge_shieldsio_linecoverage_{color.Item1}.svg");
236+
targetPath = Path.Combine(targetDirectory, $"badge_shieldsio_linecoverage_{color.Item1}.svg");
216237

217238
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
218239

@@ -221,7 +242,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
221242
this.CreateShieldsIoSvgBadge(summaryResult.CoverageQuota, color.Item2));
222243
}
223244

224-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "badge_branchcoverage.svg");
245+
targetPath = Path.Combine(targetDirectory, "badge_branchcoverage.svg");
225246

226247
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
227248

@@ -231,7 +252,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
231252

232253
foreach (var color in ShieldIoColors)
233254
{
234-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, $"badge_shieldsio_branchcoverage_{color.Item1}.svg");
255+
targetPath = Path.Combine(targetDirectory, $"badge_shieldsio_branchcoverage_{color.Item1}.svg");
235256

236257
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
237258

@@ -240,22 +261,22 @@ public void CreateSummaryReport(SummaryResult summaryResult)
240261
this.CreateShieldsIoSvgBadge(summaryResult.BranchCoverageQuota, color.Item2));
241262
}
242263

243-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "badge_combined.svg");
264+
targetPath = Path.Combine(targetDirectory, "badge_combined.svg");
244265

245266
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
246267

247268
File.WriteAllText(
248269
targetPath,
249270
this.CreateSvgBadge(summaryResult, true, true));
250271

251-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "badge_linecoverage.png");
272+
targetPath = Path.Combine(targetDirectory, "badge_linecoverage.png");
252273

253274
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
254275

255276
File.WriteAllBytes(
256277
targetPath,
257278
this.CreatePngBadge(summaryResult, true));
258-
targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "badge_branchcoverage.png");
279+
targetPath = Path.Combine(targetDirectory, "badge_branchcoverage.png");
259280

260281
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
261282

src/ReportGenerator.Core/Reporting/Builders/CloverReportBuilder.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Xml.Linq;
7+
using Palmmedia.ReportGenerator.Core.Common;
78
using Palmmedia.ReportGenerator.Core.Logging;
89
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
910
using Palmmedia.ReportGenerator.Core.Properties;
@@ -382,7 +383,27 @@ public void CreateSummaryReport(SummaryResult summaryResult)
382383

383384
XDocument result = new XDocument(new XDeclaration("1.0", "UTF-8", null), rootElement);
384385

385-
string targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "Clover.xml");
386+
string targetDirectory = this.ReportContext.ReportConfiguration.TargetDirectory;
387+
388+
if (this.ReportContext.Settings.CreateSubdirectoryForAllReportTypes)
389+
{
390+
targetDirectory = Path.Combine(targetDirectory, this.ReportType);
391+
392+
if (!Directory.Exists(targetDirectory))
393+
{
394+
try
395+
{
396+
Directory.CreateDirectory(targetDirectory);
397+
}
398+
catch (Exception ex)
399+
{
400+
Logger.ErrorFormat(Resources.TargetDirectoryCouldNotBeCreated, targetDirectory, ex.GetExceptionMessageForDisplay());
401+
return;
402+
}
403+
}
404+
}
405+
406+
string targetPath = Path.Combine(targetDirectory, "Clover.xml");
386407

387408
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
388409

src/ReportGenerator.Core/Reporting/Builders/CoberturaReportBuilder.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
using System.IO;
55
using System.Linq;
66
using System.Xml.Linq;
7+
using Palmmedia.ReportGenerator.Core.Common;
78
using Palmmedia.ReportGenerator.Core.Logging;
89
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
910
using Palmmedia.ReportGenerator.Core.Properties;
1011

1112
namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
1213
{
1314
/// <summary>
14-
/// Creates xml report in Cobertura format
15+
/// Creates xml report in Cobertura format.
1516
/// </summary>
1617
public class CoberturaReportBuilder : IReportBuilder
1718
{
@@ -229,7 +230,27 @@ public void CreateSummaryReport(SummaryResult summaryResult)
229230
XDocument result = new XDocument(new XDeclaration("1.0", null, null), rootElement);
230231
result.AddFirst(new XDocumentType("coverage", null, "http://cobertura.sourceforge.net/xml/coverage-04.dtd", null));
231232

232-
string targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "Cobertura.xml");
233+
string targetDirectory = this.ReportContext.ReportConfiguration.TargetDirectory;
234+
235+
if (this.ReportContext.Settings.CreateSubdirectoryForAllReportTypes)
236+
{
237+
targetDirectory = Path.Combine(targetDirectory, this.ReportType);
238+
239+
if (!Directory.Exists(targetDirectory))
240+
{
241+
try
242+
{
243+
Directory.CreateDirectory(targetDirectory);
244+
}
245+
catch (Exception ex)
246+
{
247+
Logger.ErrorFormat(Resources.TargetDirectoryCouldNotBeCreated, targetDirectory, ex.GetExceptionMessageForDisplay());
248+
return;
249+
}
250+
}
251+
}
252+
253+
string targetPath = Path.Combine(targetDirectory, "Cobertura.xml");
233254

234255
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
235256

src/ReportGenerator.Core/Reporting/Builders/CsvSummaryReportBuilder.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using Palmmedia.ReportGenerator.Core.Common;
78
using Palmmedia.ReportGenerator.Core.Logging;
89
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
910
using Palmmedia.ReportGenerator.Core.Properties;
@@ -56,7 +57,27 @@ public void CreateSummaryReport(SummaryResult summaryResult)
5657
throw new ArgumentNullException(nameof(summaryResult));
5758
}
5859

59-
string targetPath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "Summary.csv");
60+
string targetDirectory = this.ReportContext.ReportConfiguration.TargetDirectory;
61+
62+
if (this.ReportContext.Settings.CreateSubdirectoryForAllReportTypes)
63+
{
64+
targetDirectory = Path.Combine(targetDirectory, this.ReportType);
65+
66+
if (!Directory.Exists(targetDirectory))
67+
{
68+
try
69+
{
70+
Directory.CreateDirectory(targetDirectory);
71+
}
72+
catch (Exception ex)
73+
{
74+
Logger.ErrorFormat(Resources.TargetDirectoryCouldNotBeCreated, targetDirectory, ex.GetExceptionMessageForDisplay());
75+
return;
76+
}
77+
}
78+
}
79+
80+
string targetPath = Path.Combine(targetDirectory, "Summary.csv");
6081

6182
Logger.InfoFormat(Resources.WritingReportFile, targetPath);
6283

src/ReportGenerator.Core/Reporting/Builders/HtmlChartReportBuilder.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public override void CreateSummaryReport(IReportRenderer reportRenderer, Summary
3939
throw new ArgumentNullException(nameof(summaryResult));
4040
}
4141

42-
reportRenderer.BeginSummaryReport(this.ReportContext.ReportConfiguration.TargetDirectory, "CoverageHistory.html", ReportResources.Summary);
42+
string targetDirectory = this.CreateTargetDirectory();
43+
44+
reportRenderer.BeginSummaryReport(targetDirectory, "CoverageHistory.html", ReportResources.Summary);
4345

4446
var historicCoverages = this.GetOverallHistoricCoverages(this.ReportContext.OverallHistoricCoverages);
4547
if (historicCoverages.Any(h => h.CoverageQuota.HasValue || h.BranchCoverageQuota.HasValue))
@@ -49,11 +51,11 @@ public override void CreateSummaryReport(IReportRenderer reportRenderer, Summary
4951

5052
reportRenderer.CustomSummary(summaryResult.Assemblies, new List<RiskHotspot>(), summaryResult.SupportsBranchCoverage);
5153

52-
reportRenderer.SaveSummaryReport(this.ReportContext.ReportConfiguration.TargetDirectory);
54+
reportRenderer.SaveSummaryReport(targetDirectory);
5355

5456
File.Copy(
55-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "CoverageHistory.html"),
56-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "CoverageHistory.htm"),
57+
Path.Combine(targetDirectory, "CoverageHistory.html"),
58+
Path.Combine(targetDirectory, "CoverageHistory.htm"),
5759
true);
5860
}
5961
}

src/ReportGenerator.Core/Reporting/Builders/HtmlInlineAzurePipelinesDarkReportBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ public override void CreateSummaryReport(SummaryResult summaryResult)
4242
this.CreateSummaryReport(renderer, summaryResult);
4343
}
4444

45+
string targetDirectory = this.CreateTargetDirectory();
46+
4547
File.Copy(
46-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.html"),
47-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.htm"),
48+
Path.Combine(targetDirectory, "index.html"),
49+
Path.Combine(targetDirectory, "index.htm"),
4850
true);
4951
}
5052
}

src/ReportGenerator.Core/Reporting/Builders/HtmlInlineAzurePipelinesReportBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ public override void CreateSummaryReport(SummaryResult summaryResult)
4242
this.CreateSummaryReport(renderer, summaryResult);
4343
}
4444

45+
string targetDirectory = this.CreateTargetDirectory();
46+
4547
File.Copy(
46-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.html"),
47-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.htm"),
48+
Path.Combine(targetDirectory, "index.html"),
49+
Path.Combine(targetDirectory, "index.htm"),
4850
true);
4951
}
5052
}

src/ReportGenerator.Core/Reporting/Builders/HtmlInlineCssAndJavaScriptReportBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ public override void CreateSummaryReport(SummaryResult summaryResult)
4242
this.CreateSummaryReport(renderer, summaryResult);
4343
}
4444

45+
string targetDirectory = this.CreateTargetDirectory();
46+
4547
File.Copy(
46-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.html"),
47-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.htm"),
48+
Path.Combine(targetDirectory, "index.html"),
49+
Path.Combine(targetDirectory, "index.htm"),
4850
true);
4951
}
5052
}

src/ReportGenerator.Core/Reporting/Builders/HtmlReportBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ public override void CreateSummaryReport(SummaryResult summaryResult)
6666
this.CreateSummaryReport(renderer, summaryResult);
6767
}
6868

69+
string targetDirectory = this.CreateTargetDirectory();
70+
6971
File.Copy(
70-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.html"),
71-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "index.htm"),
72+
Path.Combine(targetDirectory, "index.html"),
73+
Path.Combine(targetDirectory, "index.htm"),
7274
true);
7375
}
7476
}

src/ReportGenerator.Core/Reporting/Builders/HtmlSummaryReportBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ public override void CreateSummaryReport(SummaryResult summaryResult)
3838
this.CreateSummaryReport(renderer, summaryResult);
3939
}
4040

41-
string sourcePath = Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "summary.html");
41+
string targetDirectory = this.CreateTargetDirectory();
42+
43+
string sourcePath = Path.Combine(targetDirectory, "summary.html");
4244

4345
if (File.Exists(sourcePath))
4446
{
4547
File.Copy(
4648
sourcePath,
47-
Path.Combine(this.ReportContext.ReportConfiguration.TargetDirectory, "summary.htm"),
49+
Path.Combine(targetDirectory, "summary.htm"),
4850
true);
4951
}
5052
}

0 commit comments

Comments
 (0)