Class MinimalReportGenerator

java.lang.Object
fr.bl.drit.jacoco.report.MinimalReportGenerator

public class MinimalReportGenerator extends Object
Minimal utility to generate a compact JSON coverage report from JaCoCo execution (".exec") files and Java class files.

The produced JSON maps fully-qualified class names to a mapping of method identifiers to a list of covered source line numbers:

{
   "com.example.MyClass": {
     "myMethod(Ljava/lang/String;)V": [12, 13, 20],
     "otherMethod()I": [45]
   },
   ...
 }

Only classes and methods that have at least one covered instruction are included. Method identifiers are composed of the method name and descriptor.

  • Method Details

    • main

      public static void main(String[] args) throws IOException
      Entry point for the minimal report generator CLI.

      Accepted command-line form:

       java -jar jacococli-minimal-report.jar <execfiles> ... --classfiles <path> ... --json <file>
       
      • All arguments before --classfiles are treated as paths to JaCoCo *.exec files.
      • All arguments after --classfiles are treated as paths to Java class files or directories containing class files.
      • The --json <file> option is required and specifies the output JSON file to write.
      • If required arguments are missing, the process prints usage and exits with status 2.
      Parameters:
      args - command-line arguments as described above
      Throws:
      IOException - if an unexpected error occurs during analysis or writing the output file (propagates underlying I/O or analysis exceptions)
    • writeReport

      public static File writeReport(MinimalReportGenerator.ClassesCoverage report, String outPath) throws IOException
      Serializes the generated report structure to the given filesystem path as a pretty (but compact object entries) JSON file.

      The writer configuration attempts to minimize spaces inside object entries while preserving readable array indentation.

      Parameters:
      report - the coverage report mapping class -> method -> lines
      outPath - path to the output JSON file to write
      Returns:
      the File instance pointing to the written file
      Throws:
      IOException - if writing the file fails
      See Also:
    • generateReport

      public static MinimalReportGenerator.ClassesCoverage generateReport(List<String> execFiles, List<String> classFiles) throws IOException
      Generates the in-memory coverage report structure for the given JaCoCo execution files and class files.

      The returned map has the shape MinimalReportGenerator.ClassesCoverage where the top-level key is the fully-qualified class name (dot-separated), the second-level key is the method identifier (method name + descriptor), and the list contains covered source line numbers for that method (empty list if there is no debug information).

      Only classes with at least one covered instruction are included. The implementation delegates to analyzeCoverage(List, List) to obtain JaCoCo IClassCoverage objects and to aggregateClassCoverage(IClassCoverage) to compute per-method coverage.

      Parameters:
      execFiles - list of paths to JaCoCo *.exec files; must contain at least one entry
      classFiles - list of paths to class files or directories containing class files; must contain at least one entry
      Returns:
      the aggregated coverage report mapping classes -> methods -> lines
      Throws:
      IOException - if reading execution or class files fails
    • analyzeCoverage

      public static Collection<IClassCoverage> analyzeCoverage(List<String> execFiles, List<String> classFiles) throws IOException
      Loads execution data from the provided JaCoCo *.exec files and analyzes the supplied class files to produce a collection of IClassCoverage objects.

      Validation and behavior:

      Parameters:
      execFiles - list of JaCoCo execution file paths to load
      classFiles - list of class file paths or directories to analyze
      Returns:
      collection of IClassCoverage instances representing the analyzed classes (may be empty if no classes matched)
      Throws:
      IOException - if an I/O error occurs while reading files
      IllegalArgumentException - if any provided path does not exist
      See Also:
    • aggregateClassCoverage

      public static MinimalReportGenerator.MethodsCoverage aggregateClassCoverage(IClassCoverage classCoverage)
      Aggregates coverage information for a single class into a map from method identifier to a list of covered source line numbers for that method.

      Method selection and identifier format:

      • Only methods that have at least one covered instruction are included.
      • The method identifier is composed of the method name and descriptor.

      This method delegates to aggregateMethodCoverage(IMethodCoverage) to compute per-method covered line lists.

      Parameters:
      classCoverage - JaCoCo IClassCoverage describing the class
      Returns:
      a map whose keys are method identifiers and whose values are lists of covered source line numbers; may be empty if no methods qualify
    • aggregateMethodCoverage

      public static MinimalReportGenerator.LinesCoverage aggregateMethodCoverage(IMethodCoverage methodCoverage)
      Aggregates the covered source line numbers for a single method. Lines whose status is ICounter.FULLY_COVERED or ICounter.PARTLY_COVERED are added to the returned list.

      If the method has no source line debug information, an empty list is returned, effectively considering the whole method as covered but without line granularity.

      Parameters:
      methodCoverage - JaCoCo IMethodCoverage describing the method
      Returns:
      ordered list of covered source line numbers within the method's [firstLine, lastLine] interval; may be empty if no line information exists
      See Also: