Skip to content

Commit

Permalink
Performed code refactoring (#403)
Browse files Browse the repository at this point in the history
Due to the increase in the number of artifacts and dependencies, in order to avoid errors in the future, it became necessary to change the structure of subprojects and add a version catalog.
Gradle plugin is now a subproject, on a par with the CLI and others.
Also implemented is getting rid of buildSrc as an outdated approach in favor of composite build.

Changes:
* Moved Kover Gradle Plugin to the separate subproject
* Migrated from buildSrc to composite build
* Added support of the version catalog

PR #403
  • Loading branch information
shanshin committed Jun 5, 2023
1 parent 8cd2317 commit 9e0779c
Show file tree
Hide file tree
Showing 306 changed files with 97 additions and 70 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ so do familiarize yourself with the following guidelines.
* Write the test that reproduces the bug.
* Fixes without tests are accepted only in exceptional circumstances if it can be shown that writing the
corresponding test is too hard or otherwise impractical.
* Place a test for the functionality of one or more Kover plugin classes in [unit tests directory](src/test/kotlin)
* Place in [functional test directory](src/functionalTest/kotlin) the test that check the functionality of the Kover plugin by the Gradle runs
* Place a test for the functionality of one or more Kover plugin classes in [unit tests directory](kover-gradle-plugin/src/test/kotlin)
* Place in [functional test directory](kover-gradle-plugin/src/functionalTest/kotlin) the test that check the functionality of the Kover plugin by the Gradle runs
* Follow the style of writing tests that is used in this project:
name test functions as `test...`, don't use backticks in test names. Name test classes as `...Tests`.
* Fixes that, in addition to directly solving the bug, add a large piece of new functionality or change the existing one, will be considered as features
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {

in this case report will be generated for current project joined with `:another:project` project.

**More examples of Gradle plugin applying can be found in [example folder](examples)**
**More examples of Gradle plugin applying can be found in [example folder](kover-gradle-plugin/examples)**

## Building locally and Contributing

Expand Down
13 changes: 13 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`kotlin-dsl`
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

repositories {
mavenCentral()
}
1 change: 1 addition & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "build-logic"
7 changes: 0 additions & 7 deletions buildSrc/build.gradle.kts

This file was deleted.

3 changes: 2 additions & 1 deletion docs/gradle-plugin/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ If inclusion and exclusion rules are specified at the same time, then excludes h
This means that even if a class is specified in both the inclusion and exclusion rules, it will be excluded from the report (e.g. class `com.example.Class1` above).

It is acceptable to filter a class from the report by its fully-qualified name - using `classes` or `packages`. Also acceptable to filter a class, function or getter marked with the specified annotation - `annotatedBy`.
**Kover supports filtering by annotations having `AnnotationRetention` `BINARY` or `RUNTIME`.

**Kover supports filtering by annotations having `AnnotationRetention` `BINARY` or `RUNTIME`.**

[Wildcards](#class-name-with-wildcards) `*` and `?` are allowed in class names.

Expand Down
4 changes: 2 additions & 2 deletions docs/gradle-plugin/development/functionalTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Functional tests run Gradle in a separate system process, and then check the res
By default, to run functional tests, Gradle is used, which builds the plugin as its dependency.

## Test types
* examples - used to demonstrate the use of the Kover plugin on ready-made projects. Located in specified subdirectory of [examples](/examples).
* examples - used to demonstrate the use of the Kover plugin on ready-made projects. Located in specified subdirectory of [examples](/kover-gradle-plugin/examples).
For such projects, it is mandatory that the latest release version of the plugin is used in the build script (the value of the `releaseVersion` property).
<br/>To create test on all examples, use `@kotlinx.kover.test.functional.framework.starter.ExamplesTest` annotation on function. This function must have receiver or single parameter with type `kotlinx.kover.test.functional.framework.checker.CheckerContext` to check result of Gradle run.
* templates - test on some specific rare case. Located in special [directory](/src/functionalTest/templates). You can execute any Gradle command for template project.
* templates - test on some specific rare case. Located in special [directory](/kover-gradle-plugin/src/functionalTest/templates). You can execute any Gradle command for template project.
<br/>To create test on all examples, use `@kotlinx.kover.test.functional.framework.starter.TemplateTest` annotation on function. This function must have receiver or single parameter with type `kotlinx.kover.test.functional.framework.checker.CheckerContext` to check result of Gradle run.
* single generated test - launching a project without a ready source code. The project is builded using the configurator in the code of the test itself. This makes the test code more versatile - it is suitable for creating builds in different script languages and using different Kotlin plugins or different Coverage Tools.
<br/>To create test on all examples, use `@kotlinx.kover.test.functional.framework.starter.TemplateTest` annotation on function. This function must have receiver or single parameter with type `kotlinx.kover.test.functional.framework.configurator.BuildConfigurator` to generate projects and perform Gradle run with checks.
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ group=org.jetbrains.kotlinx

# version of the latest release
kover.release.version=0.7.1
kotlinVersion=1.8.20
kotlin.code.style=official
25 changes: 25 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[versions]

intellij-coverage = "1.0.721"
junit = "5.9.0"
kotlinx-bcv = "0.13.0"
kotlinx-dokka = "1.8.10"
args4j = "2.33"

[libraries]

# IntelliJ coverage library
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" }

# JUnit
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }

args4j = { module = "args4j:args4j", version.ref = "args4j" }

gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin" }

[plugins]
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-bcv" }
kotlinx-dokka = { id = "org.jetbrains.dokka", version.ref = "kotlinx-dokka" }
2 changes: 1 addition & 1 deletion toolset/kover-cli/README.md → kover-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This single jar artifact allows using some of the functionality of Kover Toolset through command-line calls.

[CLI documentation](../../docs/cli/index.md)
[CLI documentation](../docs/cli/index.md)
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ extensions.configure<Kover_publishing_conventions_gradle.KoverPublicationExtensi
fatJar.set(true)
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

dependencies {
implementation("org.jetbrains.intellij.deps:intellij-coverage-reporter:1.0.721")
implementation("args4j:args4j:2.33")
implementation(libs.intellij.reporter)
implementation(libs.args4j)

testImplementation(kotlin("test"))
}
Expand Down
File renamed without changes.
File renamed without changes.
46 changes: 20 additions & 26 deletions build.gradle.kts → kover-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.0"
alias(libs.plugins.kotlinx.binaryCompatibilityValidator)
alias(libs.plugins.kotlinx.dokka)

id("org.jetbrains.dokka") version "1.8.10"
`kotlin-dsl`

`java-gradle-plugin`

id("kover-publishing-conventions")
Expand All @@ -21,7 +20,6 @@ repositories {
google()
}

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

Expand All @@ -37,23 +35,24 @@ kotlin.target.compilations.run {
getByName("functionalTest").associateWith(getByName(KotlinCompilation.MAIN_COMPILATION_NAME))
}

// name of configuration for functionalTest source set with implementation dependencies
val functionalTestImplementation = "functionalTestImplementation"

dependencies {
// exclude transitive dependency on stdlib, the Gradle version should be used
compileOnly(kotlin("stdlib"))
compileOnly(libs.gradlePlugin.kotlin)
compileOnly(libs.intellij.reporter)

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

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

testImplementation(kotlin("test"))

"functionalTestImplementation"("org.junit.jupiter:junit-jupiter:5.9.0")
"functionalTestImplementation"("org.junit.jupiter:junit-jupiter-params:5.9.0")
functionalTestImplementation(kotlin("test"))
functionalTestImplementation(libs.junit.jupiter)
functionalTestImplementation(libs.junit.params)
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}


Expand All @@ -70,7 +69,7 @@ val functionalTest by tasks.registering(Test::class) {
// basic build properties
setSystemPropertyFromProject("kover.test.kotlin.version")

systemProperties["kotlinVersion"] = kotlinVersion
systemProperties["kotlinVersion"] = embeddedKotlinVersion
systemProperties["koverVersion"] = version
systemProperties["localRepositoryPath"] = localRepositoryUri.path

Expand Down Expand Up @@ -166,11 +165,6 @@ gradlePlugin {
}
}

apiValidation {
ignoredProjects.addAll(listOf("kover-cli", "kover-offline-runtime"))
}



// ====================
// Release preparation
Expand All @@ -186,12 +180,12 @@ tasks.register("prepareRelease") {
val prevReleaseVersion = project.property("kover.release.version") as String

val dir = layout.projectDirectory
val rootDir = rootProject.layout.projectDirectory

rootDir.file("gradle.properties").asFile.patchProperties(releaseVersion)
rootDir.file("CHANGELOG.md").asFile.patchChangeLog(releaseVersion)

dir.file("gradle.properties").asFile.patchProperties(releaseVersion)
dir.file("CHANGELOG.md").asFile.patchChangeLog(releaseVersion)

dir.file("README.md").asFile.replaceInFile(prevReleaseVersion, releaseVersion)
rootDir.file("README.md").asFile.replaceInFile(prevReleaseVersion, releaseVersion)

// replace versions in examples
dir.dir("examples").asFileTree.matching {
Expand All @@ -202,7 +196,7 @@ tasks.register("prepareRelease") {
}

// replace versions in docs
dir.dir("docs").asFileTree.files.forEach {
rootDir.dir("docs").asFileTree.files.forEach {
it.replaceInFile(prevReleaseVersion, releaseVersion)
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

import java.io.File

/**
* Name of environment variable with Android SDK path.
*/
Expand Down Expand Up @@ -65,4 +67,8 @@ internal fun logInfo(message: String) {
}
}

private val testLogsEnabled = System.getProperty("testLogsEnabled") == "true"
internal val gradleWrappersRoot = File("gradle-wrappers")

internal val defaultGradleWrapperDir = File("..")

internal val testLogsEnabled = System.getProperty("testLogsEnabled") == "true"
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import kotlinx.kover.gradle.plugin.test.functional.framework.common.*
import kotlinx.kover.gradle.plugin.test.functional.framework.common.isDebugEnabled
import java.io.*

private val wrappersRoot = File("gradle-wrappers")
private val defaultWrapperDir = File(".")


/**
* Options:
* - build cache - disabled by default, to enable it, you need to pass the "--build-cache" argument.
Expand All @@ -27,7 +23,7 @@ internal fun File.runGradleBuild(args: List<String>, runIndex: Int = 0): BuildRe
gradleArgs += "--no-daemon"
}

val wrapperDir = if (gradleWrapperVersion == null) defaultWrapperDir else getWrapper(gradleWrapperVersion)
val wrapperDir = if (gradleWrapperVersion == null) defaultGradleWrapperDir else getWrapper(gradleWrapperVersion)

logInfo("Run Gradle commands $gradleArgs for project '${this.canonicalPath}' with wrapper '${wrapperDir.canonicalPath}'")

Expand Down Expand Up @@ -83,7 +79,7 @@ internal class BuildResult(exitCode: Int, private val logFile: File) {
}

private fun getWrapper(version: String): File {
val wrapperDir = wrappersRoot.resolve(version)
val wrapperDir = gradleWrappersRoot.resolve(version)
if (!wrapperDir.exists()) throw Exception("Wrapper for Gradle version '$version' is not supported by functional tests")
return wrapperDir
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

package kotlinx.kover.api

import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.commons.KoverMigrations.MIGRATION_0_6_TO_0_7
import org.gradle.api.tasks.*


// DEPRECATIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
package kotlinx.kover.api

import kotlinx.kover.gradle.plugin.commons.KoverMigrations.MIGRATION_0_6_TO_0_7
import org.gradle.api.*
import org.gradle.api.model.*
import org.gradle.api.provider.*
import org.gradle.kotlin.dsl.*
import javax.inject.*

@Deprecated(
message = "Class was removed. Please refer to migration guide in order to migrate: $MIGRATION_0_6_TO_0_7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package kotlinx.kover.gradle.plugin.locators

import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl
import org.gradle.api.*


internal class EmptyLocator : CompilationKitLocator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.*
import kotlinx.kover.gradle.plugin.util.*
import org.gradle.api.*
import org.gradle.api.tasks.*
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlinx.kover.gradle.plugin.commons.*
import kotlinx.kover.gradle.plugin.dsl.internal.KoverProjectExtensionImpl
import kotlinx.kover.gradle.plugin.util.*
import org.gradle.api.*
import org.gradle.api.tasks.*
import org.gradle.api.tasks.testing.*
import org.gradle.kotlin.dsl.*

Expand Down
Loading

0 comments on commit 9e0779c

Please sign in to comment.