Skip to content

Commit

Permalink
Repacked the intellij-agent artifact to kover-jvm-agent
Browse files Browse the repository at this point in the history
User can use the JVM agent separately, with the name kover and without mentioning IntelliJ, as well as reduce the number of parameters and properties required to transfer to the agent.

Now Kover Gradle Plugin uses kover-jvm-agent with the same version. To do this, the transfer of staging repositories was added to the functional tests.
The common logic of publishing was also extracted into a separate convention plugin.

Resolves #464
  • Loading branch information
shanshin committed Feb 27, 2024
1 parent 3730ba4 commit d75ae34
Show file tree
Hide file tree
Showing 46 changed files with 553 additions and 253 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.gradle.kotlin.dsl.base
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.java

/*
* Copyright 2000-2023 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
java
}

val fatJarDependency = "fatJar"
val fatJarConfiguration = configurations.create(fatJarDependency)


tasks.jar {
from(
fatJarConfiguration.map { if (it.isDirectory) it else zipTree(it) }
) {
exclude("OSGI-OPT/**")
exclude("META-INF/**")
exclude("LICENSE")
exclude("classpath.index")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import groovy.util.Node
import groovy.util.NodeList

/*
* Copyright 2000-2023 JetBrains s.r.o.
*
Expand Down Expand Up @@ -31,19 +28,100 @@ java {

interface KoverPublicationExtension {
val description: Property<String>
val fatJar: Property<Boolean>
val addPublication: Property<Boolean>
val localRepository: DirectoryProperty
}

val extension = extensions.create<KoverPublicationExtension>("koverPublication")

extension.description.convention("")
extension.addPublication.convention(true)
extension.fatJar.convention(false)
extension.localRepository.convention(layout.buildDirectory.dir(".m2"))

internal interface LocalArtifactAttr : Named {
companion object {
val ATTRIBUTE = Attribute.of(
"kotlinx.kover.gradle-plugin",
LocalArtifactAttr::class.java
)
}
}

val publicationTask: TaskCollection<*> = tasks.matching { task -> task.name == "publishAllPublicationsToLocalRepository" }
configurations.register("localPublication") {
isVisible = false
isCanBeResolved = false
// this configuration produces modules that can be consumed by other projects
isCanBeConsumed = true
attributes {
attribute(LocalArtifactAttr.ATTRIBUTE, objects.named("local-repository"))
}

outgoing.artifact(extension.localRepository) {
builtBy(publicationTask)
}
}

val snapshotRelease = configurations.create("snapshotRelease") {
isVisible = true
isCanBeResolved = false
isCanBeConsumed = false
}

val externalSnapshots = configurations.create("snapshots") {
isVisible = false
isCanBeResolved = true
// this config consumes modules from OTHER projects, and cannot be consumed by other projects
isCanBeConsumed = false

attributes {
attribute(LocalArtifactAttr.ATTRIBUTE, objects.named("local-repository"))
}

extendsFrom(snapshotRelease)
}

tasks.register<CollectTask>("collectRepository") {
dependsOn(publicationTask)
dependsOn(externalSnapshots)

local.convention(extension.localRepository)
externals.from(externalSnapshots)
}

@CacheableTask
abstract class CollectTask: DefaultTask() {
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val local: DirectoryProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val externals: ConfigurableFileCollection

@get:OutputDirectories
val repositories: MutableList<File> = mutableListOf()

@TaskAction
fun doCollect() {
val localFile = local.get().asFile
repositories += localFile
repositories += externals.toList()
}
}


publishing {
repositories {
addSonatypeRepository()

/**
* Maven repository in build directory to store artifacts for using in functional tests.
*/
maven {
setUrl(extension.localRepository)
name = "local"
}
}

publications.withType<MavenPublication>().configureEach {
Expand All @@ -62,13 +140,6 @@ afterEvaluate {
from(components["java"])
}
}

if (extension.fatJar.get()) {
// remove all dependencies for fat JARs after user configuring
publishing.publications.withType<MavenPublication>().configureEach {
removeDependencies()
}
}
}

fun RepositoryHandler.addSonatypeRepository() {
Expand Down Expand Up @@ -129,21 +200,6 @@ fun MavenPublication.addMetadata() {
}
}

fun MavenPublication.removeDependencies() {
pom {
withXml {
val dependencies: NodeList? = asNode().get("dependencies") as? NodeList
if (dependencies != null && dependencies.size > 0) {
dependencies.forEach { dependency ->
if (dependency is Node)
asNode().remove(dependency)
}
}
}
}
}


fun Project.acquireProperty(name: String): String? {
return project.findProperty(name) as? String ?: System.getenv(name)
}
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gradle-plugin-publish = "1.2.1"
[libraries]

# IntelliJ coverage library
intellij-agent = { module = "org.jetbrains.intellij.deps:intellij-coverage-agent", version.ref = "intellij-coverage" }
intellij-reporter = { module = "org.jetbrains.intellij.deps:intellij-coverage-reporter", version.ref = "intellij-coverage" }
intellij-offline = { module = "org.jetbrains.intellij.deps:intellij-coverage-offline", version.ref = "intellij-coverage" }

