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

Used compile dependency to Kover Features in Kover Gradle Plugin #574

Merged
merged 6 commits into from
Mar 27, 2024

Conversation

shanshin
Copy link
Collaborator

Since the version of the aggregator and report generator has been enshrined in the Kover Gradle Plugin for a long time, it makes no sense to use dynamic classpath of and classloader isolations in Gradle Workers.

We can use Kover Features as a compile dependency and use its API.

This change can also eliminate the error with access to Freemarker template inside Gradle Worker, and simplify the implementation of warn on verification error.

Resolves #567

Since the version of the aggregator and report generator has been enshrined in the Kover Gradle Plugin for a long time, it makes no sense to use dynamic classpath of and classloader isolations in Gradle Workers.

We can use Kover Features as a compile dependency and use its API.

This change can also eliminate the error with access to Freemarker template inside Gradle Worker, and simplify the implementation of warn on verification error.

Resolves #567
* @param template Template string in Kover format
* @return Regular expression corresponding given Kover template
*/
public static String koverWildcardToRegex(String template) {
Copy link
Member

Choose a reason for hiding this comment

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

Why this function has to be in the public API? Are users of Kover Features (besides our plugin) supposed to call it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's also used in CLI, and I don't see a reason why the user shouldn't be able to use this function - these are not implementation details.

ReportApi.htmlReport(htmlDir, title, null, binaryReports, classfileDirs, sourceDirs, convertFilters(filters));
// repeat reading freemarker temple from resources if error occurred, see https://github.com/Kotlin/kotlinx-kover/issues/510
// the values are selected empirically so that the maximum report generation time is not much more than a second
ReportApi.setFreemarkerRetry(7, 150);
Copy link
Member

Choose a reason for hiding this comment

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

You said that 'This change can also eliminate the error with access to Freemarker template inside Gradle Worker', so maybe we do not need a lot of retries anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, let's try )

/**
* Describes a single bound for the verification rule to enforce
*/
public static class Bound {
Copy link
Member

Choose a reason for hiding this comment

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

These classes were data in Kotlin. Should we add toString() + equals() 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.

It's data class again )

/**
* Violation of verification bound.
*/
public static class BoundViolation {
Copy link
Member

Choose a reason for hiding this comment

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

I think toString() will be especially beneficial for *Violation classes in case someone would like to print list with results

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's data class again )

kover-features-jvm/build.gradle.kts Outdated Show resolved Hide resolved
/**
* Verify coverage by specified verification rules.
*
* @param tempDir Directory to create temporary files
Copy link
Member

Choose a reason for hiding this comment

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

@param rules is undocumented

MISSED_PERCENTAGE
}

public data class CoverageValue(val entityName: String?, val value: BigDecimal)
Copy link
Member

Choose a reason for hiding this comment

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

Undocumented

for (ruleIndex in rules.indices) {
val rule = rules[ruleIndex]

val bounds: MutableList<com.intellij.rt.coverage.verify.api.Bound> = ArrayList()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val bounds: MutableList<com.intellij.rt.coverage.verify.api.Bound> = ArrayList()
val bounds: MutableList<IntellijBound> = ArrayList()

return aggregationType == AggregationType.COVERED_PERCENTAGE || aggregationType == AggregationType.MISSED_PERCENTAGE
}

private class ViolationId(private val index: Int, private val entityName: String?) : Comparable<ViolationId> {
Copy link
Member

Choose a reason for hiding this comment

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

TreeMap only requires Comparable, but shouldn't we add equals/hashCode anyway just in case? Or simply make this class data?

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 TreeMap guarantees order, in this case, the validation result will always be stable and predictable.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. I'm talking about making it data class while also being Comparable in case we want to use it tostring or equals for e.g. testing purposes

CoverageUnit.INSTRUCTION -> "instructions"
CoverageUnit.BRANCH -> "branches"
val metricText = when (bound.coverageUnits) {
kotlinx.kover.features.jvm.CoverageUnit.LINE -> "lines"
Copy link
Member

Choose a reason for hiding this comment

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

Redundant fq import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Create alias


internal fun CoverageUnit.convert(): kotlinx.kover.features.jvm.CoverageUnit {
return when (this) {
CoverageUnit.LINE -> kotlinx.kover.features.jvm.CoverageUnit.LINE
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use classes from kotlinx.kover.features.jvm. directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Create alias

jvmTarget.set(JvmTarget.JVM_1_8)
languageVersion.set(KotlinVersion.KOTLIN_1_5)
apiVersion.set(KotlinVersion.KOTLIN_1_5)
freeCompilerArgs.add("-Xsuppress-version-warnings")
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 use also -Xjdk-release 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.

I'm not sure if this is necessary, the class files are now 52 versions.
I think jvmTarget.set(JvmTarget.JVM_1_8) is enough

Copy link
Member

Choose a reason for hiding this comment

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

It's not about a class file version, it's about JDK API. To prevent errors like this one: Kotlin/kotlinx.serialization#2328

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, let it be

@shanshin shanshin merged commit 8af377c into main Mar 27, 2024
@shanshin shanshin deleted the features-instead-intellij branch March 27, 2024 18:33
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.

Use compile dependency to Kover Features in Kover Gradle Plugin
2 participants