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 all 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.

136 changes: 136 additions & 0 deletions kover-features-jvm/api/kover-features-jvm.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
public final class kotlinx/kover/features/jvm/AggregationType : java/lang/Enum {
public static final field COVERED_COUNT Lkotlinx/kover/features/jvm/AggregationType;
public static final field COVERED_PERCENTAGE Lkotlinx/kover/features/jvm/AggregationType;
public static final field MISSED_COUNT Lkotlinx/kover/features/jvm/AggregationType;
public static final field MISSED_PERCENTAGE Lkotlinx/kover/features/jvm/AggregationType;
public static fun valueOf (Ljava/lang/String;)Lkotlinx/kover/features/jvm/AggregationType;
public static fun values ()[Lkotlinx/kover/features/jvm/AggregationType;
}

public final class kotlinx/kover/features/jvm/Bound {
public fun <init> (Ljava/math/BigDecimal;Ljava/math/BigDecimal;Lkotlinx/kover/features/jvm/CoverageUnit;Lkotlinx/kover/features/jvm/AggregationType;)V
public final fun component1 ()Ljava/math/BigDecimal;
public final fun component2 ()Ljava/math/BigDecimal;
public final fun component3 ()Lkotlinx/kover/features/jvm/CoverageUnit;
public final fun component4 ()Lkotlinx/kover/features/jvm/AggregationType;
public final fun copy (Ljava/math/BigDecimal;Ljava/math/BigDecimal;Lkotlinx/kover/features/jvm/CoverageUnit;Lkotlinx/kover/features/jvm/AggregationType;)Lkotlinx/kover/features/jvm/Bound;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/Bound;Ljava/math/BigDecimal;Ljava/math/BigDecimal;Lkotlinx/kover/features/jvm/CoverageUnit;Lkotlinx/kover/features/jvm/AggregationType;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/Bound;
public fun equals (Ljava/lang/Object;)Z
public final fun getAggregationForGroup ()Lkotlinx/kover/features/jvm/AggregationType;
public final fun getCoverageUnits ()Lkotlinx/kover/features/jvm/CoverageUnit;
public final fun getMaxValue ()Ljava/math/BigDecimal;
public final fun getMinValue ()Ljava/math/BigDecimal;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/BoundViolation {
public fun <init> (Lkotlinx/kover/features/jvm/Bound;ZLjava/math/BigDecimal;Ljava/lang/String;)V
public final fun component1 ()Lkotlinx/kover/features/jvm/Bound;
public final fun component2 ()Z
public final fun component3 ()Ljava/math/BigDecimal;
public final fun component4 ()Ljava/lang/String;
public final fun copy (Lkotlinx/kover/features/jvm/Bound;ZLjava/math/BigDecimal;Ljava/lang/String;)Lkotlinx/kover/features/jvm/BoundViolation;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/BoundViolation;Lkotlinx/kover/features/jvm/Bound;ZLjava/math/BigDecimal;Ljava/lang/String;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/BoundViolation;
public fun equals (Ljava/lang/Object;)Z
public final fun getBound ()Lkotlinx/kover/features/jvm/Bound;
public final fun getEntityName ()Ljava/lang/String;
public final fun getValue ()Ljava/math/BigDecimal;
public fun hashCode ()I
public final fun isMax ()Z
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/ClassFilters {
public fun <init> (Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;)V
public final fun component1 ()Ljava/util/Set;
public final fun component2 ()Ljava/util/Set;
public final fun component3 ()Ljava/util/Set;
public final fun copy (Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;)Lkotlinx/kover/features/jvm/ClassFilters;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/ClassFilters;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/ClassFilters;
public fun equals (Ljava/lang/Object;)Z
public final fun getExcludeAnnotation ()Ljava/util/Set;
public final fun getExcludeClasses ()Ljava/util/Set;
public final fun getIncludeClasses ()Ljava/util/Set;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/CoverageUnit : java/lang/Enum {
public static final field BRANCH Lkotlinx/kover/features/jvm/CoverageUnit;
public static final field INSTRUCTION Lkotlinx/kover/features/jvm/CoverageUnit;
public static final field LINE Lkotlinx/kover/features/jvm/CoverageUnit;
public static fun valueOf (Ljava/lang/String;)Lkotlinx/kover/features/jvm/CoverageUnit;
public static fun values ()[Lkotlinx/kover/features/jvm/CoverageUnit;
}

public final class kotlinx/kover/features/jvm/CoverageValue {
public fun <init> (Ljava/lang/String;Ljava/math/BigDecimal;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/math/BigDecimal;
public final fun copy (Ljava/lang/String;Ljava/math/BigDecimal;)Lkotlinx/kover/features/jvm/CoverageValue;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/CoverageValue;Ljava/lang/String;Ljava/math/BigDecimal;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/CoverageValue;
public fun equals (Ljava/lang/Object;)Z
public final fun getEntityName ()Ljava/lang/String;
public final fun getValue ()Ljava/math/BigDecimal;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/GroupingBy : java/lang/Enum {
public static final field APPLICATION Lkotlinx/kover/features/jvm/GroupingBy;
public static final field CLASS Lkotlinx/kover/features/jvm/GroupingBy;
public static final field PACKAGE Lkotlinx/kover/features/jvm/GroupingBy;
public static fun valueOf (Ljava/lang/String;)Lkotlinx/kover/features/jvm/GroupingBy;
public static fun values ()[Lkotlinx/kover/features/jvm/GroupingBy;
}

public final class kotlinx/kover/features/jvm/KoverFeatures {
public static final field INSTANCE Lkotlinx/kover/features/jvm/KoverFeatures;
public final fun createOfflineInstrumenter ()Lkotlinx/kover/features/jvm/OfflineInstrumenter;
public final fun getVersion ()Ljava/lang/String;
public final fun koverWildcardToRegex (Ljava/lang/String;)Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/KoverLegacyFeatures {
public static final field INSTANCE Lkotlinx/kover/features/jvm/KoverLegacyFeatures;
public final fun aggregateIc (Ljava/io/File;Lkotlinx/kover/features/jvm/ClassFilters;Ljava/io/File;Ljava/util/List;Ljava/util/List;)V
public final fun evalCoverage (Lkotlinx/kover/features/jvm/GroupingBy;Lkotlinx/kover/features/jvm/CoverageUnit;Lkotlinx/kover/features/jvm/AggregationType;Ljava/io/File;Lkotlinx/kover/features/jvm/ClassFilters;Ljava/util/List;Ljava/util/List;)Ljava/util/List;
public final fun generateHtmlReport (Ljava/io/File;Ljava/lang/String;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Lkotlinx/kover/features/jvm/ClassFilters;)V
public final fun generateXmlReport (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Lkotlinx/kover/features/jvm/ClassFilters;)V
public final fun instrument (Ljava/io/File;Ljava/util/List;Lkotlinx/kover/features/jvm/ClassFilters;Z)V
public final fun verify (Ljava/util/List;Ljava/io/File;Lkotlinx/kover/features/jvm/ClassFilters;Ljava/util/List;Ljava/util/List;)Ljava/util/List;
}

public abstract interface class kotlinx/kover/features/jvm/OfflineInstrumenter {
public abstract fun instrument (Ljava/io/InputStream;Ljava/lang/String;)[B
}

public final class kotlinx/kover/features/jvm/Rule {
public fun <init> (Ljava/lang/String;Lkotlinx/kover/features/jvm/GroupingBy;Ljava/util/List;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lkotlinx/kover/features/jvm/GroupingBy;
public final fun component3 ()Ljava/util/List;
public final fun copy (Ljava/lang/String;Lkotlinx/kover/features/jvm/GroupingBy;Ljava/util/List;)Lkotlinx/kover/features/jvm/Rule;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/Rule;Ljava/lang/String;Lkotlinx/kover/features/jvm/GroupingBy;Ljava/util/List;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/Rule;
public fun equals (Ljava/lang/Object;)Z
public final fun getBounds ()Ljava/util/List;
public final fun getGroupBy ()Lkotlinx/kover/features/jvm/GroupingBy;
public final fun getName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/kover/features/jvm/RuleViolations {
public fun <init> (Lkotlinx/kover/features/jvm/Rule;Ljava/util/List;)V
public final fun component1 ()Lkotlinx/kover/features/jvm/Rule;
public final fun component2 ()Ljava/util/List;
public final fun copy (Lkotlinx/kover/features/jvm/Rule;Ljava/util/List;)Lkotlinx/kover/features/jvm/RuleViolations;
public static synthetic fun copy$default (Lkotlinx/kover/features/jvm/RuleViolations;Lkotlinx/kover/features/jvm/Rule;Ljava/util/List;ILjava/lang/Object;)Lkotlinx/kover/features/jvm/RuleViolations;
public fun equals (Ljava/lang/Object;)Z
public final fun getRule ()Lkotlinx/kover/features/jvm/Rule;
public final fun getViolations ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

31 changes: 28 additions & 3 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,7 +19,8 @@
*/

plugins {
java
kotlin("jvm")
alias(libs.plugins.kotlinx.binaryCompatibilityValidator)
id("kover-publishing-conventions")
}

Expand All @@ -24,8 +29,28 @@ extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtensi
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.compileJava {
options.release.set(8)
}

// 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.addAll("-Xsuppress-version-warnings", "-Xjdk-release=1.8")
}
}
}

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
}
}
Loading