-
Notifications
You must be signed in to change notification settings - Fork 52
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
Conversation
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/src/main/java/kotlinx/kover/features/jvm/KoverFeatures.kt
Show resolved
Hide resolved
kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/KoverLegacyFeatures.kt
Show resolved
Hide resolved
kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/KoverLegacyFeatures.kt
Show resolved
Hide resolved
/** | ||
* Verify coverage by specified verification rules. | ||
* | ||
* @param tempDir Directory to create temporary files |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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> { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant fq import?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create alias
779e192
to
56bf463
Compare
kover-features-jvm/build.gradle.kts
Outdated
jvmTarget.set(JvmTarget.JVM_1_8) | ||
languageVersion.set(KotlinVersion.KOTLIN_1_5) | ||
apiVersion.set(KotlinVersion.KOTLIN_1_5) | ||
freeCompilerArgs.add("-Xsuppress-version-warnings") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Release flag of Javac should be used for the same reason (https://docs.gradle.org/current/userguide/building_java_projects.html#sec:compiling_with_release)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let it be
kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/KoverLegacyFeatures.kt
Show resolved
Hide resolved
c449c95
to
6e49c2e
Compare
6e49c2e
to
198a96d
Compare
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