-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathKoverGradlePlugin.kt
57 lines (48 loc) · 1.75 KB
/
KoverGradlePlugin.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* 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
import kotlinx.kover.api.*
import kotlinx.kover.gradle.plugin.appliers.ProjectApplier
import kotlinx.kover.gradle.plugin.dsl.KoverVersions.MINIMUM_GRADLE_VERSION
import kotlinx.kover.gradle.plugin.util.SemVer
import org.gradle.api.*
import org.gradle.api.invocation.*
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.plugin.extraProperties
private const val LISTENER_ADDED_PROPERTY_NAME = "kover-dependency-listener-added"
/**
* Gradle Plugin for JVM Coverage Tools.
*
* The main one is Kover - with extended support for language constructs of the Kotlin language.
*/
class KoverGradlePlugin : Plugin<Project> {
/**
* Apply plugin to a given project.
*/
override fun apply(target: Project) {
target.gradle.checkVersion()
val applier = ProjectApplier(target)
applier.onApply()
target.addDeprecations()
}
/**
* Check supported Gradle versions.
*/
private fun Gradle.checkVersion() {
val current = SemVer.ofVariableOrNull(gradleVersion)!!
val min = SemVer.ofVariableOrNull(MINIMUM_GRADLE_VERSION)!!
if (current < min) throw GradleException(
"Gradle version '$gradleVersion' is not supported by Kover Plugin. " +
"Minimal supported version is '$MINIMUM_GRADLE_VERSION'"
)
}
@Suppress("DEPRECATION")
private fun Project.addDeprecations() {
extensions.create<KoverMergedConfig>("koverMerged")
tasks.withType<Test>().configureEach {
this.extensions.create<KoverTaskExtension>("kover")
}
}
}