Class MavenProfilerToCsv

java.lang.Object
de.oktoflow.platform.cmdTools.MavenProfilerToCsv

public final class MavenProfilerToCsv extends Object
Converts one or more Maven Profiler JSON reports into a CSV file that can be imported into spreadsheet applications such as Microsoft Excel or LibreOffice Calc.

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
    Modifier and Type
    Field
    Description
    private static final com.fasterxml.jackson.databind.ObjectMapper
     
    private static final char
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Prevents external creation.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    Converts a single Maven Profiler JSON report into CSV rows.
    private static String
    csv(String value)
    Escapes a value according to RFC 4180 CSV rules.
    private static List<Path>
    Determines the profiler report files to be converted.
    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.
    private static String
    firstText(com.fasterxml.jackson.databind.JsonNode parent, String... fieldNames)
    Returns the textual value of the first existing field.
    static void
    main(String[] args)
    Converts one or more Maven Profiler JSON reports into a CSV file.
    private static String
    milliseconds(com.fasterxml.jackson.databind.JsonNode value)
    Converts a profiler time value into milliseconds.
    private static String
    Formats a numeric string by removing an unnecessary fractional part.
    private static String
    Relativizes the given path with respect to user.dir.
    private static String
    text(com.fasterxml.jackson.databind.JsonNode parent, String fieldName)
    Returns the textual value of a field.
    private static void
    writeRow(BufferedWriter writer, String... values)
    Writes a single CSV row.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void main(String[] args)
      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:
      1. the JSON report file or directory
      2. the output CSV file
    • findReports

      private static List<Path> findReports(Path input) throws IOException
      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

      private static String realizive(Path path)
      Relativizes the given path with respect to user.dir.
      Parameters:
      path - the path
      Returns:
      path or the sub-path of path in user.dir
    • convertReport

      private static void convertReport(Path report, BufferedWriter writer) throws IOException
      Converts a single Maven Profiler JSON report into CSV rows.
      Parameters:
      report - the profiler report to convert
      writer - 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 node
      fieldNames - the candidate field names in lookup order
      Returns:
      the first matching node or null if 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 node
      fieldNames - the candidate field names in lookup order
      Returns:
      the field value or the empty string if no matching field exists
    • text

      private static String text(com.fasterxml.jackson.databind.JsonNode parent, String fieldName)
      Returns the textual value of a field.
      Parameters:
      parent - the parent JSON node
      fieldName - the field name
      Returns:
      the field value or the empty string if the field is missing
    • milliseconds

      private static String milliseconds(com.fasterxml.jackson.databind.JsonNode value)
      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

      private static String normalizeNumber(String value)
      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

      private static void writeRow(BufferedWriter writer, String... values) throws IOException
      Writes a single CSV row.
      Parameters:
      writer - the destination writer
      values - the column values
      Throws:
      IOException - if writing fails
    • csv

      private static String csv(String value)
      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