Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extended reports filtering #581

Merged
merged 13 commits into from
May 14, 2024
27 changes: 14 additions & 13 deletions kover-cli/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ For information about offline instrumentation, [see](../offline-instrumentation#
| --include <class-name> | instrument only specified classes, wildcards `*` and `?` are acceptable | | + |

### Generating reports

Allows you to generate HTML and XML reports from the existing binary report.

`java -jar kover-cli.jar report [<binary-report-path> ...] --classfiles <class-file-path> [--exclude <class-name>] [--excludeAnnotation <annotation-name>] [--html <html-dir>] [--include <class-name>] --src <sources-path> [--title <html-title>] [--xml <xml-file-path>]`

| Option | Description | Required | Multiple |
|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|
| `<binary-report-path>` | list of binary reports files | | + |
| --classfiles <class-file-path> | location of the compiled class-files root (must be original and not instrumented) | + | + |
| --exclude <class-name> | filter to exclude classes, wildcards `*` and `?` are acceptable | | + |
| Option | Description | Required | Multiple |
|------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|
| `<binary-report-path>` | list of binary reports files | | + |
| --classfiles <class-file-path> | location of the compiled class-files root (must be original and not instrumented) | + | + |
| --exclude <class-name> | filter to exclude classes, wildcards `*` and `?` are acceptable | | + |
| --include <class-name> | filter to include classes, wildcards `*` and `?` are acceptable | | + |
| --excludeAnnotation <exclude-annotation-name> | filter to exclude classes and functions marked by this annotation, wildcards `*` and `?` are acceptable. Excludes have priority over includes | | + |
| --includeAnnotation <include-annotation-name> | filter to include classes marked by this annotation, wildcards `*` and `?` are acceptable | | + |
| --excludeInheritedFrom <exclude-ancestor-name> | filter to exclude classes extending the specified class or implementing an interface, wildcards `*` and `?` are acceptable | | + |
| --includeInheritedFrom <include-ancestor-name> | filter to include only classes extending the specified class or implementing an interface, wildcards `*` and `?` are acceptable | | + |
| --html <html-dir> | generate a HTML report in the specified path | | |
| --include <class-name> | filter to include classes, wildcards `*` and `?` are acceptable | | + |
| --src <sources-path> | location of the source files root | + | + |
| --title <html-title> | title in the HTML report | | |
| --xml <xml-file-path> | generate a XML report in the specified path | | |
| --includeAnnotation <include-annotation-name> | filter to include classes marked by this annotation, wildcards `*` and `?` are acceptable | | + |
| --excludeInheritedFrom <exclude-ancestor-name> | filter to exclude classes extending the specified class or implementing an interface, wildcards `*` and `?` are acceptable | | + |
| --includeInheritedFrom <include-ancestor-name> | filter to include only classes extending the specified class or implementing an interface, wildcards `*` and `?` are acceptable | | + |
| --html <html-dir> | generate a HTML report in the specified path | | |
| --src <sources-path> | location of the source files root | + | + |
| --title <html-title> | title in the HTML report | | |
| --xml <xml-file-path> | generate a XML report in the specified path | | |
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,21 @@ public data class ClassFilters(
*/
public val includeAnnotation: Set<String>,
/**
* Classes that have at least one of the annotations specified in this field are not filtered.
* Classes that have at least one of the annotations specified in this field are not present in the report.
*
*
* If inclusion and exclusion rules are specified at the same time, then excludes have priority over includes.
* This means that even if a class is annotated both annotations from exclude and include, it will be excluded from the report.
* This means that even if a class is annotated with both annotations from 'exclude' and 'include', it will be excluded from the report.
*
*/
public val excludeAnnotation: Set<String>,
/**
*
* Include only classes extending at least one of the specified classes or implementing at least one of the interfaces.
* The class itself with the specified name is not included in the report.
*
*
* The entire inheritance tree is analyzed; a class may inherit the specified class/interface indirectly and still be included in the report, unless the specified class/interface is located outside of the application (see below).
* The entire inheritance tree is analyzed; a class may inherit the specified class/interface indirectly and still be included in the report, unless the specified class/interface is located outside the application (see below).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of removal was unnecessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted the IDEA to stop highlighting this text :)

Moot point, but I will return of. As I understand it, both options are acceptable.

*
*
* The following classes and interfaces can be specified in arguments:
Expand All @@ -236,19 +237,17 @@ public data class ClassFilters(
/**
*
* Exclude classes extending at least one of the specified classes or implementing at least one of the interfaces.
* The class itself with the specified name is not excluded from the report.
*
*
* The entire inheritance tree is analyzed, that is, a class may not extend the specified class directly.
* Similarly, for the specified interfaces, it is checked that they are implemented directly in the class, or in one of its heirs.
*
* The entire inheritance tree is analyzed; a class may inherit the specified class/interface indirectly and still be included in the report, unless the specified class/interface is located outside the application (see below).
*
* The following classes and interfaces can be specified in arguments:
*
* * classes and interfaces declared in the application
* * classes and interfaces declared outside the application, however they are directly inherited or implemented by any type from the application
*
*
* If specified class or interface that is not declared in the application and that is not extended/implemented directly by one of the application types, then such a filter will have no effect.
* Due to technical limitations, if a specified class or interface is not declared in the application and not extended/implemented directly by one of the application types, such a filter will have no effect.
*/
public val excludeInheritedFrom: Set<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import java.util.regex.Pattern

internal fun ClassFilters.convert(): Filters {
return Filters(
includeClasses.asRegexp(),
excludeClasses.asRegexp(),
includeAnnotation.asRegexp(),
excludeAnnotation.asRegexp(),
includeInheritedFrom.asRegexp(),
excludeInheritedFrom.asRegexp()
includeClasses.toRegexp(),
excludeClasses.toRegexp(),
includeAnnotation.toRegexp(),
excludeAnnotation.toRegexp(),
includeInheritedFrom.toRegexp(),
excludeInheritedFrom.toRegexp()
)
}

private fun Collection<String>.asRegexp(): List<Pattern> {
private fun Collection<String>.toRegexp(): List<Pattern> {
return map { template -> Pattern.compile(template.wildcardsToRegex()) }
}

Expand Down
2 changes: 1 addition & 1 deletion kover-gradle-plugin/docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Exclusion rules are names of the classes that must be excluded from the report.
If inclusion and exclusion rules are specified at the same time, then excludes have priority over includes.
This means that even if a class is specified in both the inclusion and exclusion rules, it will be excluded from the report (e.g. class `com.example.Class1` above).

It is acceptable to filter a class from the report by its fully-qualified name - using `classes` or `packages`.
It is acceptable to filter a class from the report by its fully-qualified name - using `classes`.
Also, you can have additional filter types:
- declarations marked with the specified annotation - `annotatedBy`
- classes extending specified class or implementing specified interface - `inheritedFrom`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal class ReportInheritedFromFilterTests {
xmlReport {
classCounter("org.jetbrains.RegularClass").assertFullyMissed()
classCounter("org.jetbrains.CloseableClass").assertFullyMissed()
classCounter("org.jetbrains.A").assertFullyMissed()

classCounter("org.jetbrains.B").assertAbsent()
sandwwraith marked this conversation as resolved.
Show resolved Hide resolved
classCounter("org.jetbrains.C").assertAbsent()
Expand Down Expand Up @@ -95,6 +96,7 @@ internal class ReportInheritedFromFilterTests {
classCounter("org.jetbrains.RegularClass").assertAbsent()
classCounter("org.jetbrains.CloseableClass").assertAbsent()
classCounter("org.jetbrains.BChild").assertAbsent()
classCounter("org.jetbrains.A").assertAbsent()
classCounter("org.jetbrains.D").assertAbsent()
classCounter("org.jetbrains.DChild").assertAbsent()
sandwwraith marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ public interface KoverReportFilter {

/**
* Filter classes extending at least one of the specified classes or implementing at least one of the interfaces.
* The class itself with the specified name is not taken into account.
*
* The entire inheritance tree is analyzed, that is, a class may not extend the specified class directly.
* Similarly, for the specified interfaces, it is checked that they are implemented directly in the class, or in one of its heirs.
* The entire inheritance tree is analyzed; a class may inherit the specified class/interface indirectly and still be included in the report, unless the specified class/interface is located outside the application (see below).
*
* The following classes and interfaces can be specified in arguments:
* - classes and interfaces declared in the application
Expand All @@ -730,9 +730,9 @@ public interface KoverReportFilter {

/**
* Filter classes extending at least one of the specified classes or implementing at least one of the interfaces.
* The class itself with the specified name is not taken into account.
*
* The entire inheritance tree is analyzed, that is, a class may not extend the specified class directly.
* Similarly, for the specified interfaces, it is checked that they are implemented directly in the class, or in one of its heirs.
* The entire inheritance tree is analyzed; a class may inherit the specified class/interface indirectly and still be included in the report, unless the specified class/interface is located outside the application (see below).
*
* The following classes and interfaces can be specified in arguments:
* - classes and interfaces declared in the application
Expand Down