Class MinimalReportGenerator
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents the coverage of all covered classes in a report.static interfaceRepresents the coverage of a single method as a list of covered source line numbers.static interfaceRepresents the coverage of all covered methods within a single class. -
Method Summary
Modifier and TypeMethodDescriptionaggregateClassCoverage(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.aggregateMethodCoverage(IMethodCoverage methodCoverage) Aggregates the covered source line numbers for a single method.static Collection<IClassCoverage>analyzeCoverage(List<String> execFiles, List<String> classFiles) Loads execution data from the provided JaCoCo*.execfiles and analyzes the supplied class files to produce a collection ofIClassCoverageobjects.generateReport(List<String> execFiles, List<String> classFiles) Generates the in-memory coverage report structure for the given JaCoCo execution files and class files.static voidEntry point for the minimal report generator CLI.static FilewriteReport(MinimalReportGenerator.ClassesCoverage report, String outPath) Serializes the generated report structure to the given filesystem path as a pretty (but compact object entries) JSON file.
-
Method Details
-
main
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
--classfilesare treated as paths to JaCoCo*.execfiles. - All arguments after
--classfilesare 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)
- All arguments before
-
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 -> linesoutPath- path to the output JSON file to write- Returns:
- the
Fileinstance 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.ClassesCoveragewhere 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 JaCoCoIClassCoverageobjects and toaggregateClassCoverage(IClassCoverage)to compute per-method coverage.- Parameters:
execFiles- list of paths to JaCoCo*.execfiles; must contain at least one entryclassFiles- 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*.execfiles and analyzes the supplied class files to produce a collection ofIClassCoverageobjects.Validation and behavior:
- Each path in
execFilesandclassFilesmust refer to an existing file; if a file does not exist anIllegalArgumentExceptionis thrown. - Exec files are loaded into an
ExecFileLoaderand then analyzed together using anAnalyzerbacked by aCoverageBuilder.
- Parameters:
execFiles- list of JaCoCo execution file paths to loadclassFiles- list of class file paths or directories to analyze- Returns:
- collection of
IClassCoverageinstances representing the analyzed classes (may be empty if no classes matched) - Throws:
IOException- if an I/O error occurs while reading filesIllegalArgumentException- if any provided path does not exist- See Also:
- Each path in
-
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- JaCoCoIClassCoveragedescribing 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 isICounter.FULLY_COVEREDorICounter.PARTLY_COVEREDare 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- JaCoCoIMethodCoveragedescribing 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:
-