Expand Down
1 change: 0 additions & 1 deletion kover-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ plugins {

extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtension> {
description.set("Command Line Interface for Kotlin Coverage Toolchain")
fatJar.set(true)
}

kotlin {
Expand Down
9 changes: 4 additions & 5 deletions kover-features-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ plugins {

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

java {
Expand All @@ -40,10 +39,10 @@ tasks.processResources {
project.version.toString()
}

filesMatching("**/kover.version") {
filter {
it.replace("\$version", version)
}
val file = destinationDir.resolve("kover.version")

doLast {
file.writeText(version)
}
}

Expand Down
1 change: 0 additions & 1 deletion kover-features-jvm/src/main/resources/kover.version
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
$version
1 change: 1 addition & 0 deletions kover-gradle-plugin/api/kover-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public final class kotlinx/kover/gradle/plugin/dsl/KoverVersions {
public static final field JACOCO_TOOL_DEFAULT_VERSION Ljava/lang/String;
public static final field KOVER_TOOL_VERSION Ljava/lang/String;
public static final field MINIMUM_GRADLE_VERSION Ljava/lang/String;
public final fun getVersion ()Ljava/lang/String;
}

public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverXmlTaskConfig {
Expand Down
21 changes: 7 additions & 14 deletions kover-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ repositories {
google()
}

val localRepositoryUri = uri("build/.m2")
val junitParallelism = findProperty("kover.test.junit.parallelism")?.toString()

sourceSets {
Expand All @@ -40,6 +39,7 @@ kotlin.target.compilations.run {
val functionalTestImplementation = "functionalTestImplementation"

dependencies {
implementation(project(":kover-features-jvm"))
// exclude transitive dependency on stdlib, the Gradle version should be used
compileOnly(kotlin("stdlib"))
compileOnly(libs.gradlePlugin.kotlin)
Expand All @@ -48,6 +48,9 @@ dependencies {
functionalTestImplementation(kotlin("test"))
functionalTestImplementation(libs.junit.jupiter)
functionalTestImplementation(libs.junit.params)

snapshotRelease(project(":kover-features-jvm"))
snapshotRelease(project(":kover-jvm-agent"))
}

kotlin {
Expand All @@ -65,15 +68,16 @@ val functionalTest by tasks.registering(Test::class) {
// use JUnit 5
useJUnitPlatform()

dependsOn(tasks.named("publishAllPublicationsToLocalRepository"))
dependsOn(tasks.collectRepository)
doFirst {
// basic build properties
setSystemPropertyFromProject("kover.test.kotlin.version")

systemProperties["kotlinVersion"] = embeddedKotlinVersion
systemProperties["gradleVersion"] = gradle.gradleVersion
systemProperties["koverVersion"] = version
systemProperties["localRepositoryPath"] = localRepositoryUri.path
systemProperties["snapshotRepositories"] = tasks.collectRepository.get()
.repositories.joinToString("\n") { file -> file.absolutePath }

// parallel execution
systemProperties["junit.jupiter.execution.parallel.mode.default"] = "concurrent"
Expand Down Expand Up @@ -185,17 +189,6 @@ extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtensi
addPublication.set(false)
}

publishing {
repositories {
/**
* Maven repository in build directory to store artifacts for using in functional tests.
*/
maven(localRepositoryUri) {
name = "local"
}
}
}

signing {
// disable signing if private key isn't passed
isRequired = findProperty("libs.sign.key.private") != null
Expand Down
4 changes: 0 additions & 4 deletions kover-gradle-plugin/examples/jvm/merged/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id("org.jetbrains.kotlinx.kover") version "0.7.6"
}

repositories {
mavenCentral()
}

dependencies {
implementation(project(":subproject"))
implementation(project(":excluded"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
kotlin("jvm")
}

repositories {
mavenCentral()
}
6 changes: 6 additions & 0 deletions kover-gradle-plugin/examples/jvm/merged/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ rootProject.name = "example-merged"

include(":subproject")
include(":excluded")

dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id("org.jetbrains.kotlinx.kover")
}

repositories {
mavenCentral()
}

dependencies {
testImplementation(kotlin("test"))
}
4 changes: 0 additions & 4 deletions kover-gradle-plugin/examples/jvm/minimal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id("org.jetbrains.kotlinx.kover") version "0.7.6"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation(kotlin("test"))
}
5 changes: 5 additions & 0 deletions kover-gradle-plugin/examples/jvm/minimal/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ pluginManagement {
}
rootProject.name = "example-minimal"

dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ internal class AccessorsTests {
id("org.jetbrains.kotlinx.kover")
}
repositories {
mavenCentral()
}
tasks.register("custom") {
dependsOn(tasks.koverHtmlReport)
dependsOn(tasks.koverXmlReport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package kotlinx.kover.gradle.plugin.test.functional.framework.common

import org.gradle.kotlin.dsl.provideDelegate
import java.io.File

/**
Expand Down Expand Up @@ -59,8 +60,12 @@ internal val isAndroidTestDisabled: Boolean = System.getProperty("kover.test.and
/**
* Path to the local maven repository with the current Kover build.
*/
internal val localRepositoryPath: String = System.getProperty("localRepositoryPath")
?: throw Exception("System property 'localRepositoryPath' not defined for functional tests")
internal val snapshotRepositoriesPropertyValue: List<String> by lazy {
val value = System.getProperty("snapshotRepositories")
?: throw Exception("System property 'localRepositoryPath' not defined for functional tests")

value.split("\n")
}


internal fun logInfo(message: String) {
Expand Down
Loading

0 comments on commit d75ae34

Please sign in to comment.