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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Added extended reports filtering #581

wants to merge 11 commits into from

Conversation

shanshin
Copy link
Collaborator

The following report filtering features have been implemented:

  • include filter by classes annotated with specified annotations
  • include and exclude filters by classes that inherit the specified class or implement the specified interface

Resolves #274
Resolves #454


@Option(
name = "--excludeInheritedFrom",
usage = "filter to exclude classes inheriting the specified class or implementing an interface, wildcards `*` and `?` are acceptable",
Copy link
Member

Choose a reason for hiding this comment

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

[nit] since you differ class and interface, maybe its better to use standard JVM terminology "... extending the specified class or implementing an interface"

@@ -186,17 +186,62 @@ public static class ClassFilters {
*/
public final Set<String> excludeClasses;

/**
* Classes that have at least one of the annotations specified in this field are presents in the report.
* All other classes that are not marked with at least one of the specified annotations are not included in the report.
Copy link
Member

Choose a reason for hiding this comment

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

What happens when both excludeAnnotation and includeAnnotation are specified? I know it is mentioned in markdown docs, but it would nice to have it here also

kover-gradle-plugin/docs/configuring.md Outdated Show resolved Hide resolved
kover-gradle-plugin/docs/configuring.md Outdated Show resolved Hide resolved
@@ -46,12 +46,19 @@ koverReport {
packages("com.another.subpackage")
// excludes all classes and functions, annotated by specified annotations (with BINARY or RUNTIME AnnotationRetention), wildcards '*' and '?' are available
annotatedBy("*Generated*")
// exclude all classes that inherit the specified class or implement the specified interface
inheritedFrom("*Repository")
Copy link
Member

Choose a reason for hiding this comment

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

You specified inheritedFrom("*Repository") in both excludes and includes. This makes the example very strange.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, these docs should be fully rewritten

@@ -37,18 +38,50 @@ internal class ReportAnnotationFilterTests {
}
}
}
}

class Foo : AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

I do not see this class being used in test, accidental leftover?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dark experiments )))

* inheritedFrom("*Repository")
* ```
*
* **_Does not work for JaCoCo_**
Copy link
Member

Choose a reason for hiding this comment

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

I believe that the fact that this doesn't work for JaCoCo should be mentioned in the text in this section: https://github.com/Kotlin/kotlinx-kover/blob/main/kover-gradle-plugin/docs/configuring.md#reports-filtering
Actually, this whole block:

It is acceptable to filter a class from the report by its fully-qualified name - using classes or packages. Also acceptable to filter a class, function or getter marked with the specified annotation - annotatedBy.

needs to be expanded with a new functionality

@shanshin
Copy link
Collaborator Author

Tests will fail for now, until reporter be fixed

@sandwwraith
Copy link
Member

And when reporter will be fixed?

Base automatically changed from features-instead-intellij to main March 27, 2024 18:33
shanshin and others added 9 commits May 4, 2024 19:53
The following report filtering features have been implemented:
- include filter by classes annotated with specified annotations
- include and exclude filters by classes that inherit the specified class or implement the specified interface

Resolves #274
Resolves #454
Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
| --xml <xml-file-path> | generate a XML report in the specified path | | |
| Option | Description | Required | Multiple |
|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|
| `<binary-report-path>` | list of binary reports files | | + |
Copy link
Member

Choose a reason for hiding this comment

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

Maybe binary report files, since we analyzing one report at the time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

<binary-report-path> is a name of multiple parameter, see @Argument(usage = "list of binary reports files", metaVar = "<binary-report-path>").

that is, the user is expected to write something like this /tmp/report1.ic /tmp/report2.ic meaning <binary-report-path> <binary-report-path>

kover-cli/docs/index.md Outdated Show resolved Hide resolved
| --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 | | + |
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be placed next to --exclude?

| --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 | | |
Copy link
Member

Choose a reason for hiding this comment

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

What happens if I specify both --xml and --html? Both reports will be generated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep

kover-gradle-plugin/docs/configuring.md Outdated Show resolved Hide resolved
classCounter("org.jetbrains.RegularClass").assertFullyMissed()
classCounter("org.jetbrains.CloseableClass").assertFullyMissed()

classCounter("org.jetbrains.B").assertAbsent()
Copy link
Member

Choose a reason for hiding this comment

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

Should we add classCounter("org.jetbrains.A").assertFullyMissed() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, forgot it

classCounter("org.jetbrains.CloseableClass").assertAbsent()
classCounter("org.jetbrains.BChild").assertAbsent()
classCounter("org.jetbrains.D").assertAbsent()
classCounter("org.jetbrains.DChild").assertAbsent()
Copy link
Member

Choose a reason for hiding this comment

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

Also classCounter("org.jetbrains.A").assertAbsent()?

Copy link
Member

Choose a reason for hiding this comment

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

I would add to the documentation that using include { inheritedFrom("com.app.A") } would not add A itself to the filter.

@@ -650,19 +651,29 @@ public interface KoverReportFilter {
/**
* Add to filters all classes and functions marked by specified annotations.
*
* Use cases:
* - in case of exclusion filters all classes or function marked by at least one of the specified annotation will be excluded from the report
Copy link
Member

Choose a reason for hiding this comment

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

'all classes or function marked by at least one of the specified annotation will be excluded from the report' and 'classes marked by at least one of the specified annotations will be included in the report' looks like repeating itself. Why do you think that 'Add to filters all classes and functions marked by specified annotations.' is not enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because now you can exclude class and function by annotation, but you can't include function by annotation, only whole class.

/**
* Filter classes extending at least one of the specified classes or implementing at least one of the interfaces.
*
* The entire inheritance tree is analyzed, that is, a class may not extend the specified class directly.
Copy link
Member

Choose a reason for hiding this comment

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

Copy my comments from the similar section in docs

shanshin and others added 2 commits May 8, 2024 18:32
Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
@shanshin shanshin requested a review from sandwwraith May 8, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants