Class MavenProfilerToCsv
The converter accepts either a single JSON report or a directory
containing multiple reports. In the latter case, all *.json files are
processed recursively and combined into a single CSV file.
The generated CSV contains one row per executed Maven mojo. Build-level and project-level information is repeated for each mojo execution to simplify filtering, sorting and the creation of pivot tables.
The output uses UTF-8 encoding with a BOM and semicolons as separators, which provides good compatibility with Excel in locales where commas are used as decimal separators.
Example:
java profiler.MavenProfilerToCsv \
target/profiler \
target/profiler-results.csv
- Author:
- ChatGPT, javadoc copied into as output window too small
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidconvertReport(Path report, BufferedWriter writer) Converts a single Maven Profiler JSON report into CSV rows.private static StringEscapes a value according to RFC 4180 CSV rules.findReports(Path input) Determines the profiler report files to be converted.private static com.fasterxml.jackson.databind.JsonNodeReturns the first existing child node for the given field names.private static StringReturns the textual value of the first existing field.static voidConverts one or more Maven Profiler JSON reports into a CSV file.private static Stringmilliseconds(com.fasterxml.jackson.databind.JsonNode value) Converts a profiler time value into milliseconds.private static StringnormalizeNumber(String value) Formats a numeric string by removing an unnecessary fractional part.private static StringRelativizes the givenpathwith respect touser.dir.private static StringReturns the textual value of a field.private static voidwriteRow(BufferedWriter writer, String... values) Writes a single CSV row.
-
Field Details
-
JSON
private static final com.fasterxml.jackson.databind.ObjectMapper JSON -
SEPARATOR
private static final char SEPARATOR- See Also:
-
-
Constructor Details
-
MavenProfilerToCsv
private MavenProfilerToCsv()Prevents external creation.
-
-
Method Details
-
main
Converts one or more Maven Profiler JSON reports into a CSV file.The first argument specifies either a single JSON report or a directory containing JSON reports. The second argument specifies the CSV file to be created.
- Parameters:
args- the command line arguments:- the JSON report file or directory
- the output CSV file
-
findReports
Determines the profiler report files to be converted.- Parameters:
input- the input file or directory- Returns:
- the JSON report files to process
- Throws:
IOException- if the input does not exist or the directory cannot be traversed
-
realizive
Relativizes the givenpathwith respect touser.dir.- Parameters:
path- the path- Returns:
pathor the sub-path ofpathinuser.dir
-
convertReport
Converts a single Maven Profiler JSON report into CSV rows.- Parameters:
report- the profiler report to convertwriter- the destination CSV writer- Throws:
IOException- if the report cannot be read or the CSV cannot be written
-
firstNode
private static com.fasterxml.jackson.databind.JsonNode firstNode(com.fasterxml.jackson.databind.JsonNode parent, String... fieldNames) Returns the first existing child node for the given field names.This method supports different JSON schema versions by trying multiple alternative field names.
- Parameters:
parent- the parent JSON nodefieldNames- the candidate field names in lookup order- Returns:
- the first matching node or
nullif none exists
-
firstText
private static String firstText(com.fasterxml.jackson.databind.JsonNode parent, String... fieldNames) Returns the textual value of the first existing field.- Parameters:
parent- the parent JSON nodefieldNames- the candidate field names in lookup order- Returns:
- the field value or the empty string if no matching field exists
-
text
Returns the textual value of a field.- Parameters:
parent- the parent JSON nodefieldName- the field name- Returns:
- the field value or the empty string if the field is missing
-
milliseconds
Converts a profiler time value into milliseconds.Supported input formats include numeric JSON values as well as textual representations such as
"30706 ms"or"1.25 s".If an unknown format is encountered, the original value is returned unchanged so that timing information is not lost.
- Parameters:
value- the JSON value representing a duration- Returns:
- the duration in milliseconds or the original value if it cannot be interpreted
-
normalizeNumber
Formats a numeric string by removing an unnecessary fractional part.For example,
"42.0"becomes"42"while"42.5"remains unchanged.- Parameters:
value- the numeric string- Returns:
- the normalized representation
-
writeRow
Writes a single CSV row.- Parameters:
writer- the destination writervalues- the column values- Throws:
IOException- if writing fails
-
csv
Escapes a value according to RFC 4180 CSV rules.Values containing separators, quotation marks or line breaks are enclosed in quotation marks. Embedded quotation marks are escaped by duplication.
- Parameters:
value- the value to escape- Returns:
- the escaped CSV representation
-