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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package kotlinx.kover.cli.commands

import kotlinx.kover.cli.util.asRegex
import kotlinx.kover.features.jvm.ClassFilters
import kotlinx.kover.features.jvm.KoverLegacyFeatures
import org.kohsuke.args4j.Argument
import org.kohsuke.args4j.Option
Expand Down Expand Up @@ -62,10 +62,10 @@ internal class OfflineInstrumentCommand : Command {


override fun call(output: PrintWriter, errorWriter: PrintWriter): Int {
val filters = KoverLegacyFeatures.ClassFilters(
includeClasses.asRegex().toSet(),
excludeClasses.asRegex().toSet(),
excludeAnnotation.asRegex().toSet()
val filters = ClassFilters(
includeClasses.toSet(),
excludeClasses.toSet(),
excludeAnnotation.toSet()
)

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package kotlinx.kover.cli.commands

import kotlinx.kover.cli.util.asRegex
import kotlinx.kover.features.jvm.ClassFilters
import kotlinx.kover.features.jvm.KoverLegacyFeatures
import kotlinx.kover.features.jvm.KoverLegacyFeatures.ClassFilters
import org.kohsuke.args4j.Argument
import org.kohsuke.args4j.Option
import java.io.File
Expand Down Expand Up @@ -78,23 +77,23 @@ internal class ReportCommand : Command {

override fun call(output: PrintWriter, errorWriter: PrintWriter): Int {
val filters = ClassFilters(
includeClasses.asRegex().toSet(),
excludeClasses.asRegex().toSet(),
excludeAnnotation.asRegex().toSet()
includeClasses.toSet(),
excludeClasses.toSet(),
excludeAnnotation.toSet()
)

var fail = false
if (xmlFile != null) {
try {
KoverLegacyFeatures.generateXmlReport(xmlFile, binaryReports, outputRoots, sourceRoots, title ?: "Kover XML Report", filters)
KoverLegacyFeatures.generateXmlReport(xmlFile!!, binaryReports, outputRoots, sourceRoots, title ?: "Kover XML Report", filters)
} catch (e: IOException) {
fail = true
errorWriter.println("XML generation failed: " + e.message)
}
}
if (htmlDir != null) {
try {
KoverLegacyFeatures.generateHtmlReport(htmlDir, binaryReports, outputRoots, sourceRoots, title ?: "Kover HTML Report", filters)
KoverLegacyFeatures.generateHtmlReport(htmlDir!!, null, binaryReports, outputRoots, sourceRoots, title ?: "Kover HTML Report", filters)
} catch (e: IOException) {
fail = true
errorWriter.println("HTML generation failed: " + e.message)
Expand Down
41 changes: 0 additions & 41 deletions kover-cli/src/main/kotlin/kotlinx/kover/cli/util/KoverUtils.kt

This file was deleted.

29 changes: 25 additions & 4 deletions kover-features-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/*
* Copyright 2000-2024 JetBrains s.r.o.
*
Expand All @@ -15,17 +19,34 @@
*/

plugins {
java
kotlin("jvm")
id("kover-publishing-conventions")
}

extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtension> {
description.set("Implementation of calling the main features of Kover programmatically")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
sandwwraith marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Workaround:
// `kotlin-dsl` itself specifies the language version to ensure compatibility of the Kotlin DSL API
// Since we ourselves guarantee and test compatibility with previous Gradle versions, we can override language version
// The easiest way to do this now is to specify the version in the `afterEvaluate` block
afterEvaluate {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
allWarningsAsErrors.set(true)
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

}
}
}

repositories {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.kover.features.jvm

import kotlinx.kover.features.jvm.impl.OfflineInstrumenterImpl
import kotlinx.kover.features.jvm.impl.wildcardsToRegex
import java.util.*

/**
* A class for using features via Java calls.
*/
public object KoverFeatures {
/**
* Getting version of Kover used in these utilities.
*/
public val version: String = readVersion()

/**
* Converts a Kover [template] string to a regular expression string.
* Replaces characters `*` to `.*`, `#` to `[^.]*` and `?` to `.` regexp characters.
* All special characters of regular expressions are also escaped.
*/
public fun koverWildcardToRegex(template: String): String {
return template.wildcardsToRegex()
}

/**
* Create instance to instrument already compiled class-files.
*
* @return instrumenter for offline instrumentation.
*/
public fun createOfflineInstrumenter(): OfflineInstrumenter {
sandwwraith marked this conversation as resolved.
Show resolved Hide resolved
return OfflineInstrumenterImpl(false)
}

private fun readVersion(): String {
var version = "unrecognized"
// read version from file in resources
try {
KoverFeatures::class.java.classLoader.getResourceAsStream("kover.version").use { stream ->
if (stream != null) {
version = Scanner(stream).nextLine()
}
}
} catch (e: Throwable) {
// can't read
}
return version
}
}

This file was deleted.

Loading