Kotlin / kotlinx-kover

Apache License 2.0
1.37k stars 53 forks source link

Create kover-features artifact to invoke the capabilities of Kover via the Java API #534

Closed shanshin closed 9 months ago

shanshin commented 9 months ago

Motivation

Need to add Kover coverage library support to the Android Gradle Plugin (AGP).

Current status

AGP only supports working with JaCoCo, it uses the Java calls of JaCoCo methods.

The following JaCoCo API are used:

Kover only has an API for getting a binary report in artifact org.jetbrains.kotlinx:kover-offline-runtime, a suitable method kotlinx.kover.offline.runtime.api.KoverRuntime#getReport()

Implementation plan

  1. Create published Kover artifact org.jetbrains.kotlinx:kover-features-jvm
  2. Add Java API for offline instrumentation of single class
    
    package kotlinx.kover.features.jvm

public class KoverFeatures { public static OfflineInstrumentator createOfflineInstrumenter() { ... } }

public interface OfflineInstrumenter { public byte[] instrument(InputStream originalClass, String debugName) }


3. Create `kotlinx.kover.features.jvm.KoverLegacyFeatures` and put the methods used by the Kover CLI there
4. Remove the dependency on `intellij-coverage-reporter` from the Kover CLI and add the dependency on `org.jetbrains.kotlinx:kover-features-jvm`, use the methods added in `kotlinx.kover.features.jvm.KoverFeaturesUtils`. Now, `kover-features-jvm` will be the only artifact distributing the Kover Tooling API via Java API.
5. (for the future) Develop an API for generating reports. Analyzing the JaCoCo API, it is obvious that the API for generating reports is not trivial.
It is required to develop an API that implements all the needs of external users (such as AGP), optimized, but as easy to use and non-redundant.
shanshin commented 9 months ago

Relates #96

shanshin commented 9 months ago

Implemented in 0.7.6