Skip to content

Commit

Permalink
Removed custom Json serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Nov 7, 2024
1 parent 24d447f commit 7a4be5c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 190 deletions.
49 changes: 0 additions & 49 deletions src/ReportGenerator.Core.Test/Common/JsonSerializerTest.cs

This file was deleted.

128 changes: 0 additions & 128 deletions src/ReportGenerator.Core/Common/JsonSerializer.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/ReportGenerator.Core/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ public bool GenerateReport(
}

Logger.Debug(Resources.Settings);
Logger.Debug(" " + JsonSerializer.ToJsonString(settings));
Logger.Debug(" " + JsonSerializer.ToJsonString(minimumCoverageThresholds));
Logger.Debug(" " + JsonSerializer.ToJsonString(riskHotspotsAnalysisThresholds));
Logger.Debug(" " + System.Text.Json.JsonSerializer.Serialize(settings));
Logger.Debug(" " + System.Text.Json.JsonSerializer.Serialize(minimumCoverageThresholds));
Logger.Debug(" " + System.Text.Json.JsonSerializer.Serialize(riskHotspotsAnalysisThresholds));

var stopWatch = Stopwatch.StartNew();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine("{");

reportTextWriter.WriteLine(" \"ci_service\": {");
reportTextWriter.WriteLine($" \"branch\": \"{JsonSerializer.EscapeString(gitInformation.Branch)}\",");
reportTextWriter.WriteLine($" \"branch\": {JsonSerializer.Serialize(gitInformation.Branch)},");
reportTextWriter.WriteLine(" \"build_identifier\": \"\",");
reportTextWriter.WriteLine(" \"build_url\": \"\",");
reportTextWriter.WriteLine($" \"commit_sha\": \"{gitInformation.Sha}\",");
Expand All @@ -95,15 +96,15 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine(" \"environment\": {");
reportTextWriter.WriteLine(" \"gem_version\": \"\",");
reportTextWriter.WriteLine(" \"package_version\": \"\",");
reportTextWriter.WriteLine($" \"pwd\": \"{JsonSerializer.EscapeString(Directory.GetCurrentDirectory())}\",");
reportTextWriter.WriteLine($" \"prefix\": \"{JsonSerializer.EscapeString(Directory.GetCurrentDirectory())}\",");
reportTextWriter.WriteLine($" \"pwd\": {JsonSerializer.Serialize(Directory.GetCurrentDirectory())},");
reportTextWriter.WriteLine($" \"prefix\": {JsonSerializer.Serialize(Directory.GetCurrentDirectory())},");
reportTextWriter.WriteLine(" \"rails_root\": \"\",");
reportTextWriter.WriteLine(" \"reporter_version\": \"0.11.1\",");
reportTextWriter.WriteLine(" \"simplecov_root\": \"\"");
reportTextWriter.WriteLine(" },");

reportTextWriter.WriteLine(" \"git\": {");
reportTextWriter.WriteLine($" \"branch\": \"{JsonSerializer.EscapeString(gitInformation.Branch)}\",");
reportTextWriter.WriteLine($" \"branch\": {JsonSerializer.Serialize(gitInformation.Branch)},");
reportTextWriter.WriteLine($" \"head\": \"{gitInformation.Sha}\",");
reportTextWriter.WriteLine($" \"committed_at\": {(string.IsNullOrWhiteSpace(gitInformation.TimeStamp) ? "null" : gitInformation.TimeStamp)}");
reportTextWriter.WriteLine(" },");
Expand Down Expand Up @@ -140,7 +141,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
}

reportTextWriter.WriteLine(" {");
reportTextWriter.WriteLine($" \"blob_id\": \"{JsonSerializer.EscapeString(GitHelper.GetFileHash(file.Path))}\",");
reportTextWriter.WriteLine($" \"blob_id\": {JsonSerializer.Serialize(GitHelper.GetFileHash(file.Path))},");
reportTextWriter.Write($" \"coverage\": [");

var lineCoverage = file.LineCoverage;
Expand Down Expand Up @@ -170,7 +171,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine($" \"covered\": {file.CoverableLines.ToString(CultureInfo.InvariantCulture)},");
reportTextWriter.WriteLine($" \"total\": {file.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)}");
reportTextWriter.WriteLine(" },");
reportTextWriter.WriteLine($" \"name\": \"{JsonSerializer.EscapeString(file.Path)}\"");
reportTextWriter.WriteLine($" \"name\": {JsonSerializer.Serialize(file.Path)}");
reportTextWriter.Write(" }");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
Expand Down Expand Up @@ -141,11 +142,11 @@ public void CreateSummaryReport(SummaryResult summaryResult)

if (metric.Value.HasValue)
{
reportTextWriter.Write($" {{ \"name\": \"{JsonSerializer.EscapeString(metric.Name)}\", \"value\": {metric.Value.Value.ToString(CultureInfo.InvariantCulture)} }}");
reportTextWriter.Write($" {{ \"name\": {JsonSerializer.Serialize(metric.Name)}, \"value\": {metric.Value.Value.ToString(CultureInfo.InvariantCulture)} }}");
}
else
{
reportTextWriter.Write($" {{ \"name\": \"{JsonSerializer.EscapeString(metric.Name)}\", \"value\": null }}");
reportTextWriter.Write($" {{ \"name\": {JsonSerializer.Serialize(metric.Name)}, \"value\": null }}");
}

