Skip to content

Commit

Permalink
Implemented Worker API for use with Kover toolset
Browse files Browse the repository at this point in the history
Using the Worker API allows directly call the methods of the Kover tool's classes, bypassing the serialization and deserialization of arguments in JSON and passing them to a separately running JVM process.

PR #357
  • Loading branch information
shanshin committed May 31, 2023
1 parent ea29b9f commit bbc0560
Show file tree
Hide file tree
Showing 34 changed files with 452 additions and 900 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies {

compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")

compileOnly("org.jetbrains.intellij.deps:intellij-coverage-reporter:1.0.719")

testImplementation(kotlin("test"))

"functionalTestImplementation"("org.junit.jupiter:junit-jupiter:5.9.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ plugins {
id("org.jetbrains.kotlinx.kover")
}

repositories { mavenCentral() }
repositories {
mavenCentral()
}

dependencies {
kover(project(":subprojects:alpha-project"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ plugins {
id("org.jetbrains.kotlinx.kover")
}

repositories { mavenCentral() }
repositories {
mavenCentral()
}

dependencies {
testImplementation(kotlin("test"))
Expand Down
22 changes: 18 additions & 4 deletions src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/Artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package kotlinx.kover.gradle.plugin.appliers

import kotlinx.kover.gradle.plugin.commons.AppliedKotlinPlugin
import kotlinx.kover.gradle.plugin.commons.Variant
import kotlinx.kover.gradle.plugin.commons.ArtifactNameAttr
import kotlinx.kover.gradle.plugin.commons.CompilationUnit
import kotlinx.kover.gradle.plugin.commons.KotlinPluginAttr
Expand All @@ -19,11 +18,15 @@ import kotlinx.kover.gradle.plugin.commons.localArtifactConfigurationName
import kotlinx.kover.gradle.plugin.commons.rawReportName
import kotlinx.kover.gradle.plugin.commons.rawReportsRootPath
import kotlinx.kover.gradle.plugin.dsl.KoverNames.DEPENDENCY_CONFIGURATION_NAME
import kotlinx.kover.gradle.plugin.tasks.internal.KoverArtifactGenerationTask
import kotlinx.kover.gradle.plugin.tasks.services.KoverArtifactGenerationTask
import kotlinx.kover.gradle.plugin.tools.CoverageToolVariant
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskCollection
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
Expand Down Expand Up @@ -60,7 +63,7 @@ internal fun Project.createArtifactGenerationTask(
dependsOn(compileTasks)

this.sources.from(sources)
this.outputs.from(outputs)
this.outputDirs.from(outputs)
this.reports.from(rawReportFiles)
this.artifactFile.set(localArtifactFile)
}
Expand Down Expand Up @@ -90,4 +93,15 @@ internal fun Project.createArtifactGenerationTask(
}

return Variant(variantName, localArtifactFile, artifactGenTask, local, dependencies)
}
}

/**
* Comprehensive information sufficient to generate a variant of the report.
*/
internal class Variant(
val name: String,
val localArtifact: Provider<RegularFile>,
val localArtifactGenerationTask: TaskProvider<KoverArtifactGenerationTask>,
val localArtifactConfiguration: NamedDomainObjectProvider<Configuration>,
val dependentArtifactsConfiguration: NamedDomainObjectProvider<Configuration>
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.kover.gradle.plugin.dsl.KoverNames.REPORT_EXTENSION_NAME
import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl
import kotlinx.kover.gradle.plugin.dsl.internal.KoverReportExtensionImpl
import kotlinx.kover.gradle.plugin.locators.CompilationsLocatorFactory
import kotlinx.kover.gradle.plugin.tasks.internal.KoverAgentJarTask
import kotlinx.kover.gradle.plugin.tasks.services.KoverAgentJarTask
import kotlinx.kover.gradle.plugin.tools.CoverageTool
import kotlinx.kover.gradle.plugin.tools.CoverageToolFactory
import kotlinx.kover.gradle.plugin.tools.CoverageToolVariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ package kotlinx.kover.gradle.plugin.appliers

import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.*
import kotlinx.kover.gradle.plugin.tasks.*
import kotlinx.kover.gradle.plugin.tasks.reports.AbstractKoverReportTask
import kotlinx.kover.gradle.plugin.tasks.reports.KoverHtmlTask
import kotlinx.kover.gradle.plugin.tasks.reports.KoverVerifyTask
import kotlinx.kover.gradle.plugin.tasks.reports.KoverXmlTask
import kotlinx.kover.gradle.plugin.tools.*
import org.gradle.api.*
import org.gradle.api.artifacts.*
Expand Down
20 changes: 2 additions & 18 deletions src/main/kotlin/kotlinx/kover/gradle/plugin/commons/Artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,8 @@

package kotlinx.kover.gradle.plugin.commons

import kotlinx.kover.gradle.plugin.tasks.internal.KoverArtifactGenerationTask
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import java.io.File

/**
* Comprehensive information sufficient to generate a variant of the report.
*/
internal class Variant(
val name: String,
val localArtifact: Provider<RegularFile>,
val localArtifactGenerationTask: TaskProvider<KoverArtifactGenerationTask>,
val localArtifactConfiguration: NamedDomainObjectProvider<Configuration>,
val dependentArtifactsConfiguration: NamedDomainObjectProvider<Configuration>
)
import java.io.Serializable

/**
* The contents of a single Kover artifact.
Expand All @@ -30,7 +14,7 @@ internal class ArtifactContent(
val sources: Set<File>,
val outputs: Set<File>,
val reports: Set<File>
) {
): Serializable {
fun joinWith(others: List<ArtifactContent>): ArtifactContent {
val sources = this.sources.toMutableSet()
val outputs = this.outputs.toMutableSet()
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/kotlinx/kover/gradle/plugin/commons/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
import org.gradle.api.tasks.testing.*
import org.gradle.process.*
import org.gradle.workers.WorkerExecutor
import java.io.*
import java.math.BigDecimal
import javax.annotation.*
Expand Down Expand Up @@ -140,14 +140,15 @@ internal class CompilationUnit(

internal class ReportContext(
val files: ArtifactContent,
val filters: ReportFilters,
val classpath: FileCollection,
val tempDir: File,
val projectPath: String,
val services: GradleReportServices
)

internal class GradleReportServices(
val exec: ExecOperations,
val workerExecutor: WorkerExecutor,
val antBuilder: AntBuilder,
val objects: ObjectFactory
)
Expand All @@ -161,7 +162,7 @@ internal data class ReportFilters(
val excludesClasses: Set<String> = emptySet(),
@get:Input
val excludesAnnotations: Set<String> = emptySet()
)
): Serializable

internal open class VerificationRule @Inject constructor(
@get:Input
Expand All @@ -182,7 +183,7 @@ internal open class VerificationRule @Inject constructor(

@get:Nested
internal val bounds: List<VerificationBound>
)
): Serializable

internal open class VerificationBound(
@get:Input
Expand All @@ -200,4 +201,4 @@ internal open class VerificationBound(

@get:Input
val aggregation: AggregationType
)
): Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public object KoverVersions {
/**
* Kover coverage tool version.
*/
public const val KOVER_TOOL_VERSION = "1.0.716"
public const val KOVER_TOOL_VERSION = "1.0.721"

/**
* JaCoCo coverage tool version used by default.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.kover.gradle.plugin.tasks
package kotlinx.kover.gradle.plugin.tasks.reports

import kotlinx.kover.api.*
import kotlinx.kover.gradle.plugin.commons.*
Expand All @@ -11,26 +11,29 @@ import kotlinx.kover.gradle.plugin.tools.*
import kotlinx.kover.gradle.plugin.tools.kover.*
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.*
import org.gradle.api.tasks.*
import org.gradle.configurationcache.extensions.*
import org.gradle.kotlin.dsl.*
import org.gradle.process.*
import org.gradle.workers.WorkerExecutor
import java.io.File
import javax.inject.Inject


internal abstract class AbstractKoverReportTask(@Internal protected val tool: CoverageTool) : DefaultTask() {
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
val localArtifact: RegularFileProperty = project.objects.fileProperty()
abstract val localArtifact: RegularFileProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
val externalArtifacts: ConfigurableFileCollection = project.objects.fileCollection()
abstract val externalArtifacts: ConfigurableFileCollection

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
val reportClasspath: ConfigurableFileCollection = project.objects.fileCollection()
abstract val reportClasspath: ConfigurableFileCollection

/**
* This will cause the task to be considered out-of-date when source files of dependencies have changed.
Expand Down Expand Up @@ -79,9 +82,11 @@ internal abstract class AbstractKoverReportTask(@Internal protected val tool: Co
@get:Internal
protected val projectPath: String = project.path

private val exec: ExecOperations = project.serviceOf()
@get:Inject
protected abstract val obj: ObjectFactory

private val obj = project.objects
@get:Inject
protected abstract val workerExecutor: WorkerExecutor

fun hasRawReportsAndLog(): Boolean {
val hasReports = collectAllFiles().reports.isNotEmpty()
Expand All @@ -92,8 +97,8 @@ internal abstract class AbstractKoverReportTask(@Internal protected val tool: Co
}

protected fun context(): ReportContext {
val services = GradleReportServices(exec, ant, obj)
return ReportContext(collectAllFiles(), reportClasspath, temporaryDir, projectPath, services)
val services = GradleReportServices(workerExecutor, ant, obj)
return ReportContext(collectAllFiles(), filters.get(), reportClasspath, temporaryDir, projectPath, services)
}

private fun collectAllFiles(): ArtifactContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.kover.gradle.plugin.tasks
package kotlinx.kover.gradle.plugin.tasks.reports

import kotlinx.kover.gradle.plugin.tools.CoverageTool
import org.gradle.api.file.*
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.kotlin.dsl.*
import javax.inject.*

@CacheableTask
internal open class KoverHtmlTask @Inject constructor(tool: CoverageTool) : AbstractKoverReportTask(tool) {
internal abstract class KoverHtmlTask @Inject constructor(tool: CoverageTool) : AbstractKoverReportTask(tool) {
@get:OutputDirectory
val reportDir: DirectoryProperty = project.objects.directoryProperty()
abstract val reportDir: DirectoryProperty

@get:Input
val title: Property<String> = project.objects.property()
abstract val title: Property<String>

@get:Input
@get:Optional
val charset: Property<String> = project.objects.property()
abstract val charset: Property<String>

@TaskAction
fun generate() {
val htmlDir = reportDir.get().asFile
htmlDir.mkdirs()
tool.htmlReport(htmlDir, title.get(), charset.orNull, filters.get(), context())
tool.htmlReport(htmlDir, title.get(), charset.orNull, context())
}

fun printPath(): Boolean {
Expand Down

0 comments on commit bbc0560

Please sign in to comment.