Skip to content

Commit 41744b4

Browse files
committed
+ ReportFilenamePrefix
* Code style fixes
1 parent 927da49 commit 41744b4

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

pvs2codequality/Converter/XMLConverter.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ internal static class XMLConverter
1010
{
1111
public static (int status, string? result, int linesFound) ParseFullDocument(
1212
string inputXML,
13-
string? trimFolderName = null
13+
string? trimFolderName = null,
14+
string? reportFilenamePrefix = null
1415
)
1516
{
1617
var xDoc = new XmlDocument();
@@ -46,24 +47,34 @@ public static (int status, string? result, int linesFound) ParseFullDocument(
4647
.Where(x => x.Name == "PVS-Studio_Analysis_Log")
4748
.ToArray();
4849

49-
var result = ParseAllLogNodes(logRecords, trimFolderName);
50+
var result = ParseAllLogNodes(
51+
logRecords,
52+
trimFolderName,
53+
reportFilenamePrefix
54+
);
5055

5156
return (0, System.Text.Json.JsonSerializer.Serialize(result), result.Count);
5257
}
5358

5459
public static ICollection<CodeQualityLogRecord> ParseAllLogNodes(
5560
ICollection<XmlElement> logRecords,
56-
string trimFolderName
61+
string trimFolderName,
62+
string? reportFilenamePrefix
5763
)
5864
{
5965
return logRecords
60-
.SelectMany(t => ParseAllLogNodes(t, trimFolderName))
66+
.SelectMany(t => ParseAllLogNodes(
67+
logRecord: t,
68+
trimFolderName: trimFolderName,
69+
reportFilenamePrefix: reportFilenamePrefix
70+
))
6171
.ToArray();
6272
}
6373

6474
public static ICollection<CodeQualityLogRecord> ParseAllLogNodes(
6575
XmlElement logRecord,
66-
string trimFolderName
76+
string trimFolderName,
77+
string? reportFilenamePrefix
6778
)
6879
{
6980
var fields = new[]
@@ -75,16 +86,24 @@ string trimFolderName
7586
{
7687
if (t.InnerText != null)
7788
{
78-
return (fieldName, value: t.InnerText);
89+
return (fieldName, value: (string?) t.InnerText);
7990
}
8091
}
8192

82-
return (fieldName, null);
93+
return (fieldName, value: (string?) null);
8394
})
8495
.ToDictionary(
8596
t => t.fieldName,
8697
t => t.value
8798
);
99+
if (reportFilenamePrefix != null)
100+
{
101+
reportFilenamePrefix = reportFilenamePrefix.TrimEnd('/', '\\');
102+
if (reportFilenamePrefix == string.Empty)
103+
{
104+
reportFilenamePrefix = null;
105+
}
106+
}
88107

89108
var additionalPositionNodes = logRecord
90109
.GetElementsByTagName("Positions")
@@ -96,19 +115,23 @@ string trimFolderName
96115
var filename = t.InnerText;
97116
return lines
98117
.Split(',')
99-
.Select(line => (filename, lineNumber: int.Parse(line.Trim())));
118+
.Select(line => (filename: (string?) filename, lineNumber: int.Parse(line.Trim())));
100119
})
101120
.SelectMany(t => t)
102121
.ToList();
103-
additionalPositionNodes.Add((values["File"], int.Parse(values["Line"])));
122+
additionalPositionNodes.Add((values["File"], int.Parse(values["Line"] ?? "0")));
104123
var results = additionalPositionNodes
105124
.ToHashSet()
106125
.Select(t =>
107126
{
108127
var localFile = "";
109-
if (t.filename != "")
128+
if (!string.IsNullOrEmpty(t.filename))
110129
{
111130
localFile = t.filename.Substring(trimFolderName.Length).TrimStart('/', '\\');
131+
if (reportFilenamePrefix != null)
132+
{
133+
localFile = reportFilenamePrefix + "/" + localFile;
134+
}
112135
}
113136

114137
// ReSharper disable once UseObjectOrCollectionInitializer

pvs2codequality/Options.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
using CommandLine;
1+
using System.Diagnostics.CodeAnalysis;
2+
using CommandLine;
23

34
namespace Pvs2codequality
45
{
6+
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
7+
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
8+
#pragma warning disable 8618
59
public class Options
610
{
711
[Option('i', "input", Required = true, HelpText = "Input plog file")]
812
public string InputFile { get; set; }
913

1014
[Option('o', "output", Required = false, HelpText = "Output json file")]
1115
public string? OutputFile { get; set; }
16+
17+
[Option("report-filename-prefix", Required = false, Default = null,
18+
HelpText = "Prefixes for filename in output report. If null or empty, then no prefixes attach")]
19+
public string? ReportFilenamePrefix { get; set; }
20+
21+
// TODO TrimFolderName
1222
}
23+
#pragma warning restore 8618
1324
}

pvs2codequality/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public static int RunOptionsAndReturnExitCode(Options options)
3838
}
3939

4040
var inputXML = File.ReadAllText(options.InputFile);
41-
var outputJson = XMLConverter.ParseFullDocument(inputXML);
41+
var outputJson = XMLConverter.ParseFullDocument(
42+
inputXML,
43+
trimFolderName: null,
44+
reportFilenamePrefix: options.ReportFilenamePrefix
45+
);
4246
File.WriteAllText(outputFilename, outputJson.result!);
4347
Console.WriteLine(
4448
"File {0} created. {1} lines found",

pvs2codequality/pvs2codequality.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<RootNamespace>Pvs2codequality</RootNamespace>
99
<PackageId>Pvs2codequality</PackageId>
1010
<Authors>Nokita Kaze</Authors>
11-
<Company>Pvs2codequality</Company>
11+
<Company>Nokita Kaze</Company>
1212
<Product>Pvs2codequality</Product>
1313
<IsPackable>false</IsPackable>
14-
<AssemblyVersion>0.1.0</AssemblyVersion>
14+
<AssemblyVersion>0.1.1</AssemblyVersion>
1515
<PackageVersion>0.1.0</PackageVersion>
16-
<FileVersion>0.1.0</FileVersion>
16+
<FileVersion></FileVersion>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)