metricCounter++;
Expand All @@ -167,7 +168,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine(",");
}

reportTextWriter.WriteLine($" {{ \"name\": \"{JsonSerializer.EscapeString(assembly.Name)}\", \"classes\": {assembly.Classes.Count().ToString(CultureInfo.InvariantCulture)}, \"coverage\": {(assembly.CoverageQuota.HasValue ? assembly.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredlines\": {assembly.CoveredLines.ToString(CultureInfo.InvariantCulture)}, \"coverablelines\": {assembly.CoverableLines.ToString(CultureInfo.InvariantCulture)}, \"totallines\": {(assembly.TotalLines.HasValue ? assembly.TotalLines.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"branchcoverage\": {(assembly.BranchCoverageQuota.HasValue ? assembly.BranchCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredbranches\": {(assembly.CoveredBranches.HasValue ? assembly.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"totalbranches\": {(assembly.TotalBranches.HasValue ? assembly.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : null)}, \"methodcoverage\": {(assembly.CodeElementCoverageQuota.HasValue ? assembly.CodeElementCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredmethods\": {assembly.CoveredCodeElements.ToString(CultureInfo.InvariantCulture)}, \"totalmethods\": {assembly.TotalCodeElements.ToString(CultureInfo.InvariantCulture)}, \"classesinassembly\": [");
reportTextWriter.WriteLine($" {{ \"name\": {JsonSerializer.Serialize(assembly.Name)}, \"classes\": {assembly.Classes.Count().ToString(CultureInfo.InvariantCulture)}, \"coverage\": {(assembly.CoverageQuota.HasValue ? assembly.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredlines\": {assembly.CoveredLines.ToString(CultureInfo.InvariantCulture)}, \"coverablelines\": {assembly.CoverableLines.ToString(CultureInfo.InvariantCulture)}, \"totallines\": {(assembly.TotalLines.HasValue ? assembly.TotalLines.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"branchcoverage\": {(assembly.BranchCoverageQuota.HasValue ? assembly.BranchCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredbranches\": {(assembly.CoveredBranches.HasValue ? assembly.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"totalbranches\": {(assembly.TotalBranches.HasValue ? assembly.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : null)}, \"methodcoverage\": {(assembly.CodeElementCoverageQuota.HasValue ? assembly.CodeElementCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredmethods\": {assembly.CoveredCodeElements.ToString(CultureInfo.InvariantCulture)}, \"totalmethods\": {assembly.TotalCodeElements.ToString(CultureInfo.InvariantCulture)}, \"classesinassembly\": [");

int classCounter = 0;

Expand All @@ -178,7 +179,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
reportTextWriter.WriteLine(",");
}

reportTextWriter.Write($" {{ \"name\": \"{JsonSerializer.EscapeString(@class.Name)}\", \"coverage\": {(@class.CoverageQuota.HasValue ? @class.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredlines\": {@class.CoveredLines.ToString(CultureInfo.InvariantCulture)}, \"coverablelines\": {@class.CoverableLines.ToString(CultureInfo.InvariantCulture)}, \"totallines\": {(@class.TotalLines.HasValue ? @class.TotalLines.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"branchcoverage\": {(@class.BranchCoverageQuota.HasValue ? @class.BranchCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredbranches\": {(@class.CoveredBranches.HasValue ? @class.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"totalbranches\": {(@class.TotalBranches.HasValue ? @class.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : null)}, \"methodcoverage\": {(@class.CodeElementCoverageQuota.HasValue ? @class.CodeElementCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredmethods\": {@class.CoveredCodeElements.ToString(CultureInfo.InvariantCulture)}, \"totalmethods\": {@class.TotalCodeElements.ToString(CultureInfo.InvariantCulture)} }}");
reportTextWriter.Write($" {{ \"name\": {JsonSerializer.Serialize(@class.Name)}, \"coverage\": {(@class.CoverageQuota.HasValue ? @class.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredlines\": {@class.CoveredLines.ToString(CultureInfo.InvariantCulture)}, \"coverablelines\": {@class.CoverableLines.ToString(CultureInfo.InvariantCulture)}, \"totallines\": {(@class.TotalLines.HasValue ? @class.TotalLines.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"branchcoverage\": {(@class.BranchCoverageQuota.HasValue ? @class.BranchCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredbranches\": {(@class.CoveredBranches.HasValue ? @class.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"totalbranches\": {(@class.TotalBranches.HasValue ? @class.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : null)}, \"methodcoverage\": {(@class.CodeElementCoverageQuota.HasValue ? @class.CodeElementCoverageQuota.Value.ToString(CultureInfo.InvariantCulture) : "null")}, \"coveredmethods\": {@class.CoveredCodeElements.ToString(CultureInfo.InvariantCulture)}, \"totalmethods\": {@class.TotalCodeElements.ToString(CultureInfo.InvariantCulture)} }}");

classCounter++;
}
Expand Down

0 comments on commit 7a4be5c

Please sign in to comment.